Fuzzy Logic Tools  v1.0.5.1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
Classes | Enumerations | Functions | Variables
FLT Namespace Reference

Fuzzy Logic Tools (FLT) namespace. More...

Classes

class  Anymf
 Any Membership function. More...
 
class  Constmf
 Constant Membership function. More...
 
class  Gauss2mf
 Double gaussian Membership function. More...
 
class  Gaussmf
 Gaussian Membership function. More...
 
class  GBellmf
 Bell Membership function. More...
 
class  Membership
 This class contains methods and attributes common to all Membership functions. More...
 
class  Pimf
 Pi (S-Z) Membership function. More...
 
class  PSigmf
 Product of sigmoidals Membership function. More...
 
class  Rule
 This class contains methods and attributes common to fuzzy Rules. More...
 
class  Sig2mf
 Difference of sigmoidals Membership function. More...
 
class  Sigmf
 Sigmoidal Membership function. More...
 
class  Smf
 S Membership function. More...
 
class  System
 This class contains methods and attributes common to fuzzy Systems. More...
 
class  Trapmf
 Trapezoidal Membership function. More...
 
class  Trimf
 Triangular Membership function. More...
 
class  Zmf
 Z Membership function. More...
 

Enumerations

enum  TYPE_MF {
  ANYMF = 0, CONSTMF, GAUSSMF, GAUSS2MF,
  GBELLMF, PIMF, PSIGMF, SMF,
  SIGMF, SIG2MF, TRAPMF, TRIMF,
  ZMF
}
 Enumeration with the implemented Membership functions. More...
 

Functions

TNT::Array2D< double > jacobian (System &S, const double *const x, const double *const u, TNT::Array2D< double > &B, TNT::Array1D< double > &F)
 Computes the open-loop jacobian matrix in x for the Plant S. More...
 
TNT::Array2D< double > jacobian (System &S, System &C, const double *const x)
 Computes the closed-loop jacobian matrix in x for the Plant S and the Controller C. More...
 
TNT::Array2D< double > jacobianAprox (System &S, System &C, const double *const x, double h=0.001)
 Computes the approximation of the closed-loop jacobian matrix in x for the Plant S and the Controller C using finite differences with a step h. More...
 
TNT::Array2D< double > jacobianAprox (System &S, const double *const x, const double *const u, TNT::Array2D< double > &B, TNT::Array1D< double > &F, double h=0.001)
 Computes the approximation of the open-loop jacobian matrix in x for the Plant S using finite differences with a step h. More...
 
double derconseq (System &S, double *x, size_t output, size_t rule, size_t parameter, int &error)
 Obtains the derivative of a fuzzy model with respect to a consequent. More...
 
TNT::Array2D< double > derconseq (System &S, double *x)
 Obtains the jacobian matrix of a fuzzy model with respect to its consequents. More...
 
TNT::Array2D< double > deraffine (System &S, double *x)
 Obtains the jacobian matrix of a fuzzy model with respect to its affine consequents. More...
 
double derantec (System &S, double *x, size_t input, size_t output, size_t rule, size_t parameter, int &error)
 Obtains the derivative of a fuzzy model with respect to a parameter of an antecedent. More...
 
TNT::Array2D< double > derantec (System &S, double *x)
 Obtains the jacobian matrix of a fuzzy model with respect to its antecedents. More...
 
TNT::Array2D< double > derfuzzy (System &S, double *x)
 Obtains the jacobian matrix of a fuzzy model with respect to all of its parameters. More...
 
TNT::Array2D< double > derCLFSconseq (System &P, System &C, const double *const x)
 Obtains the jacobian matrix of a Closed Loop Fuzzy System (CLFS) with respect to the consequents of the fuzzy controller This implementation does not provide for the inclusion of the control signal in the antecedents of the plant. More...
 
TNT::Array1D< double > KalmanAntec (System &Model, TNT::Array1D< double > &input, TNT::Array1D< double > &output, TNT::Array2D< double > &covariance, TNT::Array2D< double > &P, TNT::Array2D< double > &Phi)
 Computes antecedets adjust by the discrete extended Kalman filter. More...
 
TNT::Array1D< double > KalmanAntec (System &Model, TNT::Array1D< double > &input, TNT::Array1D< double > &output, TNT::Array2D< double > &covariance, TNT::Array2D< double > &P)
 Computes antecedets adjust by the discrete extended Kalman filter where Phi is assumed to be the identity matrix. More...
 
TNT::Array1D< double > KalmanConseq (System &Model, TNT::Array1D< double > &input, TNT::Array1D< double > &output, TNT::Array2D< double > &covariance, TNT::Array2D< double > &P, TNT::Array2D< double > &Phi)
 Computes consequents adjust by the discrete extended Kalman filter. More...
 
TNT::Array1D< double > KalmanConseq (System &Model, TNT::Array1D< double > &input, TNT::Array1D< double > &output, TNT::Array2D< double > &covariance, TNT::Array2D< double > &P)
 Computes consequents adjust by the discrete extended Kalman filter where Phi is assumed to be the identity matrix. More...
 
TNT::Array1D< double > KalmanFuz (System &Model, TNT::Array1D< double > &input, TNT::Array1D< double > &output, TNT::Array2D< double > &covariance, TNT::Array2D< double > &P, TNT::Array2D< double > &Phi)
 Computes the simultaneous adjustment of antecedets and consequents by the discrete extended Kalman filter. More...
 
TNT::Array1D< double > KalmanFuz (System &Model, TNT::Array1D< double > &input, TNT::Array1D< double > &output, TNT::Array2D< double > &covariance, TNT::Array2D< double > &P)
 Computes the simultaneous adjustment of antecedets and consequents by the discrete extended Kalman filter where Phi is assumed to be the identity matrix. More...
 
int sign (double x)
 Implementation of the sign function. More...
 
MembershipcreateMF (TYPE_MF t)
 Virtual constructor for Membership functions. More...
 
int System2TXT (System &S, const char *file)
 Saves the fuzzy System S in a text file. More...
 
System TXT2System (const char *file)
 Reads a fuzzy System from a text file. More...
 
int printSystem (const char *file, System &S, char *inputs[]=NULL, char *outputs[]=NULL, int accuracy=10)
 Writes a fuzzy system in its linguistic form. More...
 
TNT::Array1D< double > evaluate (const double *const point, System &S, System &C)
 Evaluates a closed loop fuzzy system in the given point. More...
 
System initialController (System &Plant)
 Creates a fuzzy Controller from a given plant. More...
 
System subSystem (System &S, size_t nrules, size_t *outputs, size_t *rules)
 Extracts a subsystem from a fuzzy System. More...
 
TNT::Array2D< double > extractPoints (System &S, unsigned int numMeshPoints=5, double precision=1E-3, bool addMesh=false, bool onlyStatePoints=true)
 Extracts the representative points of a fuzzy system. More...
 
void col2row_major (const double *const colM, double *rowM, size_t num_rows, size_t num_cols)
 Converts a column-major matrix in a row-major one. More...
 
TNT::Array2D< double > col2row_major (const double *const colM, size_t num_rows, size_t num_cols)
 Converts a column-major matrix in a row-major one. More...
 
void row2col_major (const double *const rowM, double *colM, size_t num_rows, size_t num_cols)
 Converts a row-major matrix in a column-major one. More...
 
int readModel (const mxArray *model, System &S)
 Reads a Fuzzy Model (TXT, FIS file or FIS variable) More...
 
int FIS2System (const mxArray *FIS, System &S)
 Reads the Fuzzy Model from a FIS variable. More...
 
int System2FIS (System &S, mxArray *FIS)
 Writes the Fuzzy Model in a FIS variable. More...
 

Variables

static const char * MF_NAMES []
 Names of the Membership functions. More...
 
static const size_t MF_PARAM_NUMBER []
 Initial number of parameters of each Membership function in FLT::TYPE_MF. More...
 

Detailed Description

Fuzzy Logic Tools (FLT) namespace.

Enumeration Type Documentation

Enumeration with the implemented Membership functions.

FLT::TYPE_MF is used to determinate the Membership function type, FLT::MF_NAMES are the names of the Membership functions, and FLT::MF_PARAM_NUMBER are the initial number of parameters of the Membership functions.

Remarks
FLT::TYPE_MF, FLT::MF_NAMES and FLT::MF_PARAM_NUMBER must be consistent.
Important: If the first or last element of FLT::TYPE_MF are changed, you needd to check membership.cpp (and perhaps others files), because these elements are used to make some comparisons.
Enumerator
ANYMF 

Any Membership function (FLT::Anymf).

CONSTMF 

Constant Membership function (FLT::Constmf).

GAUSSMF 

Gaussian Membership function (FLT::Gaussmf).

GAUSS2MF 

Double gaussian Membership function (FLT::Gauss2mf).

GBELLMF 

Bell Membership function (FLT::GBellmf).

PIMF 

Pi (S-Z) Membership function (FLT::Pimf).

PSIGMF 

Product of sigmoidals Membership function (FLT::PSigmf).

SMF 

S Membership function (FLT::Smf).

SIGMF 

Sigmoidal Membership function (FLT::Sigmf).

SIG2MF 

Difference of sigmoidals Membership function (FLT::Sig2mf).

TRAPMF 

Trapezoidal Membership function (FLT::Trapmf).

TRIMF 

Triangular Membership function (FLT::Trimf).

ZMF 

Z Membership function (FLT::Zmf).

Function Documentation

void FLT::col2row_major ( const double *const  colM,
double *  rowM,
size_t  num_rows,
size_t  num_cols 
)
inline

Converts a column-major matrix in a row-major one.

MATLAB© uses column-major matrices, but C uses row-major.

Examples:
matlab_utilities/Kalmanantec.cpp, matlab_utilities/Kalmanconseq.cpp, and matlab_utilities/Kalmanfuz.cpp.
TNT::Array2D<double> FLT::col2row_major ( const double *const  colM,
size_t  num_rows,
size_t  num_cols 
)
inline

Converts a column-major matrix in a row-major one.

MATLAB© uses column-major matrices, but C uses row-major.

Membership * FLT::createMF ( TYPE_MF  t)

Virtual constructor for Membership functions.

This function create and return a Membership function of the selected type.

TNT::Array2D< double > FLT::deraffine ( System S,
double *  x 
)

Obtains the jacobian matrix of a fuzzy model with respect to its affine consequents.

Returns
Returns an empty array if error.
Examples:
matlab_utilities/fuzderaffine.cpp.
double FLT::derantec ( System S,
double *  x,
size_t  input,
size_t  output,
size_t  rule,
size_t  parameter,
int &  error 
)

Obtains the derivative of a fuzzy model with respect to a parameter of an antecedent.

It is assumed that the output of the system is the same as the parameter, otherwise it should be considered derivative equal to 0.

Returns
If output, rule or parameter are out of System limits, the function returns 0 and error = 1.
Examples:
matlab_utilities/fuzderantec.cpp.
TNT::Array2D< double > FLT::derantec ( System S,
double *  x 
)

Obtains the jacobian matrix of a fuzzy model with respect to its antecedents.

Returns
Returns an empty array if error.
TNT::Array2D<double> FLT::derCLFSconseq ( System &  P,
System &  C,
const double *const  x 
)

Obtains the jacobian matrix of a Closed Loop Fuzzy System (CLFS) with respect to the consequents of the fuzzy controller This implementation does not provide for the inclusion of the control signal in the antecedents of the plant.

Returns
Returns an empty array if error.
double FLT::derconseq ( System S,
double *  x,
size_t  output,
size_t  rule,
size_t  parameter,
int &  error 
)

Obtains the derivative of a fuzzy model with respect to a consequent.

It is assumed that the output of the system is the same as the parameter, otherwise it should be considered derivative equal to 0.

Returns
If output, rule or parameter are out of System limits, the function returns 0 and error = 1.
Examples:
matlab_utilities/fuzderaffine.cpp, and matlab_utilities/fuzderconseq.cpp.
TNT::Array2D< double > FLT::derconseq ( System S,
double *  x 
)

Obtains the jacobian matrix of a fuzzy model with respect to its consequents.

Returns
Returns an empty array if error.
TNT::Array2D< double > FLT::derfuzzy ( System S,
double *  x 
)

Obtains the jacobian matrix of a fuzzy model with respect to all of its parameters.

Returns
Returns an empty array if error.
Examples:
matlab_utilities/fuzderparam.cpp.
Array1D< double > FLT::evaluate ( const double *const  point,
System S,
System C 
)

Evaluates a closed loop fuzzy system in the given point.

S is the plant and C is a fuzzy controller.

Returns
Returns an empty array if error.
Examples:
example.cpp, and matlab_utilities/fuzeval.cpp.
Array2D< double > FLT::extractPoints ( System S,
unsigned int  numMeshPoints = 5,
double  precision = 1E-3,
bool  addMesh = false,
bool  onlyStatePoints = true 
)

Extracts the representative points of a fuzzy system.

Parameters
SIs a fuzzy System.
numMeshPointsIs used in Memberships functions without significative points, like ANYMF, CONSTMF, SMF, ...
precisionIs used to remove similar points.
addMeshIf addMesh is true, a mesh of numMeshPoints for each dimmension will be added to System points.
onlyStatePointsIf onlyStatePoints is true, this function only extracts the state vector points, not the control vector points.
Examples:
matlab_utilities/extractPoints.cpp.
int FLT::FIS2System ( const mxArray *  FIS,
System S 
)

Reads the Fuzzy Model from a FIS variable.

Returns 0 if no errors.

System FLT::initialController ( System Plant)

Creates a fuzzy Controller from a given plant.

The fuzzy controller will have all the rules that the plant owns in each of its outputs.
Consequents all initialized to 0.

Returns
Returns an empty System if error.
Examples:
matlab_utilities/initializeController.cpp.
Array2D< double > FLT::jacobian ( System S,
const double *const  x,
const double *const  u,
TNT::Array2D< double > &  B,
TNT::Array1D< double > &  F 
)

Computes the open-loop jacobian matrix in x for the Plant S.

Obtains the linearization $\mathbf{f}(\mathbf{x},\mathbf{u}) \approx \mathbf{F} + \mathbf{A x} + \mathbf{Bu}$.

Returns
Returns the dynamic matrix, $\mathbf{A}$, or an empty array if error.
Examples:
example.cpp, matlab_utilities/fuzderparam.cpp, matlab_utilities/fuzjac.cpp, and matlab_utilities/fuzlinear.cpp.
TNT::Array2D< double > FLT::jacobian ( System S,
System C,
const double *const  x 
)

Computes the closed-loop jacobian matrix in x for the Plant S and the Controller C.

Returns
Returns the jacobian matrix or an empty array if error.
TNT::Array2D< double > FLT::jacobianAprox ( System S,
System C,
const double *const  x,
double  h = 0.001 
)

Computes the approximation of the closed-loop jacobian matrix in x for the Plant S and the Controller C using finite differences with a step h.

Returns
Returns an empty array if error.
Examples:
matlab_utilities/aproxjac.cpp, and matlab_utilities/aproxlinear.cpp.
TNT::Array2D< double > FLT::jacobianAprox ( System S,
const double *const  x,
const double *const  u,
TNT::Array2D< double > &  B,
TNT::Array1D< double > &  F,
double  h = 0.001 
)

Computes the approximation of the open-loop jacobian matrix in x for the Plant S using finite differences with a step h.

Obtains the linearization $\mathbf{f}(\mathbf{x},\mathbf{u}) \approx \mathbf{F} + \mathbf{A x} + \mathbf{Bu}$.

Returns
Returns the dynamic matrix, $\mathbf{A}$, or an empty array if error.
TNT::Array1D< double > FLT::KalmanAntec ( System Model,
TNT::Array1D< double > &  input,
TNT::Array1D< double > &  output,
TNT::Array2D< double > &  covariance,
TNT::Array2D< double > &  P,
TNT::Array2D< double > &  Phi 
)

Computes antecedets adjust by the discrete extended Kalman filter.

Parameters
ModelIs the fuzzy system whose antecedents will be adjusted.
inputIs the input applied to the system in the current iteration.
outputIs the real output of the system in the current iteration.
covarianceIs the noise covariance matrix estimated from the hope operator.
PIs the covariance matrix of the filter.
PhiIs the Jacobian matrix that relates the parameters to be set with the following value of these parameters. Usually this will be an identity matrix of appropriate dimensions.
Returns
Returns the error vector of the iteration, or an empty vector if there was some error.

Model and P will be changed according to the Kalman discrete filte algorithm.

Examples:
matlab_utilities/Kalmanantec.cpp.
TNT::Array1D< double > FLT::KalmanAntec ( System Model,
TNT::Array1D< double > &  input,
TNT::Array1D< double > &  output,
TNT::Array2D< double > &  covariance,
TNT::Array2D< double > &  P 
)

Computes antecedets adjust by the discrete extended Kalman filter where Phi is assumed to be the identity matrix.

Parameters
ModelIs the fuzzy system whose antecedents will be adjusted.
inputIs the input applied to the system in the current iteration.
outputIs the real output of the system in the current iteration.
covarianceIs the noise covariance matrix estimated from the hope operator.
PIs the covariance matrix of the filter.
Returns
Returns the error vector of the iteration, or an empty vector if there was some error.

Model and P will be changed according to the Kalman discrete filte algorithm.

TNT::Array1D< double > FLT::KalmanConseq ( System Model,
TNT::Array1D< double > &  input,
TNT::Array1D< double > &  output,
TNT::Array2D< double > &  covariance,
TNT::Array2D< double > &  P,
TNT::Array2D< double > &  Phi 
)

Computes consequents adjust by the discrete extended Kalman filter.

Parameters
ModelIs the fuzzy system whose consequents will be adjusted.
inputIs the input applied to the system in the current iteration (current State vector, x(k)).
outputIs the real output of the system in the current iteration.
covarianceIs the noise covariance matrix estimated from the hope operator.
PIs the covariance matrix of the filter.
PhiIs the Jacobian matrix that relates the parameters to be set with the following value of these parameters. Usually this will be an identity matrix of appropriate dimensions.
Returns
Returns the error vector of the iteration, or an empty vector if there was some error.

Model and P will be changed according to the Kalman discrete filte algorithm.

Examples:
matlab_utilities/Kalmanconseq.cpp.
TNT::Array1D< double > FLT::KalmanConseq ( System Model,
TNT::Array1D< double > &  input,
TNT::Array1D< double > &  output,
TNT::Array2D< double > &  covariance,
TNT::Array2D< double > &  P 
)

Computes consequents adjust by the discrete extended Kalman filter where Phi is assumed to be the identity matrix.

Parameters
ModelIs the fuzzy system whose consequents will be adjusted.
inputIs the input applied to the system in the current iteration (current State vector, x(k)).
outputIs the real output of the system in the current iteration.
covarianceIs the noise covariance matrix estimated from the hope operator.
PIs the covariance matrix of the filter.
Returns
Returns the error vector of the iteration, or an empty vector if there was some error.

Model and P will be changed according to the Kalman discrete filte algorithm.

TNT::Array1D< double > FLT::KalmanFuz ( System Model,
TNT::Array1D< double > &  input,
TNT::Array1D< double > &  output,
TNT::Array2D< double > &  covariance,
TNT::Array2D< double > &  P,
TNT::Array2D< double > &  Phi 
)

Computes the simultaneous adjustment of antecedets and consequents by the discrete extended Kalman filter.

Parameters
ModelIs the fuzzy system whose parameters will be adjusted.
inputIs the input applied to the system in the current iteration.
outputIs the real output of the system in the current iteration.
covarianceIs the noise covariance matrix estimated from the hope operator.
PIs the covariance matrix of the filter.
PhiIs the Jacobian matrix that relates the parameters to be set with the following value of these parameters. Usually this will be an identity matrix of appropriate dimensions.
Returns
Returns the error vector of the iteration, or an empty vector if there was some error.

Model and P will be changed according to the Kalman discrete filte algorithm.

Examples:
matlab_utilities/Kalmanfuz.cpp.
TNT::Array1D< double > FLT::KalmanFuz ( System Model,
TNT::Array1D< double > &  input,
TNT::Array1D< double > &  output,
TNT::Array2D< double > &  covariance,
TNT::Array2D< double > &  P 
)

