fuzzylite  6.0
A Fuzzy Logic Control Library in C++
fl::Function Class Reference

The Function class is a polynomial Term that represents a generic function \( f : x \mapsto f(x) \). More...

#include <Function.h>

Inheritance diagram for fl::Function:
Collaboration diagram for fl::Function:

Classes

struct  Element
 The Element class represents a single element in a formula, be that either a function or an operator. More...
 
struct  Node
 The Node class structures a binary tree by storing pointers to a left Node and a right Node, and storing its content as a Function::Element, the name of an InputVariable or OutputVariable, or a constant value. More...
 

Public Types

typedef scalar(* Unary) (scalar)
 
typedef scalar(* Binary) (scalar, scalar)
 

Public Member Functions

 Function (const std::string &name="", const std::string &formula="", const Engine *engine=fl::null)
 
 Function (const Function &other)
 
Functionoperator= (const Function &other)
 
virtual ~Function () FL_IOVERRIDE
 
virtual Complexity complexity () const FL_IOVERRIDE
 Computes the estimated complexity of evaluating the membership function. More...
 
virtual scalar membership (scalar x) const FL_IOVERRIDE
 Computes the membership function value of \(x\) at the root node. More...
 
virtual scalar evaluate (const std::map< std::string, scalar > *variables=fl::null) const
 Computes the function value of this term using the given map of variable substitutions. More...
 
virtual std::string className () const FL_IOVERRIDE
 Returns the name of the class of the term. More...
 
virtual std::string parameters () const FL_IOVERRIDE
 Returns the parameters of the term as formula More...
 
virtual void configure (const std::string &parameters) FL_IOVERRIDE
 Configures the term with the parameters given as formula More...
 
virtual void setFormula (const std::string &formula)
 Sets the formula of the function. More...
 
virtual std::string getFormula () const
 Gets the formula of the function. More...
 
virtual void setEngine (const Engine *engine)
 Sets the engine to which the formula can refer. More...
 
virtual const EnginegetEngine () const
 Gets the engine to which the formula can refer. More...
 
virtual Noderoot () const
 Gets the root node of the expression tree defining the Function. More...
 
virtual bool isLoaded () const
 Indicates whether the formula is loaded. More...
 
virtual void unload ()
 Unloads the formula and resets the map of substitution variables. More...
 
virtual void load ()
 Loads the current formula expressed in infix notation. More...
 
virtual void load (const std::string &formula)
 Loads the given formula expressed in infix notation. More...
 
virtual void load (const std::string &formula, const Engine *engine)
 Loads the given formula expressed in infix notation, and sets the engine holding the variables to which the formula refers. More...
 
virtual Nodeparse (const std::string &formula)
 Creates a node representing a binary expression tree from the given formula. More...
 
virtual std::string toPostfix (const std::string &formula) const
 Translates the given formula to postfix notation. More...
 
virtual std::string space (const std::string &formula) const
 Adds spaces to the formula to separate parentheses, commas and function operators such that these are treated as tokens when parsing the function. More...
 
