A fuzzy logic C++ library
|
Rule base, expressed as a vector of RULE_IDX. More...
#include <rule_base.hpp>
Public Member Functions | |
Constructors and associated functions | |
RULE_BASE () | |
Constructor. | |
void | Clear () |
void | Changed () const |
Used for signaling from inside or outside that the rule base has been changed, so rb_table needs to be recomputed. | |
I/O functions | |
void | Print (FILE *f=stderr, const char *msg=0) const |
Print Rules List (WIP), see Print2() | |
void | Print2 (FILE *f=stderr, const char *msg=0) const |
Print Rules List (WIP) version 2, see Print() | |
void | Print (std::string filename, const char *msg=0, bool OnlyIndexes=false) const |
void | PrintTable (FILE *f=stderr, const char *msg=0) const |
bool | ExportCSV (std::string fn) const |
Exports to file fn in CSV format, returns true on success. | |
Adding and accessing rules | |
size_t | GetNbRules () const |
void | AddRule (const RULE_IDX &r) |
Add rule r to rule base. Assumes rule is valid, considering the FIS. | |
void | DeleteRule (size_t idx) |
Delete rule idx . | |
bool | AddNewRule (const std::vector< REALVAL > &in, const VALUE &out) |
Builds and adds a AND rule to the FIS, and compute its degree. | |
bool | HasRule (RULE_IDX &r) const |
Returns true if given rule (considering only inputs indexes) is in the rule base, false if not. | |
const RULE_IDX & | GetRule (size_t idx) const |
Returns rule idx (const version) | |
RULE_IDX & | GetRule (size_t idx) |
Returns rule idx (non-const version) | |
int | GetRuleIndex (const RULE_IDX &r) |
Searches the list of rules for a rule identical (only inputs) to r , and returns its index, or -1 if not found. | |
Algorithms | |
void | Reduce (EN_REDUCE_METHOD method) |
Parse the rule base, and removes rules with equal premisses and different consequence part. | |
void | Factorize () |
Checks if some rules can be factorised by input in_idx . Returns nb of rules that were removed. | |
void | Sort (int idx=0) |
Sorting of the rules according to index idx . | |
Misc. | |
bool | rbIsValid () const |
Checks that no rules use an index of either input or output that does not exist in the FIS. | |
size_t | GetNbInputs () const |
Returns nb of inputs associated to the fis associated to this rule base. | |
void | AssignInputSets (const std::vector< FUZZY_IN > &ifs) |
void | AssignInputSets (const INPUT_SETS &ifs) |
void | AssignOutputSet (const FUZZY_OUT &ofs) |
const FUZZY_IN & | GetInputSet (size_t idx) const |
Returns input set nb idx associated to the fis associated to this rule base. | |
const FUZZY_OUT & | GetOutputSet () const |
RB_TABLE * | GetRbtable () const |
Operators | |
bool | operator== (const RULE_BASE &m) const |
bool | operator!= (const RULE_BASE &m) const |
Private Member Functions | |
bool | P_FindBestMf (const FUZZY_ROOT &FuzzySet, REALVAL in, size_t &idx, FUZZYVAL &max) const |
Among the set of MF MfSet , finds the best function for input value in (Private) | |
RULE_IDX | P_SelectBestRule (size_t, size_t, EN_REDUCE_METHOD method) const |
(Private) Helper function for void RULE_BASE::Reduce( EN_REDUCE_METHOD method ). Returns the index on the best rule among the ones | |
int | P_FactorizeBy (size_t in_idx, bool DoRemove) |
Helper function for RULE_BASE::Factorize(), that actually does the job... Returns nb of rules that were removed. | |
void | P_ComputeUsedInputs () const |
Computes how many inputs are effectively handled by the rule base (attribute _v_UsedInputs) | |
bool | P_Write_bin (std::ofstream &f) const |
bool | P_Read_bin (std::ifstream &f) |
Reading of rule base in a stream. | |
bool | P_Write_XML (TiXmlElement *root) const |
bool | P_Read_XML (TiXmlElement *pElem) |
bool | P_HaveSameOutput (const std::vector< std::vector< RULE_IDX >::iterator > &v) const |
Helper function for RULE_BASE::P_Factorize() | |
bool | P_CoversAllInputValues (const std::vector< std::vector< RULE_IDX >::iterator > &v_iter, size_t in_idx) const |
Returns true if all the rules pointed by the iterators in v_iter cover all possible input values for input in_idx . | |
bool | P_HasRefToInputs () const |
Returns true if rule base has a reference on some input set. | |
Private Attributes | |
std::vector< RULE_IDX > | _v_rules |
The rule base. | |
const std::vector< FUZZY_IN > * | pv_InputFuzzySets |
A pointer on the input sets of functions of the SLIFIS object (see RULE_BASE description) | |
const INPUT_SETS * | p_inputset |
const FUZZY_OUT * | p_OutputFuzzySet |
A pointer on the output set of functions of the SLIFIS object. | |
bool | _HasBeenReduced |
True if rule base has been reduced. | |
EN_REDUCE_METHOD | _redmeth |
Method used for reducing the nb of rules. | |
size_t | _BadRulesCounter |
For counting the nb of rules where the FIS was unable to find either an input function, either an output function, in a learning situation (default value is 0) | |
std::vector< size_t > | _v_UsedInputs |
Holds the indexes of inputs that are effectively used in the rule base. | |
RB_TABLE | _rb_table |
This attribute is used ONLY for 2-inputs FIS and rule-bases. | |
Friends | |
class | RB_TABLE |
class | SLIFIS |
bool | rule2_cmp2 (const RULE_IDX &a, const RULE_IDX &b) |
Alternate comparison function, sorts rule by considering first output function index, and second the rule terms, as defined by slifis::RULE_IDX::operator<() |
Rule base, expressed as a vector of RULE_IDX.
It is stored as a vector of RULE_IDX objects. Since these are only made of indexes on input and output membership functions (inside sets of functions), we need to have access to these. This is achieved through the pointers pv_InputFuzzySets and p_OutputFuzzySet, that need to be initialized with a call to AssignMfSets(). Whithout a value value in these pointers, the rule base is meaningless!
These pointers are also used for plotting: when we want to plot a rule base, we need to have access to the underlying input sets, that are not part of the rule base.
For learning rules from data, see Learning rules from data.
Constructor.
References _BadRulesCounter, _HasBeenReduced, _rb_table, slifis::RB_TABLE::AssignRuleBase(), slifis::RULE_IDX::AssignRuleBase(), and Changed().
void slifis::RULE_BASE::Clear | ( | ) |
References _HasBeenReduced, _v_rules, _v_UsedInputs, and Changed().
Referenced by slifis::SLIFIS::DeleteAllRules(), P_Read_bin(), and P_Read_XML().
void slifis::RULE_BASE::Changed | ( | ) | const [inline] |
Used for signaling from inside or outside that the rule base has been changed, so rb_table needs to be recomputed.
This can happen when one extracts a rule from a rule base a reference with GetRule()
References slifis::RB_TABLE::_IsComputed, and _rb_table.
Referenced by AddNewRule(), AddRule(), slifis::RULE_IDX::AddTerm(), AssignInputSets(), AssignOutputSet(), Clear(), slifis::RULE_IDX::Clear(), DeleteRule(), slifis::RULE_IDX::operator=(), P_FactorizeBy(), slifis::RULE_IDX::P_Init(), P_Read_bin(), slifis::RULE_IDX::P_Read_bin(), Reduce(), slifis::RULE_IDX::RemoveTermForInput(), RULE_BASE(), slifis::RULE_IDX::SetOutMfIndex(), and Sort().
void slifis::RULE_BASE::Print | ( | FILE * | f = stderr , |
const char * | msg = 0 |
||
) | const |
Print Rules List (WIP), see Print2()
References __IN__, __OUT__, _BadRulesCounter, _HasBeenReduced, _redmeth, _v_rules, slifis::RULE_IDX::GetDegree(), slifis::ROOT_RULE::GetFisType(), GetInputSet(), slifis::ROOT_RULE::GetNbInputs(), GetNbInputs(), slifis::FUZZY_ROOT::GetNbMf(), GetNbRules(), slifis::RULE_IDX::GetNbTerms(), slifis::ROOT_RULE::GetOpType(), slifis::RULE_IDX::GetOutMfIndex(), GetRule(), slifis::GetString(), slifis::RULE_IDX::GetTerms(), slifis::ROOT_RULE::GetTSCoeff(), slifis::ROOT_RULE::GetTSConstCoeff(), slifis::OPR_AND, slifis::OPR_OR, P_HasRefToInputs(), p_OutputFuzzySet, slifis::RULE_IDX::Print(), pv_InputFuzzySets, SWITCH_ERROR, and slifis::TYPE_MAMDANI.
void slifis::RULE_BASE::Print2 | ( | FILE * | f = stderr , |
const char * | msg = 0 |
||
) | const |
Print Rules List (WIP) version 2, see Print()
References __IN__, __OUT__, _HasBeenReduced, _redmeth, _v_rules, slifis::RULE_IDX::GetDegree(), slifis::ROOT_RULE::GetFisType(), GetInputSet(), slifis::FUZZY_ROOT::GetMf(), slifis::FUZZY_ROOT::GetName(), slifis::MEMBFUNC::GetName(), GetNbInputs(), slifis::FUZZY_ROOT::GetNbMf(), GetNbRules(), slifis::RULE_IDX::GetNbTerms(), slifis::ROOT_RULE::GetOpType(), slifis::RULE_IDX::GetOutMfIndex(), GetRule(), slifis::GetString(), slifis::RULE_IDX::GetTerms(), slifis::ROOT_RULE::GetTSCoeff(), slifis::ROOT_RULE::GetTSConstCoeff(), slifis::OPR_AND, slifis::OPR_OR, P_HasRefToInputs(), p_OutputFuzzySet, slifis::RULE_IDX::Print(), SWITCH_ERROR, and slifis::TYPE_MAMDANI.
Referenced by Print().
void slifis::RULE_BASE::Print | ( | std::string | filename, |
const char * | msg = 0 , |
||
bool | OnlyIndexes = false |
||
) | const |
References __IN__, __OUT__, slifis::ERR_IO_ERROR, Print(), Print2(), and SLIFIS_ERROR_2.
void slifis::RULE_BASE::PrintTable | ( | FILE * | f = stderr , |
const char * | msg = 0 |
||
) | const |
References _rb_table, GetNbInputs(), slifis::RB_TABLE::Print(), and SLIFIS_WARNING.
bool slifis::RULE_BASE::ExportCSV | ( | std::string | fn | ) | const |
Exports to file fn
in CSV format, returns true on success.
Columns :
for each term :
Plus TS coeffs, if any (if the rules are of type 'TS')
References __IN__, __OUT__, _v_UsedInputs, slifis::ERR_RULE_BAD_TYPE, slifis::RULE_IDX::GetDegree(), slifis::ROOT_RULE::GetFisType(), GetNbRules(), slifis::RULE_IDX::GetNbTerms(), slifis::ROOT_RULE::GetOpType(), slifis::RULE_IDX::GetOutMfIndex(), GetRule(), slifis::RULE_IDX::GetTerms(), slifis::ROOT_RULE::GetTSCoeff(), slifis::ROOT_RULE::GetTSConstCoeff(), slifis::ROOT_RULE::GetTSVectorSize(), slifis::OPR_AND, SLIFIS_ERROR_2, SLIFIS_STAMP_S, SLIFIS_WARNING_1, slifis::TYPE_MAMDANI, and slifis::TYPE_SUGENO.
size_t slifis::RULE_BASE::GetNbRules | ( | ) | const [inline] |
References _v_rules.
Referenced by DeleteRule(), slifis_plot::PLOT_RB_TEXT::Draw(), ExportCSV(), Factorize(), slifis::SLIFIS::GetNbRules(), slifis_plot::PLOT_RB_TEXT::GetPositionInfo(), GetRule(), Mouse_CB_rb_2D(), Mouse_CB_rb_text(), operator==(), slifis_plot::PLOT_RB_TEXT::p_ComputePlotSize(), P_ComputeUsedInputs(), slifis_plot::PLOT_RB_2D::P_DrawIndexes(), P_FactorizeBy(), P_Write_bin(), P_Write_XML(), Print(), Print2(), slifis::PrintDifferences(), rbIsValid(), Reduce(), and slifis_plot::PLOT_RB_TEXT::SelectOutput().
void slifis::RULE_BASE::AddRule | ( | const RULE_IDX & | r | ) | [inline] |
Add rule r
to rule base. Assumes rule is valid, considering the FIS.
References __IN__, __OUT__, _HasBeenReduced, _v_rules, Changed(), and P_ComputeUsedInputs().
Referenced by Mouse_CB_rb_2D(), Mouse_CB_rb_text(), and P_Read_XML().
void slifis::RULE_BASE::DeleteRule | ( | size_t | idx | ) |
Delete rule idx
.
References __IN__, __OUT__, _v_rules, Changed(), slifis::ERR_RULE_BAD_INDEX, GetNbRules(), P_ComputeUsedInputs(), and SLIFIS_ERROR_2.
Referenced by Mouse_CB_rb_2D(), and Mouse_CB_rb_text().
bool slifis::RULE_BASE::AddNewRule | ( | const std::vector< REALVAL > & | in, |
const VALUE & | out | ||
) |
Builds and adds a AND rule to the FIS, and compute its degree.
according to:
Returns false if unable to find a matching function for at least one function (that is, for a given input, if the fuzzyfied value is always 0)
in | The vector of input values, in order of input indexes (numeric values only) |
out | The output value, string or numeric |
References __IN__, __OUT__, _BadRulesCounter, _HasBeenReduced, _v_rules, slifis::RULE_IDX::AddTerm(), Changed(), slifis::DT_NUMERIC, slifis::DT_STRING, slifis::ERR_BAD_INPUT_SIZE, slifis::ERR_RULEBASE_NO_POINTERS, slifis::ERR_UNKNOWN, slifis::FUZZY_ROOT::FindMf(), slifis::VALUE::GetFloat(), GetInputSet(), slifis::INPUT_SETS::GetMfSet(), GetNbInputs(), slifis::VALUE::GetString(), slifis::VALUE::GetType(), P_ComputeUsedInputs(), P_FindBestMf(), P_HasRefToInputs(), p_inputset, p_OutputFuzzySet, pv_InputFuzzySets, slifis::RULE_IDX::SetDegree(), slifis::RULE_IDX::SetOutMfIndex(), SLIFIS_DEBUG_LOG, SLIFIS_ERROR, SLIFIS_ERROR_2, SLIFIS_WARNING, SWITCH_ERROR, and slifis::FUZZY_ROOT::Trigger().
bool slifis::RULE_BASE::HasRule | ( | RULE_IDX & | rule | ) | const |
Returns true if given rule
(considering only inputs indexes) is in the rule base, false if not.
If rule found, then it is completed with output membership function index and rule degree of rule rule
. If not found, it is left unchanged.
References _v_rules, slifis::RULE_IDX::SetDegree(), and slifis::RULE_IDX::SetOutMfIndex().
const RULE_IDX & slifis::RULE_BASE::GetRule | ( | size_t | idx | ) | const [inline] |
Returns rule idx
(const version)
References __IN__, __OUT__, _v_rules, slifis::ERR_RULE_BAD_INDEX, GetNbRules(), and SLIFIS_ERROR_2.
Referenced by slifis_plot::PLOT_RB_TEXT::Draw(), ExportCSV(), slifis_plot::PLOT_RB_TEXT::GetPositionInfo(), Mouse_CB_rb_2D(), Mouse_CB_rb_text(), P_ComputeUsedInputs(), P_Write_bin(), slifis::SLIFIS::P_Write_FCL(), P_Write_XML(), Print(), Print2(), slifis::PrintDifferences(), and rbIsValid().
RULE_IDX & slifis::RULE_BASE::GetRule | ( | size_t | idx | ) | [inline] |
Returns rule idx
(non-const version)
References __IN__, __OUT__, _v_rules, slifis::ERR_RULE_BAD_INDEX, GetNbRules(), and SLIFIS_ERROR_2.
int slifis::RULE_BASE::GetRuleIndex | ( | const RULE_IDX & | r | ) |
Searches the list of rules for a rule identical (only inputs) to r
, and returns its index, or -1 if not found.
References _v_rules.
Referenced by Mouse_CB_rb_2D().
void slifis::RULE_BASE::Reduce | ( | EN_REDUCE_METHOD | method | ) |
Parse the rule base, and removes rules with equal premisses and different consequence part.
method
argument, see slifis::EN_REDUCE_METHOD.References __IN__, __OUT__, _HasBeenReduced, _redmeth, _v_rules, Changed(), GetNbRules(), P_SelectBestRule(), slifis::PremisesAreEqual(), slifis::RULE_IDX::SetOrgNbRules(), and Sort().
void slifis::RULE_BASE::Factorize | ( | ) |
Checks if some rules can be factorised by input in_idx
. Returns nb of rules that were removed.
For example, say we have (after reducing) in the rule base the following subset of rules, for a FIS of 2 inputs, with input 1 made of 2 functions, input 2 made of 3 functions:
Then, it is clear that these 3 rules can be reduced to a single rule :
Warning ! : this algorithm relies on a sorted rule base !
References __IN__, __OUT__, _v_UsedInputs, GetNbRules(), P_ComputeUsedInputs(), P_FactorizeBy(), and SLIFIS_WARNING.
void slifis::RULE_BASE::Sort | ( | int | idx = 0 | ) |
Sorting of the rules according to index idx
.
if idx
is equal to -1, then the rules will get sorted by output function index
References __IN__, __OUT__, _v_rules, Changed(), slifis::ERR_RULEBASE_NO_POINTERS, slifis::INPUT_SETS::GetNb(), P_HasRefToInputs(), p_inputset, p_OutputFuzzySet, pv_InputFuzzySets, rule2_cmp2, slifis::ROOT_RULE::SetNbInputs(), slifis::RULE_IDX::SetSortIndex(), and SLIFIS_ERROR.
Referenced by Reduce().
bool slifis::RULE_BASE::rbIsValid | ( | ) | const |
Checks that no rules use an index of either input or output that does not exist in the FIS.
References __IN__, __OUT__, GetInputSet(), GetNbInputs(), slifis::FUZZY_ROOT::GetNbMf(), GetNbRules(), slifis::RULE_IDX::GetOutMfIndex(), GetRule(), slifis::RULE_IDX::GetTerms(), P_HasRefToInputs(), p_OutputFuzzySet, and SLIFIS_ERROR_LOG.
size_t slifis::RULE_BASE::GetNbInputs | ( | ) | const [inline] |
Returns nb of inputs associated to the fis associated to this rule base.
References __IN__, __OUT__, slifis::ERR_RULEBASE_NO_POINTERS, slifis::INPUT_SETS::GetNb(), P_HasRefToInputs(), p_inputset, pv_InputFuzzySets, and SLIFIS_ERROR.
Referenced by AddNewRule(), slifis_plot::PLOT_RB_2D::Draw(), slifis_plot::PLOT_RB_TEXT::Draw(), GetInputSet(), slifis_plot::PLOT_RB_TEXT::GetPositionInfo(), slifis_plot::PLOT_RB_TEXT::p_ComputePlotSize(), P_ComputeUsedInputs(), slifis_plot::PLOT_RB_2D::P_DrawFiringStrength(), slifis_plot::PLOT_RB_2D::P_DrawIndexes(), P_FactorizeBy(), Print(), Print2(), PrintTable(), and rbIsValid().
void slifis::RULE_BASE::AssignInputSets | ( | const std::vector< FUZZY_IN > & | ifs | ) |
References Changed(), p_inputset, and pv_InputFuzzySets.
void slifis::RULE_BASE::AssignInputSets | ( | const INPUT_SETS & | ifs | ) |
References Changed(), p_inputset, and pv_InputFuzzySets.
void slifis::RULE_BASE::AssignOutputSet | ( | const FUZZY_OUT & | ofs | ) |
References Changed(), and p_OutputFuzzySet.
const FUZZY_IN & slifis::RULE_BASE::GetInputSet | ( | size_t | idx | ) | const [inline] |
Returns input set nb idx
associated to the fis associated to this rule base.
References __IN__, __OUT__, slifis::ERR_BAD_INPUT_SIZE, slifis::ERR_RULEBASE_NO_POINTERS, slifis::INPUT_SETS::GetMfSet(), GetNbInputs(), P_HasRefToInputs(), p_inputset, pv_InputFuzzySets, SLIFIS_ERROR, and SLIFIS_ERROR_2.
Referenced by AddNewRule(), slifis_plot::PLOT_RB_TEXT::Draw(), slifis_plot::PLOT_RB_TEXT::p_ComputePlotSize(), P_CoversAllInputValues(), Print(), Print2(), and rbIsValid().
const FUZZY_OUT & slifis::RULE_BASE::GetOutputSet | ( | ) | const [inline] |
References __IN__, __OUT__, slifis::ERR_RULEBASE_NO_POINTERS, p_OutputFuzzySet, and SLIFIS_ERROR.
Referenced by slifis_plot::PLOT_RB_TEXT::Draw(), and slifis_plot::PLOT_RB_TEXT::p_ComputePlotSize().
RB_TABLE* slifis::RULE_BASE::GetRbtable | ( | ) | const [inline] |
References _rb_table.
Referenced by slifis_plot::PLOT_RB_2D::PLOT_RB_2D().
bool slifis::RULE_BASE::operator== | ( | const RULE_BASE & | m | ) | const |
References _v_rules, GetNbRules(), P_HasRefToInputs(), and p_OutputFuzzySet.
bool slifis::RULE_BASE::operator!= | ( | const RULE_BASE & | m | ) | const [inline] |
bool slifis::RULE_BASE::P_FindBestMf | ( | const FUZZY_ROOT & | MfSet, |
REALVAL | in, | ||
size_t & | idx, | ||
FUZZYVAL & | fmax | ||
) | const [private] |
Among the set of MF MfSet
, finds the best function for input value in
(Private)
idx
the index of the best MF chosen, and in max
the value of this maximumMfSet | (in) Set of membership functions associated with numerical value |
in | (in) The input value |
idx | (out) index of the best membership function |
fmax | (out) fuzzy value computed with the latter membership function |
References __IN__, __OUT__, slifis::MEMBFUNC::Fuzzify(), slifis::FUZZY_ROOT::GetMf(), slifis::FUZZY_ROOT::GetName(), slifis::FUZZY_ROOT::GetNbMf(), slifis::FUZZYVAL::IsZero(), slifis::FUZZY_ROOT::Print(), SLIFIS_ERROR_LOG, SLIFIS_WARNING, and SLIFIS_WARNING_1.
Referenced by AddNewRule().
RULE_IDX slifis::RULE_BASE::P_SelectBestRule | ( | size_t | idx_start, |
size_t | NbRules, | ||
EN_REDUCE_METHOD | method | ||
) | const [private] |
(Private) Helper function for void RULE_BASE::Reduce( EN_REDUCE_METHOD method ). Returns the index on the best rule among the ones
in the set that are between idx_start
and idx_start
+ NbRules
-1
The meaning of the "best" rule depends on method
(see EN_REDUCE_METHOD)
idx_start | Start index |
NbRules | Nb rules (?) |
method | method for selecting best rule |
References __IN__, __OUT__, _v_rules, slifis::RULE_IDX::GetDegree(), slifis::FUZZY_ROOT::GetNbMf(), p_OutputFuzzySet, slifis::REDM_HIGHEST, slifis::REDM_HIGHEST_NBRULES, slifis::REDM_HIGHEST_SUM, SLIFIS_DEBUG_LOG, SWITCH_ERROR, and VECTOR_ELEM.
Referenced by Reduce().
int slifis::RULE_BASE::P_FactorizeBy | ( | size_t | in_idx, |
bool | DoRemove | ||
) | [private] |
Helper function for RULE_BASE::Factorize(), that actually does the job... Returns nb of rules that were removed.
Algorithm:
idx
idx
(output value not considered), and fill set subset
in_idx | index of input that we want to factorize |
DoRemove | If false, then nothing happens (pseudo const function), we only count how much rules could be removed |
References __IN__, __OUT__, _v_rules, Changed(), GetNbInputs(), GetNbRules(), slifis::RULE_IDX::GetNbTerms(), P_CoversAllInputValues(), P_HasRefToInputs(), P_HaveSameOutput(), slifis::RULE_IDX::P_IsEqualUpToInput(), slifis::RULE_IDX::RemoveTermForInput(), SLIFIS_DEBUG_LOG, and slifis::RULE_IDX::UsesInput().
Referenced by Factorize().
void slifis::RULE_BASE::P_ComputeUsedInputs | ( | ) | const [private] |
Computes how many inputs are effectively handled by the rule base (attribute _v_UsedInputs)
References __IN__, __OUT__, _v_UsedInputs, GetNbInputs(), GetNbRules(), GetRule(), and slifis::RULE_IDX::GetTerms().
Referenced by AddNewRule(), AddRule(), DeleteRule(), and Factorize().
bool slifis::RULE_BASE::P_Write_bin | ( | std::ofstream & | f | ) | const [private] |
References __IN__, __OUT__, GetNbRules(), GetRule(), slifis::RULE_IDX::P_Write_bin(), STREAM_OK_TEST, and STREAMCHECK_INIT.
bool slifis::RULE_BASE::P_Read_bin | ( | std::ifstream & | f | ) | [private] |
Reading of rule base in a stream.
References __IN__, __OUT__, _v_rules, Changed(), Clear(), slifis::RULE_IDX::P_Read_bin(), SLIFIS_ERROR_LOG, STREAM_OK_TEST, and STREAMCHECK_INIT.
bool slifis::RULE_BASE::P_Write_XML | ( | TiXmlElement * | root | ) | const [private] |
References __IN__, __OUT__, GetNbRules(), GetRule(), slifis::RULE_IDX::P_Write_XML(), and SLIFIS_ERROR_LOG.
bool slifis::RULE_BASE::P_Read_XML | ( | TiXmlElement * | pElem | ) | [private] |
References __IN__, __OUT__, AddRule(), Clear(), slifis::RULE_IDX::P_Read_XML(), SLIFIS_ERROR_LOG, and SLIFIS_XML_READ_INT_ATTRIB.
bool slifis::RULE_BASE::P_HaveSameOutput | ( | const std::vector< std::vector< RULE_IDX >::iterator > & | v_rules | ) | const [private] |
Helper function for RULE_BASE::P_Factorize()
Returns true if and only if all the following conditions are met:
v_rules
holds more than 1 rulev_rules
have the same output idx,v_rules
have the same nb of termsArgument v_rules
is a vector of iterators on a vector of RULE_IDX
References __IN__, __OUT__, slifis::RULE_IDX::GetNbTerms(), and slifis::RULE_IDX::GetOutMfIndex().
Referenced by P_FactorizeBy().
bool slifis::RULE_BASE::P_CoversAllInputValues | ( | const std::vector< std::vector< RULE_IDX >::iterator > & | v_iter, |
size_t | in_idx | ||
) | const [private] |
Returns true if all the rules pointed by the iterators in v_iter
cover all possible input values for input in_idx
.
Algorithm:
References __IN__, __OUT__, GetInputSet(), slifis::FUZZY_ROOT::GetNbMf(), slifis::RULE_IDX::GetTerms(), P_HasRefToInputs(), and slifis::RULE_IDX::UsesInput().
Referenced by P_FactorizeBy().
bool slifis::RULE_BASE::P_HasRefToInputs | ( | ) | const [inline, private] |
Returns true if rule base has a reference on some input set.
References p_inputset, and pv_InputFuzzySets.
Referenced by AddNewRule(), GetInputSet(), GetNbInputs(), operator==(), P_CoversAllInputValues(), P_FactorizeBy(), Print(), Print2(), rbIsValid(), and Sort().
friend class RB_TABLE [friend] |
friend class SLIFIS [friend] |
bool rule2_cmp2 | ( | const RULE_IDX & | a, |
const RULE_IDX & | b | ||
) | [friend] |
Alternate comparison function, sorts rule by considering first output function index, and second the rule terms, as defined by slifis::RULE_IDX::operator<()
Referenced by Sort().
std::vector<RULE_IDX> slifis::RULE_BASE::_v_rules [private] |
The rule base.
Referenced by AddNewRule(), AddRule(), Clear(), DeleteRule(), GetNbRules(), GetRule(), GetRuleIndex(), HasRule(), operator==(), P_FactorizeBy(), P_Read_bin(), P_SelectBestRule(), Print(), Print2(), Reduce(), and Sort().
const std::vector<FUZZY_IN>* slifis::RULE_BASE::pv_InputFuzzySets [private] |
A pointer on the input sets of functions of the SLIFIS object (see RULE_BASE description)
Referenced by AddNewRule(), AssignInputSets(), GetInputSet(), GetNbInputs(), P_HasRefToInputs(), Print(), and Sort().
const INPUT_SETS* slifis::RULE_BASE::p_inputset [private] |
Referenced by AddNewRule(), AssignInputSets(), GetInputSet(), GetNbInputs(), P_HasRefToInputs(), and Sort().
const FUZZY_OUT* slifis::RULE_BASE::p_OutputFuzzySet [private] |
A pointer on the output set of functions of the SLIFIS object.
Referenced by AddNewRule(), AssignOutputSet(), GetOutputSet(), operator==(), P_SelectBestRule(), Print(), Print2(), rbIsValid(), and Sort().
bool slifis::RULE_BASE::_HasBeenReduced [private] |
True if rule base has been reduced.
Referenced by AddNewRule(), AddRule(), Clear(), Print(), Print2(), Reduce(), and RULE_BASE().
EN_REDUCE_METHOD slifis::RULE_BASE::_redmeth [private] |
size_t slifis::RULE_BASE::_BadRulesCounter [private] |
For counting the nb of rules where the FIS was unable to find either an input function, either an output function, in a learning situation (default value is 0)
Referenced by AddNewRule(), Print(), and RULE_BASE().
std::vector<size_t> slifis::RULE_BASE::_v_UsedInputs [mutable, private] |
Holds the indexes of inputs that are effectively used in the rule base.
For example, a FIS can have 6 inputs, but its rule base only use 4 of them. Either because rules have been given directly, either because the learned rule base has been reduced and factorised
This vector is filled by RULE_BASE::P_ComputeUsedInputs()
Referenced by Clear(), ExportCSV(), Factorize(), and P_ComputeUsedInputs().
RB_TABLE slifis::RULE_BASE::_rb_table [mutable, private] |
This attribute is used ONLY for 2-inputs FIS and rule-bases.
Referenced by Changed(), GetRbtable(), PrintTable(), and RULE_BASE().