Computes the simultaneous adjustment of antecedets and consequents by the discrete extended Kalman filter where Phi is assumed to be the identity matrix.

Parameters
ModelIs the fuzzy system whose parameters will be adjusted.
inputIs the input applied to the system in the current iteration.
outputIs the real output of the system in the current iteration.
covarianceIs the noise covariance matrix estimated from the hope operator.
PIs the covariance matrix of the filter.
Returns
Returns the error vector of the iteration, or an empty vector if there was some error.

Model and P will be changed according to the Kalman discrete filte algorithm.

int FLT::printSystem ( const char *  file,
System S,
char *  inputs[] = NULL,
char *  outputs[] = NULL,
int  accuracy = 10 
)

Writes a fuzzy system in its linguistic form.

"IF temperature is high and pressure is ... THEN valve is ..."

You can specify the name of the variables and the number of decimals that will be used to represent the system.

Examples:
matlab_utilities/fuzprint.cpp.
int FLT::readModel ( const mxArray *  model,
System S 
)
void FLT::row2col_major ( const double *const  rowM,
double *  colM,
size_t  num_rows,
size_t  num_cols 
)
inline

Converts a row-major matrix in a column-major one.

MATLAB© uses column-major matrices, but C uses row-major.

Examples:
matlab_utilities/Kalmanantec.cpp, matlab_utilities/Kalmanconseq.cpp, and matlab_utilities/Kalmanfuz.cpp.
int FLT::sign ( double  x)
inline

Implementation of the sign function.

Returns
Returns 0 if x=0, 1 if x>0 and -1 if x<0.
System FLT::subSystem ( System S,
size_t  nrules,
size_t *  outputs,
size_t *  rules 
)

Extracts a subsystem from a fuzzy System.

Returns
Returns an empty System if error.
Examples:
matlab_utilities/fuzsubsystem.cpp.
int FLT::System2FIS ( System S,
mxArray *  FIS 
)
int FLT::System2TXT ( System S,
const char *  file 
)

Saves the fuzzy System S in a text file.

Returns
Returns 0 if no errors.
See also
See TXT2System to see the template for the TXT file.
Examples:
matlab_utilities/fis2txt.cpp, and matlab_utilities/fuzcomb.cpp.
System FLT::TXT2System ( const char *  file)

Reads a fuzzy System from a text file.

Returns
Returns an empty System if error.
Template for the TXT file
The text in italics is only helpful, should not appear in the template.

'Number of inputs' 'Number of outputs'
'Number of rules for the 1st ouput' 'Number of rules for the 2nd ouput'
...

Rules: For each output, for each rule in this output:
Antecedents. For each input:

'Type membership function' 'Parameters separated by spaces'
Consequents:
'Affine term' and for each input 'consequents terms separated by spaces'

'lower limit for input 1' 'upper limit for input 1'
'lower limit for input 2' 'upper limit for input 2'

... for all the inputs

'lower limit for output 1' 'upper limit for output 1'
'lower limit for output 2' 'upper limit for output 2'

... for all the outputs
Examples:
example.cpp, and matlab_utilities/txt2fis.cpp.

Variable Documentation

FLT::MF_NAMES
static
Initial value:
=
{
"ANYMF",
"CONSTMF",
"GAUSSMF",
"GAUSS2MF",
"GBELLMF",
"PIMF",
"PSIGMF",
"SMF",
"SIGMF",
"SIG2MF",
"TRAPMF",
"TRIMF",
"ZMF"
}

Names of the Membership functions.

Remarks
FLT::TYPE_MF, FLT::MF_NAMES and FLT::MF_PARAM_NUMBER must be consistent.
FLT::MF_PARAM_NUMBER
static
Initial value:
=
{
0,
1,
2,
4,
3,
4,
4,
2,
2,
4,
4,
3,
2
}

Initial number of parameters of each Membership function in FLT::TYPE_MF.

Remarks
These values are used for initialization, in the code is better use the num_params function from Membership class.
FLT::TYPE_MF, FLT::MF_NAMES and FLT::MF_PARAM_NUMBER must be consistent.