A fuzzy logic C++ library
|
Root virtual class for rule, inherited into RULE and RULE_IDX. More...
#include <root_rule.hpp>
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_RULE & | operator= (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 |
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.
slifis::ROOT_RULE::ROOT_RULE | ( | EN_FIS_TYPE | RuleType = TYPE_MAMDANI , |
EN_RULE_OP | op = OPR_AND |
||
) | [protected] |
Default constructor.
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.
EN_RULE_OP slifis::ROOT_RULE::GetOpType | ( | ) | const [inline] |
References _operation.
Referenced by slifis_plot::PLOT_RB_TEXT::Draw(), slifis::RULE_BASE::ExportCSV(), slifis::RULE_IDX::GetRuleFiringStrength(), Mouse_CB_rb_text(), operator=(), operator==(), slifis::SLIFIS::P_Write_FCL(), slifis::RULE_IDX::P_Write_XML(), slifis::PremisesAreEqual(), slifis::RULE_BASE::Print(), slifis::RULE_IDX::Print(), slifis::RULE_BASE::Print2(), and slifis::PrintDifferences().
EN_FIS_TYPE slifis::ROOT_RULE::GetFisType | ( | ) | const [inline] |
Returns the type of the rule (TYPE_MAMDANI or TYPE_SUGENO)
References _RuleType.
Referenced by slifis::SLIFIS::AddRule(), slifis::RULE_IDX::ComputeTSError(), slifis::RULE_BASE::ExportCSV(), GetTSCoeff(), GetTSOutputValue(), operator=(), operator==(), slifis::RULE_IDX::operator==(), slifis::RULE_IDX::P_Read_XML(), slifis::RULE_IDX::P_Write_bin(), slifis::RULE_IDX::P_Write_XML(), slifis::PremisesAreEqual(), slifis::RULE_BASE::Print(), slifis::RULE_IDX::Print(), slifis::RULE_BASE::Print2(), slifis::PrintDifferences(), slifis::RULE_IDX::SetOutMfIndex(), and SetTSCoeff().
void slifis::ROOT_RULE::SetOpType | ( | std::string | operation | ) |
Assigns the operation type of the rule.
References __IN__, __OUT__, _operation, slifis::ERR_RULE_BAD_TYPE, slifis::OPR_AND, slifis::OPR_OR, and SLIFIS_ERROR_2.
Referenced by Mouse_CB_rb_text(), and slifis::RULE_IDX::P_Read_XML().
void slifis::ROOT_RULE::SetFisType | ( | std::string | type | ) |
Assigns the rule type.
See related function:
References __IN__, __OUT__, _RuleType, slifis::ERR_RULE_BAD_TYPE, slifis::GetString(), SLIFIS_ERROR_2, slifis::TYPE_MAMDANI, and slifis::TYPE_SUGENO.
Referenced by slifis::RULE_IDX::P_Read_bin(), and slifis::RULE_IDX::P_Read_XML().
void slifis::ROOT_RULE::SetFisType | ( | EN_FIS_TYPE | type | ) | [inline] |
Assigns the rule type.
References _RuleType.
void slifis::ROOT_RULE::SetOpType | ( | EN_RULE_OP | op | ) | [inline] |
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.
Errors can be of two types:
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 |
Returns TS index for input input_idx
(0-based index)
References __IN__, __OUT__, slifis::ERR_RULE_BAD_TYPE, slifis::ERR_RULE_TS_COEFFS, GetFisType(), GetTSVectorSize(), pv_SugenoOut, SLIFIS_ERROR_1, SLIFIS_ERROR_2, and slifis::TYPE_SUGENO.
Referenced by slifis::RULE_IDX::ComputeTSError(), slifis::RULE_BASE::ExportCSV(), GetTSOutputValue(), slifis::RULE_IDX::P_Write_XML(), slifis::RULE_BASE::Print(), slifis::RULE_IDX::Print(), slifis::RULE_BASE::Print2(), and slifis::PrintDifferences().
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] |
Returns the const coeff of TS Rule.
References _TSConstCoeff.
Referenced by slifis::RULE_IDX::ComputeTSError(), slifis::RULE_BASE::ExportCSV(), GetTSOutputValue(), P_Write_bin(), slifis::RULE_IDX::P_Write_XML(), slifis::RULE_BASE::Print(), slifis::RULE_IDX::Print(), slifis::RULE_BASE::Print2(), and slifis::PrintDifferences().
size_t slifis::ROOT_RULE::GetTSVectorSize | ( | ) | const [inline] |
REALVAL slifis::ROOT_RULE::GetTSOutputValue | ( | const INPUT_SETS & | InputFuzzySets | ) | const |
Returns output value for a Takagi-Sugeno rule, for given input values.
The consequence part of such a rule is :
References __IN__, __OUT__, slifis::ERR_RULE_BAD_TYPE, slifis::ERR_RULE_TS_COEFFS, GetFisType(), slifis::FUZZY_IN::GetInputValue(), slifis::INPUT_SETS::GetMfSet(), slifis::INPUT_SETS::GetNb(), GetTSCoeff(), GetTSConstCoeff(), GetTSVectorSize(), SLIFIS_ERROR, SLIFIS_ERROR_2, and slifis::TYPE_SUGENO.
Referenced by slifis::SLIFIS::P_Evaluate_TS().
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] |
Assignment operator. Rules need to be of same type.
References __IN__, __OUT__, _operation, _RuleType, _TSConstCoeff, slifis::ERR_RULE_BAD_TYPE, slifis::ERR_RULE_INVALID_OP, GetFisType(), GetOpType(), pv_SugenoOut, and SLIFIS_ERROR_2.
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
.
Reimplemented in slifis::RULE_IDX.
References __IN__, __OUT__, _operation, pv_SugenoOut, SetTSConstCoeff(), STREAM_OK_TEST, and STREAMCHECK_INIT.
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().
EN_RULE_OP slifis::ROOT_RULE::_operation [private] |
Operation type of the rule (AND or OR)
Referenced by GetOpType(), operator=(), P_Read_bin(), P_Write_bin(), ROOT_RULE(), and SetOpType().
EN_FIS_TYPE slifis::ROOT_RULE::_RuleType [private] |
Referenced by GetFisType(), operator=(), ROOT_RULE(), and SetFisType().
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().
double slifis::ROOT_RULE::_TSConstCoeff [private] |
const coeff for TS rules
Referenced by GetTSConstCoeff(), operator=(), operator==(), ROOT_RULE(), and SetTSConstCoeff().