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

The Linear class is a linear polynomial Term expressed as \(f(x)= \mathbf{c}\mathbf{v}+k = \sum_i c_iv_i + k\), where variable \(x\) is not utilized, \(\mathbf{v}\) is a vector of values from the input variables, \(\mathbf{c}\) is a vector of coefficients, and \(k\) is a constant. More...

#include <Linear.h>

Inheritance diagram for fl::Linear:
Collaboration diagram for fl::Linear:

Public Member Functions

 Linear (const std::string &name="", const std::vector< scalar > &coefficients=std::vector< scalar >(), const Engine *engine=fl::null)
 
virtual ~Linear () FL_IOVERRIDE
 
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 vector \(\mathbf{c}^\star\). More...
 
virtual void configure (const std::string &parameters) FL_IOVERRIDE
 Configures the term with the values of \(\mathbf{c}^\star\). More...
 
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 linear function \(f(x)=\sum_i c_iv_i +k\), where \(v_i\) is the value of the input variable \(i\) registered in the Linear::getEngine() More...
 
virtual void set (const std::vector< scalar > &coefficients, const Engine *engine)
 Sets the vector \(\mathbf{c}^\star\) and the Engine from which vector \(\mathbf{v}\) will be retrieved when necessary. More...
 
virtual void setCoefficients (const std::vector< scalar > &coefficients)
 Sets the vector \(\mathbf{c}^\star\) of the linear function. More...
 
virtual const std::vector< scalar > & coefficients () const
 Gets the immutable vector \(\mathbf{c}^\star\). More...
 
virtual std::vector< scalar > & coefficients ()
 Gets the mutable vector \(\mathbf{c}^\star\). More...
 
virtual void setEngine (const Engine *engine)
 Sets the engine from which the vector \(\mathbf{v}\) will be obtained upon computing the Linear::membership() More...
 
virtual const EnginegetEngine () const
 Gets the engine from which the vector \(\mathbf{v}\) will be obtained upon computing the Linear::membership() More...
 
virtual Linearclone () const FL_IOVERRIDE
 Creates a clone of the term. 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...
 
- 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 Termconstructor ()
 
template<typename T >
static Linearcreate (const std::string &name, const Engine *engine, T firstCoefficient,...)
 Creates a Linear term from a variadic set of coefficients. More...
 

Additional Inherited Members

- Protected Attributes inherited from fl::Term
scalar _height
 

Detailed Description

The Linear class is a linear polynomial Term expressed as \(f(x)= \mathbf{c}\mathbf{v}+k = \sum_i c_iv_i + k\), where variable \(x\) is not utilized, \(\mathbf{v}\) is a vector of values from the input variables, \(\mathbf{c}\) is a vector of coefficients, and \(k\) is a constant.

Hereinafter, the vector \(\mathbf{c}^\star=\{c_1, \ldots, c_i, \ldots, c_n, k\}\) refers to a vector containing the coefficients of \(\mathbf{c}\) and the constant \(k\).

Author
Juan Rada-Vilela, Ph.D.
See also
Term
Variable
Since
4.0

Definition at line 39 of file Linear.h.

Constructor & Destructor Documentation

◆ Linear()

fl::Linear::Linear ( const std::string &  name = "",
const std::vector< scalar > &  coefficients = std::vector< scalar >(),
const Engine engine = fl::null 
)
explicit

◆ ~Linear()

virtual fl::Linear::~Linear ( )
virtual

Member Function Documentation

◆ className()

virtual std::string fl::Linear::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 Linear* fl::Linear::clone ( ) const
virtual

Creates a clone of the term.

Returns
a clone of the term

Implements fl::Term.

◆ coefficients() [1/2]

virtual const std::vector<scalar>& fl::Linear::coefficients ( ) const
virtual

Gets the immutable vector \(\mathbf{c}^\star\).

Returns
the immutable vector \(\mathbf{c}^\star\)

◆ coefficients() [2/2]

virtual std::vector<scalar>& fl::Linear::coefficients ( )
virtual

Gets the mutable vector \(\mathbf{c}^\star\).

Returns
the mutable vector \(\mathbf{c}^\star\)

◆ complexity()

virtual Complexity fl::Linear::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::Linear::configure ( const std::string &  parameters)
virtual

Configures the term with the values of \(\mathbf{c}^\star\).

Parameters
parametersas "c1 ... ci ... cn k"

Implements fl::Term.

◆ constructor()

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

◆ create()

template<typename T >
Linear * fl::Linear::create ( const std::string &  name,
const Engine engine,
firstCoefficient,
  ... 
)
inlinestatic

Creates a Linear term from a variadic set of coefficients.

Beware: this method is unsafe and must be used with care by ensuring:

  • the data type of each variadic arguments is the same, e.g., \((1.0, 2.0, 3.0)\) are all fl::scalars. You need to avoid the case of \((1.0, 2, 3.0)\), where the second term will be considered as an int (different from the others) and cause memory issues due to the difference in size between an int and fl::scalar; and
  • the number of variadic arguments is exactly the same as the number of input variables in the engine plus one in order to match the size of the vector \(\mathbf{c}^\star\)
Parameters
nameis the name of the term
engineis the engine from which the vector \(\mathbf{v}\) will be obtained
firstCoefficientis the coefficient for the first input variable, namely \(c_1\)
...is a variadic number of coefficients whose type need to be the same as the first coefficient
Returns
a new Linear term with the given parameters

Definition at line 161 of file Linear.h.

References FL_AT.

◆ getEngine()

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

Gets the engine from which the vector \(\mathbf{v}\) will be obtained upon computing the Linear::membership()

Returns
the engine from which the vector \(\mathbf{v}\) will be obtained

◆ membership()

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

Computes the linear function \(f(x)=\sum_i c_iv_i +k\), where \(v_i\) is the value of the input variable \(i\) registered in the Linear::getEngine()

Parameters
xis not utilized
Returns
\(\sum_i c_ix_i +k\)

Implements fl::Term.

◆ parameters()

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

Returns the vector \(\mathbf{c}^\star\).

Returns
"c1 ... ci ... cn k"

Implements fl::Term.

◆ set()

virtual void fl::Linear::set ( const std::vector< scalar > &  coefficients,
const Engine engine 
)
virtual

Sets the vector \(\mathbf{c}^\star\) and the Engine from which vector \(\mathbf{v}\) will be retrieved when necessary.

Parameters
coefficientsis the vector \(\mathbf{c}^\star\)
engineis the engine from which \(\mathbf{v}\) will be retrieved when necessary

◆ setCoefficients()

virtual void fl::Linear::setCoefficients ( const std::vector< scalar > &  coefficients)
virtual

Sets the vector \(\mathbf{c}^\star\) of the linear function.

Parameters
coefficientsis the vector \(\mathbf{c}^\star\)

◆ setEngine()

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

Sets the engine from which the vector \(\mathbf{v}\) will be obtained upon computing the Linear::membership()

Parameters
engineis the engine from which the vector \(\mathbf{v}\) will be obtained

◆ updateReference()

virtual void fl::Linear::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.


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