A fuzzy logic C++ library
|
This is the main class of the library, holds everything is required for a Fis. More...
#include <slifis.hpp>
Public Member Functions | |
SLIFIS (EN_FIS_TYPE FisType=TYPE_MAMDANI) | |
Constructor, default type is "Mamdani". | |
SLIFIS (std::string name, EN_FIS_TYPE Type=TYPE_MAMDANI) | |
Constructor, default type is "Mamdani". | |
Feeding input values, and getting output | |
void | SetInputValue (size_t idx, REALVAL value) |
Sets one input value - 3. | |
void | SetInputValue (std::string inputvar, REALVAL value) |
Sets one input value. | |
void | SetInputValues (const std::vector< REALVAL > &vect) |
Sets input values with the values given in vector vect . | |
void | SetInputValues (const DATA_POINT &dpt, const DATA_DESCR &dd) |
Sets input values with the values given in data point dpt. | |
REALVAL | GetOutputValue () |
Computes the defuzzyfied value from the FIS (Mamdani or TS type) | |
MEMBFUNC | GetOutputMf () |
Return the output membership function, that is, for a given set of input values,. | |
FUZZYVAL | GetFuzzyValue (size_t idx_input, size_t idx_mf) const |
Returns fuzzy value of input set idx_input , using membership function idx_mf . | |
FUZZYVAL | GetFuzzyValue (std::string in_name, size_t idx_mf) const |
Returns fuzzy value of input set of name in_name , using membership function idx_mf . | |
const std::vector< MEMBFUNC > & | GetOutMfVector () const |
const std::vector< size_t > & | GetOutRulesVector () const |
rules : adding rules from data and reducing the rule base | |
bool | AddRuleFromValues (const std::vector< REALVAL > &vect, const VALUE_PTR &out) |
Builds and adds a Mamdani AND rule to the FIS, and compute its degree (v1) | |
bool | AddRuleFromValues (const std::vector< REALVAL > &vect, const VALUE &out) |
Builds and adds a Mamdani AND rule to the FIS, and compute its degree (v2) | |
void | ReduceRuleBase (EN_REDUCE_METHOD method=REDM_HIGHEST_SUM) |
Parse the rule base, and removes rules that have the same premisses but different "consequence" part, based on degree of rule. | |
void | FactorizeRuleBase () |
Factorisation of rule base. | |
bool | BuildRuleBaseFromData (const DATA_SET &dataset, RBB_PARAMS &rbb_params) |
Builds the rule base using the provided data, ok for Madamni or TS FIS type. | |
bool | BuildTSRulesFromValues (const DATA_SET &dataset, RBB_PARAMS &rbb_params) |
Linear fitting with Eigen (least squares, no outlier detection) | |
Handling ouput set of membership functions | |
void | SetOutput (const FUZZY_OUT &f) |
Assigns the set of functions of output membership functions to the given set of functions fout . | |
bool | AddOutputMf (const MEMBFUNC &mf) |
Adds the membership function mf to the output set of functions. | |
void | DeleteOutputMf (size_t idx) |
Delete a MF in the output set. | |
const FUZZY_OUT & | GetOutputSet () const |
Returns reference on output set of functions. | |
std::string | GetOutputName () const |
Returns name of output set of membership functions. | |
Handling inputs sets of membership functions | |
size_t | GetNbInputs () const |
std::string | GetInputName (size_t idx) const |
Returns name of the input membership function associated to index idx . | |
bool | HasInput (std::string s) const |
Returns true is fis already has an input of that name. | |
void | AddInput (const FUZZY_IN &f) |
Adds a set of input membership functions to the classifyier. | |
void | DeleteInput (std::string in_name) |
Delete an input, identified through name. | |
void | DeleteInput (size_t idx) |
Delete an input, identified through index. | |
bool | AddInputMf (std::string name, const MEMBFUNC &mf) |
Adds the membership function mf to the input set of functions identified by name name . Returns false on error (unable to find set of that name, or already a function of that name in set) | |
bool | AddInputMf (size_t idx, const MEMBFUNC &mf) |
Adds the membership function mf to the input set of functions identified by index idx . Returns false on error (already a function of that name in set, or index invalid) | |
void | DeleteInputMf (size_t fs_idx, size_t mf_idx) |
Deletes the membership function identified by index mf_idx from the input set of functions identified by index fs_idx . Returns false on error (invalid index) | |
void | DeleteInputMf (std::string fs_name, size_t mf_idx) |
Deletes the membership function identified by index mf_idx from the input set of functions identified by name fs_name . Returns false on error (unable to find set of that name) | |
void | DeleteAllInputsMf () |
Erases all membership functions of the inputs, does not delete the inputs. | |
void | DeleteAllInputs () |
Deletes all inputs. | |
const FUZZY_IN & | GetInputSet (size_t idx) const |
Returns reference on input set of index idx . | |
const FUZZY_IN & | GetInputSet (std::string inputvar) const |
Returns reference on input set of name name . | |
Handling contained rule base | |
size_t | GetNbRules () const |
void | AddRule (const RULE &r) |
Add the rule rule to the inference system. | |
void | AddRule (const RULE_IDX &rule) |
Experimental, returns false if rule is not valid. Makes sense only if inputs/outputs have been defined. | |
void | DeleteAllRules () |
Deletes all rules. | |
const RULE_BASE & | GetRuleBase () const |
RULE_BASE & | GetRuleBase () |
Managing counting of triggered functions in all the contained sets. | |
void | ClearCounters () |
Clears all counters. | |
void | GenerateHistogramFile () const |
Generates material for plotting histograms of input triggering with gnuplot. | |
void | GetOutputTriggerValues (std::vector< size_t > &v_hits) const |
Return trigger values for the ouput set of membership functions, see Density information. | |
void | GetInputTriggerValues (size_t input_idx, std::vector< size_t > &v_hits) const |
Return trigger values for the input input_idx set of membership functions, see Density information. | |
void | GetInputTriggerValues (std::string fs_name, std::vector< size_t > &v_hits) const |
Return trigger values for the input named name set of membership functions, see Density information. | |
double | GetInputCoeffVar (size_t idx) |
Returns coeff of variation for input input_idx , see Density information for more information. | |
double | GetInputCoeffVar (std::string input_name) |
Returns coeff of variation for input input_name , see Density information for more information. | |
double | GetOutputCoeffVar () |
Returns coeff of variation for FIS output, see Density information for more information. | |
File I/O operations | |
void | Print (FILE *f=stderr) const |
Print data in human-readable form in file f . | |
void | Print (std::string filename) const |
Print data in human-readable form, into file filename . | |
void | Read (std::string filename, EN_AUTO_FILE_FORMAT format_auto=AUTO_EXT_OFF, EN_FIS_CHECKING=EN_FIS_CHECKING_YES) |
Read FIS from a file. | |
void | Write (std::string filename, EN_AUTO_FILE_FORMAT format_auto=AUTO_EXT_OFF) const |
Generic "write" function. | |
Misc. | |
void | Clear () |
const std::string & | GetName () const |
Returns name of Fis. | |
void | SetName (std::string n) |
void | SetDefuzzMethod (EN_DEFUZZMETHOD m) |
void | SetOutputAggregMethod (EN_SNORM snorm) |
void | SetRuleInferenceMethod (EN_TNORM and_op, EN_SNORM or_op) |
EN_DEFUZZMETHOD | GetDefuzzMethod () const |
INF_PARAMS & | GetInferenceParams () |
EN_FIS_TYPE | GetType () const |
bool | IsValid () const |
Checks validity of FIS. | |
bool | Generate3DPlot (INPUT_RANGE &r0, INPUT_RANGE &r1, std::string filename) |
Generates 2 files: a data file and a gnuplot command file to generate a 3D plot of FIS. | |
Defined operators | |
bool | operator== (const SLIFIS &m) const |
Comparison operator. | |
bool | operator!= (const SLIFIS &m) const |
Static Public Member Functions | |
static const char * | GetVersion_String () |
Static member function. | |
static void | SetDefaultIO (EN_FF_TYPE f) |
Private Member Functions | |
void | P_Init (EN_FIS_TYPE Type) |
bool | P_Evaluate_M () |
Computes the output membership function for Mamdani FIS type. | |
bool | P_Evaluate_TS (REALVAL &out_val) |
Evaluates the fis and produces an output value for Takagi-Sugeno FIS type. | |
double | P_ComputeCoeffVar (const std::vector< size_t > &v_hits) |
Does the computing of coeff of variation, see http://en.wikipedia.org/wiki/Coefficient_of_variation. | |
bool | P_Read_bin (std::string filename) |
Read binary FIS file, see SLIFIS::P_Write_bin() for details. | |
bool | P_Write_bin (std::string filename) const |
Save all the data into a binary file. | |
bool | P_Write_FCL (std::string filename) const |
FCL export function, argument is name WITHOUT extension (will be added automatically) | |
bool | P_Read_XML (std::string filename) |
XML file reading, see File Storage. | |
bool | P_Write_XML (std::string filename) const |
XML file write, see File Storage. | |
Private Attributes | |
bool | _HasChanged |
Flag used to know if "something" (rule base, input sets, output set, input values...) has changed in the FIS. | |
RULE_BASE | _rule_base |
The rule base... | |
INPUT_SETS | _InputFuzzySets |
Input sets of membership functions. | |
FUZZY_OUT | _OutputFuzzySet |
Output set of membership functions. | |
MEMBFUNC | _mf_out |
Output membership function, for a given input value. | |
std::vector< MEMBFUNC > | _v_out_mf |
Used only for evaluating output (aggregation of MF produced by several rules) | |
std::vector< size_t > | _v_RuleIndexes |
Used only for evaluating output, holds indexes of the rules used to produce the output membership function. | |
std::string | _fis_name |
EN_FIS_TYPE | _FisType |
TYPE_MAMDANI or TYPE_SUGENO. | |
INF_PARAMS | _InferParams |
Inference parameters. | |
Static Private Attributes | |
static EN_FF_TYPE | _s_file_format = IO_BIN |
default file format used for Write() and Read() operations, change with SetDefaultIO() | |
Friends | |
void | PrintDifferences (FILE *f, const SLIFIS &fis1, const SLIFIS &fis2) |
Prints in f the differences between the two FIS. |
This is the main class of the library, holds everything is required for a Fis.
Contains the following data items:
slifis::SLIFIS::SLIFIS | ( | EN_FIS_TYPE | FisType = TYPE_MAMDANI | ) |
Constructor, default type is "Mamdani".
slifis::SLIFIS::SLIFIS | ( | std::string | name, |
EN_FIS_TYPE | Type = TYPE_MAMDANI |
||
) |
Constructor, default type is "Mamdani".
void slifis::SLIFIS::SetInputValue | ( | size_t | idx, |
REALVAL | value | ||
) |
Sets one input value - 3.
References __IN__, __OUT__, slifis::ERR_MFSET_BAD_INDEX, and SLIFIS_ERROR_2.
Referenced by Process().
void slifis::SLIFIS::SetInputValue | ( | std::string | inputvar, |
REALVAL | value | ||
) |
Sets one input value.
References __IN__, __OUT__, slifis::ERR_MFSET_NONAME, and SLIFIS_ERROR_1.
void slifis::SLIFIS::SetInputValues | ( | const std::vector< REALVAL > & | v_in | ) |
Sets input values with the values given in vector vect
.
References __IN__, __OUT__, slifis::ERR_BAD_INPUT_SIZE, and SLIFIS_ERROR_2.
Referenced by main().
void slifis::SLIFIS::SetInputValues | ( | const DATA_POINT & | dpt, |
const DATA_DESCR & | dd | ||
) |
Sets input values with the values given in data point dpt.
References __IN__, __OUT__, slifis::ERR_BAD_INPUT_SIZE, slifis::DATA_POINT::GetInputValue(), slifis::DATA_DESCR::GetNbInputs(), SLIFIS_DEBUG_LOG, and SLIFIS_ERROR_2.
Computes the defuzzyfied value from the FIS (Mamdani or TS type)
References __IN__, __OUT__, slifis::ERR_FIS_DEFUZZ_UNABLE, slifis::ERR_FIS_EVAL_UNABLE, SLIFIS_ERROR, and slifis::TYPE_MAMDANI.
Referenced by main().
Return the output membership function, that is, for a given set of input values,.
returns the function that was built using the rule base.
References __IN__, __OUT__, slifis::ERR_FIS_BAD_TYPE, SLIFIS_ERROR, and slifis::TYPE_MAMDANI.
FUZZYVAL slifis::SLIFIS::GetFuzzyValue | ( | size_t | idx_input, |
size_t | idx_mf | ||
) | const |
Returns fuzzy value of input set idx_input
, using membership function idx_mf
.
References __IN__, __OUT__, slifis::ERR_MFSET_BAD_INDEX, and SLIFIS_ERROR_2.
FUZZYVAL slifis::SLIFIS::GetFuzzyValue | ( | std::string | in_name, |
size_t | idx_mf | ||
) | const |
const std::vector<MEMBFUNC>& slifis::SLIFIS::GetOutMfVector | ( | ) | const [inline] |
const std::vector<size_t>& slifis::SLIFIS::GetOutRulesVector | ( | ) | const [inline] |
References _v_RuleIndexes.
Referenced by main().
bool slifis::SLIFIS::AddRuleFromValues | ( | const std::vector< REALVAL > & | in, |
const VALUE_PTR & | out | ||
) |
Builds and adds a Mamdani AND rule to the FIS, and compute its degree (v1)
according to
Referenced by main().
bool slifis::SLIFIS::AddRuleFromValues | ( | const std::vector< REALVAL > & | in, |
const VALUE & | out | ||
) |
Builds and adds a Mamdani AND rule to the FIS, and compute its degree (v2)
according to
References __IN__, __OUT__, slifis::ERR_FIS_BAD_TYPE, SLIFIS_ERROR, and slifis::TYPE_MAMDANI.
void slifis::SLIFIS::ReduceRuleBase | ( | EN_REDUCE_METHOD | method = REDM_HIGHEST_SUM | ) |
Parse the rule base, and removes rules that have the same premisses but different "consequence" part, based on degree of rule.
References __IN__, __OUT__, SLIFIS_WARNING, and slifis::TYPE_MAMDANI.
Referenced by main().
void slifis::SLIFIS::FactorizeRuleBase | ( | ) |
bool slifis::SLIFIS::BuildRuleBaseFromData | ( | const DATA_SET & | dataset, |
RBB_PARAMS & | rbb_params | ||
) |
Builds the rule base using the provided data, ok for Madamni or TS FIS type.
References __IN__, __OUT__, slifis::RBB_PARAMS::DoFactorize, slifis::RBB_PARAMS::DoReduce, slifis::ERR_DATA_NO_DESCRIPTION, slifis::ERR_UNKNOWN, slifis::DATA_POINT::FillWithInputValues(), slifis::DATA_SET::GetDataPoint(), slifis::DATA_SET::GetDescription(), slifis::DATA_SET::GetNbFields(), slifis::DATA_SET::GetNbPoints(), slifis::DATA_POINT::GetOutputValue(), slifis::RBB_PARAMS::NbPoints, slifis::RBB_PARAMS::NbUnable, slifis::RBB_PARAMS::ReduceMethod, SLIFIS_DEBUG_LOG, SLIFIS_ERROR, SLIFIS_ERROR_1, and slifis::TYPE_SUGENO.
Referenced by main().
bool slifis::SLIFIS::BuildTSRulesFromValues | ( | const DATA_SET & | dataset, |
RBB_PARAMS & | rbb_params | ||
) |
Linear fitting with Eigen (least squares, no outlier detection)
References __IN__, __OUT__, slifis::RULE_IDX::AddTerm(), slifis::RULE_IDX::ComputeTSError(), slifis::DATA_SET::GetInputValues(), slifis::DATA_SET::GetNbPoints(), slifis::DATA_SET::GetOutValue(), slifis::DATA_SET::GetSubset(), slifis::ESTIM_ERROR::relative_error, slifis::ROOT_RULE::SetTSCoeff(), slifis::ROOT_RULE::SetTSConstCoeff(), SLIFIS_DEBUG_LOG, slifis::RBB_PARAMS::TS_fuzzy_threshold, and slifis::TYPE_SUGENO.
void slifis::SLIFIS::SetOutput | ( | const FUZZY_OUT & | f | ) |
Assigns the set of functions of output membership functions to the given set of functions fout
.
References __IN__, __OUT__, slifis::ERR_MFSET_NOT_VALID, slifis::FUZZY_OUT::SetIsValid(), and SLIFIS_ERROR.
Referenced by main().
bool slifis::SLIFIS::AddOutputMf | ( | const MEMBFUNC & | mf | ) |
void slifis::SLIFIS::DeleteOutputMf | ( | size_t | idx | ) |
const FUZZY_OUT & slifis::SLIFIS::GetOutputSet | ( | ) | const |
Returns reference on output set of functions.
Referenced by main(), Mouse_CB_rb_2D(), Mouse_CB_rb_text(), and slifis::PrintDifferences().
std::string slifis::SLIFIS::GetOutputName | ( | ) | const [inline] |
Returns name of output set of membership functions.
References _OutputFuzzySet, and slifis::FUZZY_ROOT::GetName().
size_t slifis::SLIFIS::GetNbInputs | ( | ) | const [inline] |
References _InputFuzzySets, and slifis::INPUT_SETS::GetNb().
Referenced by main(), operator==(), slifis::PrintDifferences(), Process(), and Show().
std::string slifis::SLIFIS::GetInputName | ( | size_t | idx | ) | const |
bool slifis::SLIFIS::HasInput | ( | std::string | s | ) | const |
Returns true is fis already has an input of that name.
void slifis::SLIFIS::AddInput | ( | const FUZZY_IN & | f | ) |
void slifis::SLIFIS::DeleteInput | ( | std::string | in_name | ) |
Delete an input, identified through name.
References __IN__, __OUT__, and SLIFIS_CATCH_RETHROW.
void slifis::SLIFIS::DeleteInput | ( | size_t | idx | ) |
Delete an input, identified through index.
References __IN__, __OUT__, and SLIFIS_CATCH_RETHROW.
bool slifis::SLIFIS::AddInputMf | ( | std::string | name, |
const MEMBFUNC & | mf | ||
) |
bool slifis::SLIFIS::AddInputMf | ( | size_t | idx, |
const MEMBFUNC & | mf | ||
) |
void slifis::SLIFIS::DeleteInputMf | ( | size_t | fs_idx, |
size_t | mf_idx | ||
) |
void slifis::SLIFIS::DeleteInputMf | ( | std::string | fs_name, |
size_t | mf_idx | ||
) |
void slifis::SLIFIS::DeleteAllInputsMf | ( | ) | [inline] |
Erases all membership functions of the inputs, does not delete the inputs.
References _InputFuzzySets, and slifis::INPUT_SETS::DeleteAllMf().
void slifis::SLIFIS::DeleteAllInputs | ( | ) | [inline] |
Deletes all inputs.
References _HasChanged, _InputFuzzySets, and slifis::INPUT_SETS::Clear().
Referenced by main().
const FUZZY_IN & slifis::SLIFIS::GetInputSet | ( | size_t | idx | ) | const |
Returns reference on input set of index idx
.
Referenced by main(), and Mouse_CB_rb_text().
const FUZZY_IN & slifis::SLIFIS::GetInputSet | ( | std::string | inputvar | ) | const |
Returns reference on input set of name name
.
size_t slifis::SLIFIS::GetNbRules | ( | ) | const [inline] |
References _rule_base, and slifis::RULE_BASE::GetNbRules().
Referenced by main().
void slifis::SLIFIS::AddRule | ( | const RULE & | rule | ) |
Add the rule rule
to the inference system.
This functions converts the rule expressed in linguistic terms (RULE) into a rule expressed using indexes of corresponding input and output fuzzyfication (RULE_IDX) Throws an error if:
References __IN__, __OUT__, slifis::RULE_IDX::AddTerm(), slifis::ERR_MF_NAME_NOT_FOUND, slifis::ERR_MFSET_EMPTY, slifis::ERR_NO_INPUTS, slifis::ERR_RULE_BAD_TYPE, slifis::ERR_RULE_NAME_NOT_FOUND, slifis::ERR_RULE_NO_OUTPUT_VAL, slifis::ERR_RULE_NO_TERMS, slifis::ROOT_RULE::GetFisType(), slifis::FUZZY_ROOT::GetMfName(), slifis::FUZZY_ROOT::GetName(), slifis::FUZZY_ROOT::GetNbMf(), slifis::RULE::GetNbTerms(), slifis::RULE::GetOutputValue(), slifis::RULE::GetVarName(), slifis::RULE::GetVarValue(), slifis::RULE_IDX::SetOutMfIndex(), SLIFIS_DEBUG_LOG, SLIFIS_ERROR, SLIFIS_ERROR_2, and slifis::TYPE_MAMDANI.
Referenced by main().
void slifis::SLIFIS::AddRule | ( | const RULE_IDX & | rule | ) |
Experimental, returns false if rule is not valid. Makes sense only if inputs/outputs have been defined.
References __IN__, __OUT__, slifis::ERR_RULE_BAD_INDEX, slifis::ERR_RULE_BAD_TYPE, slifis::ERR_RULE_NO_TERMS, slifis::ROOT_RULE::GetFisType(), slifis::FUZZY_ROOT::GetNbMf(), slifis::RULE_IDX::GetNbTerms(), slifis::RULE_IDX::GetOutMfIndex(), slifis::RULE_IDX::GetTerms(), slifis::RULE_IDX::Print(), SLIFIS_ERROR, SLIFIS_ERROR_2, SLIFIS_ERROR_LOG, SLIFIS_WARNING, and SLIFIS_WARNING_1.
void slifis::SLIFIS::DeleteAllRules | ( | ) | [inline] |
Deletes all rules.
References _HasChanged, _rule_base, slifis::RULE_BASE::Clear(), and ClearCounters().
Referenced by main().
const RULE_BASE& slifis::SLIFIS::GetRuleBase | ( | ) | const [inline] |
References _rule_base.
Referenced by main(), Mouse_CB_rb_2D(), Mouse_CB_rb_text(), slifis::PrintDifferences(), and Process().
RULE_BASE& slifis::SLIFIS::GetRuleBase | ( | ) | [inline] |
References _rule_base.
void slifis::SLIFIS::ClearCounters | ( | ) |
Clears all counters.
This function is called on each modification of FIS (adding or deleting inputs, adding or deleting Mf from inputs, adding or deleting output Mf,...
See Density information.
References slifis::FUZZY_ROOT::ClearCounters().
Referenced by DeleteAllRules().
void slifis::SLIFIS::GenerateHistogramFile | ( | ) | const |
Generates material for plotting histograms of input triggering with gnuplot.
The goal is that the user can appreciate how the choosen sets of functions 'fit' the real data, in a visual way.
See Density information.
With a fis having 'n' input, this function will generate n+2 files:
At present, all files are written in the current directory
Of course, this must be done when some data has been fed to the fis. This can be done in learning stage, or in production stage.
The tool used is gnuplot (http://www.gnuplot.info), a well-known plotting app, freely available for all platforms.
At present, histogram plotting style parameters (gnuplot related) are hard-coded, but you can of course edit this file afterwards.
References __IN__, __OUT__, slifis::ERR_IO_ERROR, SLIFIS_ERROR_1, SLIFIS_STAMP_S, and SLIFIS_WARNING.
Referenced by main().
void slifis::SLIFIS::GetOutputTriggerValues | ( | std::vector< size_t > & | v_hits | ) | const |
Return trigger values for the ouput set of membership functions, see Density information.
void slifis::SLIFIS::GetInputTriggerValues | ( | size_t | input_idx, |
std::vector< size_t > & | v_hits | ||
) | const |
Return trigger values for the input input_idx
set of membership functions, see Density information.
References SLIFIS_CATCH_RETHROW.
void slifis::SLIFIS::GetInputTriggerValues | ( | std::string | fs_name, |
std::vector< size_t > & | v_hits | ||
) | const |
Return trigger values for the input named name
set of membership functions, see Density information.
double slifis::SLIFIS::GetInputCoeffVar | ( | size_t | idx | ) |
Returns coeff of variation for input input_idx
, see Density information for more information.
References SLIFIS_WARNING_2.
Referenced by main().
double slifis::SLIFIS::GetInputCoeffVar | ( | std::string | input_name | ) |
Returns coeff of variation for input input_name
, see Density information for more information.
References SLIFIS_WARNING_1.
double slifis::SLIFIS::GetOutputCoeffVar | ( | ) |
Returns coeff of variation for FIS output, see Density information for more information.
Referenced by main().
void slifis::SLIFIS::Print | ( | FILE * | f = stderr | ) | const |
Print data in human-readable form in file f
.
This can be any opened file, or stdout, stderr, ...
References __IN__, __OUT__, slifis::GetString(), and SLIFIS_STAMP_F.
Referenced by main().
void slifis::SLIFIS::Print | ( | std::string | filename | ) | const |
Print data in human-readable form, into file filename
.
References __IN__, __OUT__, and SLIFIS_WARNING_1.
void slifis::SLIFIS::Read | ( | std::string | filename, |
EN_AUTO_FILE_FORMAT | format_auto = AUTO_EXT_OFF , |
||
EN_FIS_CHECKING | do_checking = EN_FIS_CHECKING_YES |
||
) |
Read FIS from a file.
In case of error, throws an error, and writes error message to cerr
References __IN__, __OUT__, slifis::AUTO_EXT_ON, slifis::EN_FIS_CHECKING_YES, slifis::ERR_FIS_NOTVALID, slifis::ERR_IO_ERROR, slifis::GetTypeFromFilename(), slifis::IO_BIN, slifis::IO_FCL, slifis::IO_UNKNOWN, slifis::IO_XML, SLIFIS_ERROR_1, SLIFIS_ERROR_LOG, and SWITCH_ERROR.
Referenced by main().
void slifis::SLIFIS::Write | ( | std::string | filename, |
EN_AUTO_FILE_FORMAT | format_auto = AUTO_EXT_OFF |
||
) | const |
Generic "write" function.
References __IN__, __OUT__, slifis::AUTO_EXT_ON, slifis::ERR_IO_ERROR, slifis::GetTypeFromFilename(), slifis::IO_BIN, slifis::IO_FCL, slifis::IO_UNKNOWN, slifis::IO_XML, SLIFIS_ERROR, SLIFIS_ERROR_1, SLIFIS_ERROR_LOG, and SWITCH_ERROR.
Referenced by main().
void slifis::SLIFIS::Clear | ( | ) |
const std::string & slifis::SLIFIS::GetName | ( | ) | const [inline] |
void slifis::SLIFIS::SetName | ( | std::string | n | ) | [inline] |
References _fis_name.
void slifis::SLIFIS::SetDefuzzMethod | ( | EN_DEFUZZMETHOD | m | ) | [inline] |
References _InferParams, and slifis::INF_PARAMS::DefuzzMethod.
Referenced by main().
void slifis::SLIFIS::SetOutputAggregMethod | ( | EN_SNORM | snorm | ) | [inline] |
References _InferParams, and slifis::INF_PARAMS::OutputAggregation.
void slifis::SLIFIS::SetRuleInferenceMethod | ( | EN_TNORM | and_op, |
EN_SNORM | or_op | ||
) | [inline] |
References _InferParams, slifis::INF_PARAMS::RuleAndMethod, and slifis::INF_PARAMS::RuleOrMethod.
EN_DEFUZZMETHOD slifis::SLIFIS::GetDefuzzMethod | ( | ) | const [inline] |
References _InferParams, and slifis::INF_PARAMS::DefuzzMethod.
INF_PARAMS& slifis::SLIFIS::GetInferenceParams | ( | ) | [inline] |
References _InferParams.
EN_FIS_TYPE slifis::SLIFIS::GetType | ( | ) | const [inline] |
References _FisType.
Referenced by main(), operator==(), and slifis::PrintDifferences().
bool slifis::SLIFIS::IsValid | ( | ) | const |
Checks validity of FIS.
A FIS must have:
References __IN__, __OUT__, and SLIFIS_ERROR_LOG.
bool slifis::SLIFIS::Generate3DPlot | ( | INPUT_RANGE & | rx, |
INPUT_RANGE & | ry, | ||
std::string | filename | ||
) |
Generates 2 files: a data file and a gnuplot command file to generate a 3D plot of FIS.
References __IN__, __OUT__, slifis::INPUT_RANGE::GetCurrentValue(), slifis::INPUT_RANGE::GetName(), slifis::INPUT_RANGE::GetNbSteps(), slifis::INPUT_RANGE::Init(), SLIFIS_ERROR_LOG, and SLIFIS_STAMP_S.
Referenced by main().
const char * slifis::SLIFIS::GetVersion_String | ( | ) | [static] |
static void slifis::SLIFIS::SetDefaultIO | ( | EN_FF_TYPE | f | ) | [inline, static] |
References _s_file_format.
Referenced by main().
bool slifis::SLIFIS::operator== | ( | const SLIFIS & | m | ) | const |
Comparison operator.
References _InferParams, _InputFuzzySets, _OutputFuzzySet, _rule_base, slifis::INPUT_SETS::GetMfSet(), GetNbInputs(), and GetType().
bool slifis::SLIFIS::operator!= | ( | const SLIFIS & | m | ) | const [inline] |
void slifis::SLIFIS::P_Init | ( | EN_FIS_TYPE | Type | ) | [private] |
bool slifis::SLIFIS::P_Evaluate_M | ( | ) | [private] |
Computes the output membership function for Mamdani FIS type.
Returns false if unable
See FIS usage and Defuzzification.
References __IN__, __OUT__, slifis::ERR_UNKNOWN, slifis::FUZZY_ROOT::FindBestMf(), slifis::FuzzyBSum(), slifis::FuzzyMax(), slifis::FuzzyPSum(), slifis::FUZZY_IN::GetInputValue(), slifis::RULE_IDX::GetNbTerms(), slifis::RULE_IDX::GetOutMfIndex(), slifis::RULE_IDX::GetRuleFiringStrength(), slifis::MEMBFUNC::IsNull(), slifis::MEMBFUNC::Print(), slifis::MEMBFUNC::Scale(), slifis::MEMBFUNC::SetName(), SLIFIS_DEBUG_LOG, SLIFIS_ERROR, SLIFIS_WARNING, slifis::SN_BSUM, slifis::SN_MAX, slifis::SN_PSUM, SWITCH_ERROR, slifis::TN_MIN, slifis::TN_PROD, slifis::FUZZY_ROOT::Trigger(), and slifis::MEMBFUNC::Truncate().
bool slifis::SLIFIS::P_Evaluate_TS | ( | REALVAL & | out_val | ) | [private] |
Evaluates the fis and produces an output value for Takagi-Sugeno FIS type.
Inference method: for each rule, we compute its firing strength (see Firing strength of a rule), the corresponding value computed from the coefficients, and the global output value is the weighted means of all the values.
See FIS usage and Defuzzification.
References __IN__, __OUT__, slifis::RULE_IDX::GetRuleFiringStrength(), slifis::ROOT_RULE::GetTSOutputValue(), slifis::FUZZYVAL::IsZero(), SLIFIS_DEBUG_LOG, and SLIFIS_WARNING.
double slifis::SLIFIS::P_ComputeCoeffVar | ( | const std::vector< size_t > & | v_hits | ) | [private] |
Does the computing of coeff of variation, see http://en.wikipedia.org/wiki/Coefficient_of_variation.
bool slifis::SLIFIS::P_Read_bin | ( | std::string | filename | ) | [private] |
Read binary FIS file, see SLIFIS::P_Write_bin() for details.
References __IN__, __OUT__, slifis::g_current_bin_file_format(), slifis::FUZZY_ROOT::P_Read_bin(), SLIFIS_ERROR_LOG, SLIFIS_WARNING, SLIFIS_WARNING_1, STREAM_OK_TEST, STREAM_READ_STRING, and STREAMCHECK_INIT.
bool slifis::SLIFIS::P_Write_bin | ( | std::string | filename | ) | const [private] |
Save all the data into a binary file.
In case of error, returns false, and writes error message to cerr.
The ordering of data inside file is:
See SLIFIS::P_Read_bin() for reading
References __IN__, __OUT__, slifis::g_current_bin_file_format(), SLIFIS_WARNING, SLIFIS_WARNING_1, STREAM_OK_TEST, STREAM_WRITE_STRING, and STREAMCHECK_INIT.
bool slifis::SLIFIS::P_Write_FCL | ( | std::string | filename | ) | const [private] |
FCL export function, argument is name WITHOUT extension (will be added automatically)
References slifis::FUZZY_ROOT::GetMf(), slifis::FUZZY_ROOT::GetMfName(), slifis::FUZZY_ROOT::GetName(), slifis::MEMBFUNC::GetName(), slifis::FUZZY_ROOT::GetNbMf(), slifis::MEMBFUNC::GetNbPoints(), slifis::RULE_IDX::GetNbTerms(), slifis::GetNow_String(), slifis::ROOT_RULE::GetOpType(), slifis::RULE_IDX::GetOutMfIndex(), slifis::MEMBFUNC::GetPoint(), slifis::RULE_BASE::GetRule(), slifis::GetString(), slifis::RULE_IDX::GetTerms(), slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), slifis::OPR_AND, SLIFIS_ERROR_LOG, and STR.
bool slifis::SLIFIS::P_Read_XML | ( | std::string | filename | ) | [private] |
XML file reading, see File Storage.
References __IN__, __OUT__, slifis::ERR_IO_ERROR, slifis::g_current_xml_file_format(), slifis::GetString(), slifis::FUZZY_ROOT::P_Read_XML(), SLIFIS_ERROR_2, SLIFIS_ERROR_LOG, SLIFIS_XML_READ_INT_ATTRIB, SLIFIS_XML_READ_INT_ATTRIB_2, slifis::TYPE_MAMDANI, and slifis::TYPE_SUGENO.
bool slifis::SLIFIS::P_Write_XML | ( | std::string | filename | ) | const [private] |
XML file write, see File Storage.
References __IN__, __OUT__, slifis::g_current_xml_file_format(), slifis::GetNow_String(), slifis::GetString(), and SLIFIS_ERROR_LOG.
void PrintDifferences | ( | FILE * | f, |
const SLIFIS & | fis1, | ||
const SLIFIS & | fis2 | ||
) | [friend] |
Prints in f
the differences between the two FIS.
EN_FF_TYPE slifis::SLIFIS::_s_file_format = IO_BIN [static, private] |
default file format used for Write() and Read() operations, change with SetDefaultIO()
Referenced by SetDefaultIO().
bool slifis::SLIFIS::_HasChanged [private] |
Flag used to know if "something" (rule base, input sets, output set, input values...) has changed in the FIS.
The ONLY time it is set to 'false' is when output membership function is evaluated (see P_Evaluate_M() )
Referenced by DeleteAllInputs(), and DeleteAllRules().
RULE_BASE slifis::SLIFIS::_rule_base [private] |
The rule base...
Referenced by DeleteAllRules(), GetNbRules(), GetRuleBase(), and operator==().
INPUT_SETS slifis::SLIFIS::_InputFuzzySets [private] |
Input sets of membership functions.
Referenced by DeleteAllInputs(), DeleteAllInputsMf(), GetNbInputs(), operator==(), and slifis::PrintDifferences().
FUZZY_OUT slifis::SLIFIS::_OutputFuzzySet [private] |
Output set of membership functions.
Referenced by GetOutputName(), and operator==().
MEMBFUNC slifis::SLIFIS::_mf_out [private] |
Output membership function, for a given input value.
std::vector<MEMBFUNC> slifis::SLIFIS::_v_out_mf [private] |
Used only for evaluating output (aggregation of MF produced by several rules)
Referenced by GetOutMfVector().
std::vector<size_t> slifis::SLIFIS::_v_RuleIndexes [private] |
Used only for evaluating output, holds indexes of the rules used to produce the output membership function.
Referenced by GetOutRulesVector().
std::string slifis::SLIFIS::_fis_name [private] |
EN_FIS_TYPE slifis::SLIFIS::_FisType [private] |
TYPE_MAMDANI or TYPE_SUGENO.
Referenced by GetType().
INF_PARAMS slifis::SLIFIS::_InferParams [private] |
Inference parameters.
Referenced by GetDefuzzMethod(), GetInferenceParams(), operator==(), SetDefuzzMethod(), SetOutputAggregMethod(), and SetRuleInferenceMethod().