virtual void updateReference (const Engine *engine) FL_IOVERRIDE
 Updates the references (if any) to point to the current engine (useful when cloning engines or creating terms within Importer objects. More...
 
virtual Functionclone () const FL_IOVERRIDE
 Creates a clone of the term. More...
 
- Public Member Functions inherited from fl::Term
 Term (const std::string &name="", scalar height=1.0)
 
virtual ~Term ()
 
virtual void setName (const std::string &name)
 Sets the name of the term. More...
 
virtual std::string getName () const
 Gets the name of the term. More...
 
virtual void setHeight (scalar height)
 Sets the height of the term. More...
 
virtual scalar getHeight () const
 Gets the height of the term. More...
 
virtual std::string toString () const
 Returns the representation of the term in the FuzzyLite Language. More...
 

Static Public Member Functions

static Functioncreate (const std::string &name, const std::string &formula, const Engine *engine=fl::null)
 Creates a Function term with the given parameters. More...
 
static Termconstructor ()
 

Public Attributes

std::map< std::string, scalarvariables
 A map of variables and substitution values. More...
 

Additional Inherited Members

- Protected Attributes inherited from fl::Term
scalar _height
 

Detailed Description

The Function class is a polynomial Term that represents a generic function \( f : x \mapsto f(x) \).

Every Function object has a public key-value map, namely Function::variables, that links variable names to fl::scalar values, which are utilized to replace the variable names for their respective values in the given formula whenever the function \(f\) is evaluated. Specifically, when the method Function::membership() is called, the name and value of the variable \(x\) are automatically loaded into the map. Furthermore, if an Engine is given, the names of its InputVariables and OutputVariables will also be automatically loaded into the map linking to their respective input values and (previously defuzzified) output values. The Function::variables need to be manually loaded whenever variables other than \(x\), input variables, and output variables, are expressed in the given formula, always having in mind that (a) the map replaces existing keys, and (b) the variable \(x\), and input variables and output variables of an engine will automatically be replaced and will also take precedence over previously loaded variables.

Besides the use of Function as a linguistic Term, it is also utilized to convert the text of the Antecedent of a Rule, expressed in infix notation, into postfix notation.

Author
Juan Rada-Vilela, Ph.D.
See also
Term
Variable
FunctionFactory
Antecedent::load()
Since
4.0

Definition at line 60 of file Function.h.

Member Typedef Documentation

◆ Binary

typedef scalar(* fl::Function::Binary) (scalar, scalar)

Definition at line 63 of file Function.h.

◆ Unary

typedef scalar(* fl::Function::Unary) (scalar)

Definition at line 62 of file Function.h.

Constructor & Destructor Documentation

◆ Function() [1/2]

fl::Function::Function ( const std::string &  name = "",
const std::string &  formula = "",
const Engine engine = fl::null 
)
explicit

◆ Function() [2/2]

fl::Function::Function ( const Function other)

◆ ~Function()

virtual fl::Function::~Function ( )
virtual

Member Function Documentation

◆ className()

virtual std::string fl::Function::className ( ) const
virtual

Returns the name of the class of the term.

Returns
the name of the class of the term

Implements fl::Term.

◆ clone()

virtual Function* fl::Function::clone ( ) const
virtual

Creates a clone of the term.

Returns
a clone of the term

Implements fl::Term.

◆ complexity()

virtual Complexity fl::Function::complexity ( ) const
virtual

Computes the estimated complexity of evaluating the membership function.

Returns
the estimated complexity of evaluating the membership function

Implements fl::Term.

◆ configure()

virtual void fl::Function::configure ( const std::string &  parameters)
virtual

Configures the term with the parameters given as formula

Parameters
parametersas formula

Implements fl::Term.

◆ constructor()

static Term* fl::Function::constructor ( )
static

◆ create()

static Function* fl::Function::create ( const std::string &  name,
const std::string &  formula,
const Engine engine = fl::null 
)
static

Creates a Function term with the given parameters.

Parameters
nameis the name of the term
formulais the formula defining the membership function
engineis the engine to which the Function can have access
Returns
a Function term configured with the given parameters
Exceptions
fl::Exceptionif the formula has a syntax error

◆ evaluate()

virtual scalar fl::Function::evaluate ( const std::map< std::string, scalar > *  variables = fl::null) const
virtual

Computes the function value of this term using the given map of variable substitutions.

Parameters
variablesis a map of substitution variables
Returns
the function value of this term using the given map of variable substitutions.

◆ getEngine()

virtual const Engine* fl::Function::getEngine ( ) const
virtual

Gets the engine to which the formula can refer.

Returns
the engine to which the formula can refer

◆ getFormula()

virtual std::string fl::Function::getFormula ( ) const
virtual

Gets the formula of the function.

Returns
the formula of the function

◆ isLoaded()

virtual bool fl::Function::isLoaded ( ) const
virtual

Indicates whether the formula is loaded.

Returns
whether the formula is loaded

◆ load() [1/3]

virtual void fl::Function::load ( )
virtual

Loads the current formula expressed in infix notation.

◆ load() [2/3]

virtual void fl::Function::load ( const std::string &  formula)
virtual

Loads the given formula expressed in infix notation.

Parameters
formulais the right-hand side of a mathematical equation
Exceptions
fl::Exceptionif the formula has syntax errors

◆ load() [3/3]

virtual void fl::Function::load ( const std::string &  formula,
const Engine engine 
)
virtual

Loads the given formula expressed in infix notation, and sets the engine holding the variables to which the formula refers.

Parameters
formulais the right-hand side of a mathematical equation expressed in infix notation
engineis the engine to which the formula can refer
Exceptions
fl::Exceptionif the formula has syntax errors

◆ membership()

virtual scalar fl::Function::membership ( scalar  x) const
virtual

Computes the membership function value of \(x\) at the root node.

If the engine has been set, the current values of the input variables and output variables are added to the map of Function::variables. In addition, the variable \(x\) will also be added to the map.

Parameters
x
Returns
the membership function value of \(x\) at the root node

Implements fl::Term.

◆ operator=()

Function& fl::Function::operator= ( const Function other)

◆ parameters()

virtual std::string fl::Function::parameters ( ) const
virtual

Returns the parameters of the term as formula

Returns
formula

Implements fl::Term.

◆ parse()

virtual Node* fl::Function::parse ( const std::string &  formula)
virtual

Creates a node representing a binary expression tree from the given formula.

Parameters
formulais the right-hand side of a mathematical equation expressed in infix notation
Returns
a node representing a binary expression tree from the given formula
Exceptions
fl::Exceptionif the formula has syntax errors

◆ root()

virtual Node* fl::Function::root ( ) const
virtual

Gets the root node of the expression tree defining the Function.

The root is fl::null if the formula has not been loaded.

Returns
the root node of the expression tree defining the Function, or fl::null if the formula has not been loaded

◆ setEngine()

virtual void fl::Function::setEngine ( const Engine engine)
virtual

Sets the engine to which the formula can refer.

Parameters
engineis the engine to which the formula can refer

◆ setFormula()

virtual void fl::Function::setFormula ( const std::string &  formula)
virtual

Sets the formula of the function.

Parameters
formulais the formula of the function

◆ space()

virtual std::string fl::Function::space ( const std::string &  formula) const
virtual

Adds spaces to the formula to separate parentheses, commas and function operators such that these are treated as tokens when parsing the function.

Parameters
formulais the right-hand side of a mathematical equation expressed in infix notation
Returns
the formula with spaces before and after parentheses, commas and function operators

◆ toPostfix()

virtual std::string fl::Function::toPostfix ( const std::string &  formula) const
virtual

Translates the given formula to postfix notation.

Parameters
formulais the right-hand side of a mathematical equation expressed in infix notation
Returns
the formula represented in postfix notation
Exceptions
fl::Exceptionif the formula has syntax errors

◆ unload()

virtual void fl::Function::unload ( )
virtual

Unloads the formula and resets the map of substitution variables.

◆ updateReference()

virtual void fl::Function::updateReference ( const Engine engine)
virtual

Updates the references (if any) to point to the current engine (useful when cloning engines or creating terms within Importer objects.

Parameters
engineis the engine to which this term belongs to

Reimplemented from fl::Term.

Member Data Documentation

◆ variables

std::map<std::string, scalar> fl::Function::variables
mutable

A map of variables and substitution values.

Definition at line 250 of file Function.h.


The documentation for this class was generated from the following file: