A fuzzy logic C++ library
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | Private Attributes
slifis::ROOT_RULE Class Reference

Root virtual class for rule, inherited into RULE and RULE_IDX. More...

#include <root_rule.hpp>

+ Inheritance diagram for slifis::ROOT_RULE:
+ Collaboration diagram for slifis::ROOT_RULE:

List of all members.

Public Member Functions

EN_RULE_OP GetOpType () const
EN_FIS_TYPE GetFisType () const
 Returns the type of the rule (TYPE_MAMDANI or TYPE_SUGENO)
void SetOpType (std::string operation)
 Assigns the operation type of the rule.
void SetFisType (std::string type)
 Assigns the rule type.
void SetFisType (EN_FIS_TYPE type)
 Assigns the rule type.
void SetOpType (EN_RULE_OP op)
void SetTSCoeffs (const std::vector< double > &v_d)
 Assigns the values in vector v_d to the Takagi-Sugeno coeffs in rule.
void SetTSCoeff (size_t idx, double val)
 Assigns the value val to the Takagi-Sugeno coeff idx in rule.
double GetTSCoeff (size_t idx) const
 Returns TS index for input input_idx (0-based index)
void SetTSConstCoeff (double val)
 Sets the const coeff of TS Rule.
double GetTSConstCoeff () const
 Returns the const coeff of TS Rule.
size_t GetTSVectorSize () const
REALVAL GetTSOutputValue (const INPUT_SETS &InputFuzzySets) const
 Returns output value for a Takagi-Sugeno rule, for given input values.
REALVAL GetTSOutputValue (std::vector< double > &input_values) const
 Returns output value for a Takagi-Sugeno rule, for given input values.

Static Public Member Functions

static void SetNbInputs (size_t n)
static size_t GetNbInputs ()

Protected Member Functions

 ROOT_RULE (EN_FIS_TYPE FisType=TYPE_MAMDANI, EN_RULE_OP t=OPR_AND)
 Default constructor.
 ROOT_RULE (const ROOT_RULE &r)
 Copy constructor.
 ~ROOT_RULE ()
void AllocateTSVector (size_t n)
bool operator== (const ROOT_RULE &r) const
 This operator compares rule operation and type of rule, and TS coeffs, if there are some.
bool operator!= (const ROOT_RULE &m) const
ROOT_RULEoperator= (const ROOT_RULE &r)
 Assignment operator. Rules need to be of same type.
I/O functions and related
bool P_Write_bin (std::ofstream &f) const
 Writes the rule into the (opened) binary stream f.
bool P_Read_bin (std::ifstream &f)
 Reads the rule from the (opened) binary stream f.

Static Protected Attributes

static size_t s_NbInputs = 0
 Holds the number of inputs of the FIS. This is needed ONLY for sorting (see RULE_IDX::operator <() )

Private Attributes

EN_RULE_OP _operation
 Operation type of the rule (AND or OR)
EN_FIS_TYPE _RuleType
std::vector< double > * pv_SugenoOut
 Pointer on vector, allocated only if Sugeno type rule.
double _TSConstCoeff
 const coeff for TS rules

Detailed Description

Root virtual class for rule, inherited into RULE and RULE_IDX.

Please note that the term aggregation operator is the same for all the terms of the rule. This means that you CAN NOT have rules such as:

"if A is 'this' and B is 'that' or C is 'this', then ..."

For both inherited classes, this rule holds type (Mamdani or TS), aggregation operation, and TS coefficients, if this applies. In case of Mamdani rule, it DOES NOT hold the output value, as this will be a linguistic term in RULE and a numerical index in RULE_IDX.


Constructor & Destructor Documentation

Default constructor.

  • if TS type, the vector is NOT allocated, this will be done when values are given
slifis::ROOT_RULE::ROOT_RULE ( const ROOT_RULE r) [protected]

Copy constructor.

References __IN__, __OUT__, _operation, _RuleType, _TSConstCoeff, and pv_SugenoOut.

slifis::ROOT_RULE::~ROOT_RULE ( ) [inline, protected]

References pv_SugenoOut.


Member Function Documentation

void slifis::ROOT_RULE::SetOpType ( std::string  operation)
void slifis::ROOT_RULE::SetFisType ( std::string  type)
void slifis::ROOT_RULE::SetFisType ( EN_FIS_TYPE  type) [inline]

Assigns the rule type.

References _RuleType.

References _operation.

void slifis::ROOT_RULE::SetTSCoeffs ( const std::vector< double > &  v_d)

Assigns the values in vector v_d to the Takagi-Sugeno coeffs in rule.

References __IN__, __OUT__, and pv_SugenoOut.

void slifis::ROOT_RULE::SetTSCoeff ( size_t  idx,
double  val 
)

Assigns the value val to the Takagi-Sugeno coeff idx in rule.

Warning:
In case of error, a warning will be generated in the log file, and function will abort.

Errors can be of two types:

  • If rule is NOT of type TS
  • If index idx is invalid

References __IN__, __OUT__, slifis::ERR_RULE_BAD_TYPE, GetFisType(), pv_SugenoOut, SLIFIS_ERROR, and slifis::TYPE_SUGENO.

Referenced by slifis::SLIFIS::BuildTSRulesFromValues(), and slifis::RULE_IDX::P_Read_XML().

double slifis::ROOT_RULE::GetTSCoeff ( size_t  idx) const
void slifis::ROOT_RULE::SetTSConstCoeff ( double  val) [inline]

Sets the const coeff of TS Rule.

References _TSConstCoeff.

Referenced by slifis::SLIFIS::BuildTSRulesFromValues(), P_Read_bin(), and slifis::RULE_IDX::P_Read_XML().

double slifis::ROOT_RULE::GetTSConstCoeff ( ) const [inline]
size_t slifis::ROOT_RULE::GetTSVectorSize ( ) const [inline]
REALVAL slifis::ROOT_RULE::GetTSOutputValue ( const INPUT_SETS InputFuzzySets) const
REALVAL slifis::ROOT_RULE::GetTSOutputValue ( std::vector< double > &  input_values) const

Returns output value for a Takagi-Sugeno rule, for given input values.

The consequence part of such a rule is :

out = \sum_1 a_i * x_i + d

References __IN__, __OUT__, slifis::ERR_RULE_BAD_TYPE, slifis::ERR_RULE_TS_COEFFS, GetFisType(), GetTSCoeff(), GetTSConstCoeff(), GetTSVectorSize(), SLIFIS_ERROR, SLIFIS_ERROR_2, and slifis::TYPE_SUGENO.

static void slifis::ROOT_RULE::SetNbInputs ( size_t  n) [inline, static]

References s_NbInputs.

Referenced by slifis::RULE_BASE::Sort().

static size_t slifis::ROOT_RULE::GetNbInputs ( ) [inline, static]

References s_NbInputs.

Referenced by slifis::RULE_BASE::Print().

void slifis::ROOT_RULE::AllocateTSVector ( size_t  n) [protected]

References pv_SugenoOut.

Referenced by slifis::RULE_IDX::P_Read_XML().

bool slifis::ROOT_RULE::operator== ( const ROOT_RULE r) const [protected]

This operator compares rule operation and type of rule, and TS coeffs, if there are some.

References _TSConstCoeff, FLOAT_ARE_EQUAL, GetFisType(), GetOpType(), GetTSVectorSize(), pv_SugenoOut, and slifis::TYPE_SUGENO.

bool slifis::ROOT_RULE::operator!= ( const ROOT_RULE m) const [inline, protected]
ROOT_RULE & slifis::ROOT_RULE::operator= ( const ROOT_RULE r) [protected]
bool slifis::ROOT_RULE::P_Write_bin ( std::ofstream &  f) const [protected]

Writes the rule into the (opened) binary stream f.

Returns true on success, false if I/O error

Please note that in order to avoid future incompatibilities between binary data files that would have been written by different version of this lib that eventually didn't use the same data size for the set stl::map, these values are always written (and read) as the biggest (common...) datatype available, that is: size_t.

Reimplemented in slifis::RULE_IDX.

References __IN__, __OUT__, _operation, GetTSConstCoeff(), pv_SugenoOut, SLIFIS_ERROR_LOG, STREAM_OK_TEST, and STREAMCHECK_INIT.

bool slifis::ROOT_RULE::P_Read_bin ( std::ifstream &  f) [protected]

Reads the rule from the (opened) binary stream f.

  • Assumes file pointer is correctly set

Reimplemented in slifis::RULE_IDX.

References __IN__, __OUT__, _operation, pv_SugenoOut, SetTSConstCoeff(), STREAM_OK_TEST, and STREAMCHECK_INIT.


Member Data Documentation

size_t slifis::ROOT_RULE::s_NbInputs = 0 [static, protected]

Holds the number of inputs of the FIS. This is needed ONLY for sorting (see RULE_IDX::operator <() )

Referenced by GetNbInputs(), slifis::RULE_IDX::operator<(), and SetNbInputs().

Operation type of the rule (AND or OR)

Referenced by GetOpType(), operator=(), P_Read_bin(), P_Write_bin(), ROOT_RULE(), and SetOpType().

std::vector<double>* slifis::ROOT_RULE::pv_SugenoOut [private]

Pointer on vector, allocated only if Sugeno type rule.

Referenced by AllocateTSVector(), GetTSCoeff(), GetTSVectorSize(), operator=(), operator==(), P_Read_bin(), P_Write_bin(), ROOT_RULE(), SetTSCoeff(), SetTSCoeffs(), and ~ROOT_RULE().

const coeff for TS rules

Referenced by GetTSConstCoeff(), operator=(), operator==(), ROOT_RULE(), and SetTSConstCoeff().