The Function class is a polynomial Term that represents a generic function \( f : x \mapsto f(x) \). More...
#include <Function.h>
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) | |
Function & | operator= (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 ¶meters) 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 Engine * | getEngine () const |
Gets the engine to which the formula can refer. More... | |
virtual Node * | root () 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 Node * | parse (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 Function * | clone () 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 Function * | create (const std::string &name, const std::string &formula, const Engine *engine=fl::null) |
Creates a Function term with the given parameters. More... | |
static Term * | constructor () |
Public Attributes | |
std::map< std::string, scalar > | variables |
A map of variables and substitution values. More... | |
Additional Inherited Members | |
Protected Attributes inherited from fl::Term | |
scalar | _height |
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.
Definition at line 60 of file Function.h.
Definition at line 63 of file Function.h.
Definition at line 62 of file Function.h.
|
explicit |
fl::Function::Function | ( | const Function & | other | ) |
|
virtual |
|
virtual |
Returns the name of the class of the term.
Implements fl::Term.
|
virtual |
|
virtual |
Computes the estimated complexity of evaluating the membership function.
Implements fl::Term.
|
virtual |
Configures the term with the parameters given as formula
parameters | as formula |
Implements fl::Term.
|
static |
|
static |
Creates a Function term with the given parameters.
name | is the name of the term |
formula | is the formula defining the membership function |
engine | is the engine to which the Function can have access |
fl::Exception | if the formula has a syntax error |
|
virtual |
Computes the function value of this term using the given map of variable substitutions.
variables | is a map of substitution variables |
|
virtual |
Gets the engine to which the formula can refer.
|
virtual |
Gets the formula of the function.
|
virtual |
Indicates whether the formula is loaded.
|
virtual |
Loads the current formula expressed in infix notation.
|
virtual |
Loads the given formula expressed in infix notation.
formula | is the right-hand side of a mathematical equation |
fl::Exception | if the formula has syntax errors |
|
virtual |
Loads the given formula expressed in infix notation, and sets the engine holding the variables to which the formula refers.
formula | is the right-hand side of a mathematical equation expressed in infix notation |
engine | is the engine to which the formula can refer |
fl::Exception | if the formula has syntax errors |
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.
x |
Implements fl::Term.
|
virtual |
|
virtual |
Creates a node representing a binary expression tree from the given formula.
formula | is the right-hand side of a mathematical equation expressed in infix notation |
fl::Exception | if the formula has syntax errors |
|
virtual |
|
virtual |
Sets the engine to which the formula can refer.
engine | is the engine to which the formula can refer |
|
virtual |
Sets the formula of the function.
formula | is the formula of the function |
|
virtual |
Adds spaces to the formula to separate parentheses, commas and function operators such that these are treated as tokens when parsing the function.
formula | is the right-hand side of a mathematical equation expressed in infix notation |
|
virtual |
Translates the given formula to postfix notation.
formula | is the right-hand side of a mathematical equation expressed in infix notation |
fl::Exception | if the formula has syntax errors |
|
virtual |
Unloads the formula and resets the map of substitution variables.
|
virtual |
|
mutable |
A map of variables and substitution values.
Definition at line 250 of file Function.h.