A fuzzy logic C++ library
|
Virtual class, designed to be inherited into FUZZY_IN and FUZZY_OUT. More...
#include <fuzzy_root.hpp>
Public Member Functions | |
virtual | ~FUZZY_ROOT () |
Destructor (empty) | |
void | SetTriangularSet (const std::vector< REALVAL > &v_mf) |
Creates in the set triangular membership functions. | |
void | SetTriangularSet (REALVAL vmin, REALVAL vmax, size_t NbFunc, EN_FUNCSPACING s=FS_LIN) |
Creates in the set triangular membership functions. | |
void | SetNormalisedSet (const std::vector< REALVAL > &v_pts) |
Creates in the set triangular membership functions plus one HL at the right, and one LH at the left, so set is normalised. | |
void | SetNormalisedSet (REALVAL vmin, REALVAL vmax, size_t NbFunc, EN_FUNCSPACING s=FS_LIN) |
Creates in the set triangular membership functions plus one HL at the right, and one LH at the left, so set is normalised. | |
bool | operator== (const FUZZY_ROOT &fr2) const |
Equality operator. Returns true if all the contained membership functions are equal. | |
bool | operator!= (const FUZZY_ROOT &m) const |
Fetching one of the functions of the set | |
const MEMBFUNC & | GetMf (size_t idx) const |
A 'const' version, so it can be called for read-only operation. | |
MEMBFUNC & | GetMf (size_t idx) |
Returns a reference on the function that has index idx . | |
MEMBFUNC & | GetMf (std::string n) |
Editing set (adding or removing functions) | |
void | DeleteMf (const std::string name) |
Delete contained function identified by name name . | |
void | DeleteMf (size_t idx) |
Delete contained membership function identified by index idx . Returns true on success, false if index is invalid. | |
void | DeleteAllMf () |
bool | AddMf (const MEMBFUNC &mf) |
Adds the membership function mf to the set (with checking) | |
void | Clear () |
Clears vector of functions, keeps the name. | |
Managing counting of triggered functions in this set (see FUZZY_ROOT::_v_trigger) | |
void | ClearCounters () const |
Clears all counters. | |
void | Trigger (size_t idx) const |
Trigger function idx . | |
size_t | GetNbHits () const |
void | GenerateHistogramDataFile (std::string s, size_t n=0) const |
Creates a data file in the current folder with ready-to-plot data of the triggers. | |
const std::vector< size_t > & | GetTriggerValues () const |
returns the vector holding the triggered values | |
Information on set | |
size_t | GetNbMf () const |
bool | IsNormalised () const |
Returns true if set is normalised, that is if for every x,. | |
virtual bool | SetIsValid () const =0 |
Name related | |
Returns name of set. | |
const std::string & | GetName () const |
void | SetName (std::string s) |
Edit name of set. | |
std::string | GetMfName (size_t idx) const |
Returns a copy of the name of function that has index idx . | |
void | SetMfName (size_t idx, std::string n) |
Edit name of one the the contained membership functions. | |
Misc. | |
int | FindMf (const std::string &name) const |
Searches set of functions, and returns index of function that has name name . If not found, returns -1. | |
bool | FindBestMf (REALVAL in, size_t &idx, FUZZYVAL &max) const |
Among the set of membership functions, finds the best function for input value inval . | |
void | Print (FILE *f=stderr) const |
Prints out in f content of set in a human-readable form, no particular formatting. | |
Protected Member Functions | |
FUZZY_ROOT (const std::string &n) | |
Constructor. Here, we keep the reference argument passing, because no user code will use this constructor. | |
bool | P_SetIsValid () const |
Return true if the set of functions is valid. | |
File I/O functions | |
bool | P_Write_bin (std::ofstream &f) const |
Writes the set of membership function into the (opened) binary stream f . | |
bool | P_Read_bin (std::ifstream &f) |
Reads the rule from the (opened) binary stream f . | |
bool | P_Write_XML (TiXmlElement *root) const |
bool | P_Read_XML (TiXmlElement *pElem) |
Protected Attributes | |
std::vector< MEMBFUNC > | _v_mf |
The set of functions contained here. | |
std::string | _name |
Name of this set of membership function (for example, "temperature"). | |
std::vector< size_t > | _v_trigger |
Used for counting the nb of timer a membership function has been triggered by an input in the set (see Density information) | |
Friends | |
class | SLIFIS |
Virtual class, designed to be inherited into FUZZY_IN and FUZZY_OUT.
Contains a vector of membership functions, that are used to fuzzify a real value.
Contains functions for automatic filling with functions from numerical values
slifis::FUZZY_ROOT::FUZZY_ROOT | ( | const std::string & | n | ) | [protected] |
Constructor. Here, we keep the reference argument passing, because no user code will use this constructor.
slifis::FUZZY_ROOT::~FUZZY_ROOT | ( | ) | [virtual] |
Destructor (empty)
void slifis::FUZZY_ROOT::SetTriangularSet | ( | const std::vector< REALVAL > & | v_pts | ) |
Creates in the set triangular membership functions.
For example, if 4 points given, it will create the following partition (2 functions) :
Fuzzy Axis | | 1 + ^ ^ | / \ / \ | / \ / \ 0.5 + / \/ \ | / /\ \ | / / \ \ 0 +======+======+----+======+====== Real Axis v1 v2 v3 v4
Note : 4 points is the minimum accepted
References __IN__, __OUT__, AddMf(), Clear(), slifis::ERR_MFSET_NOT_ENOUGH_POINTS, slifis::MF_TRI, and SLIFIS_ERROR_2.
Referenced by slifis::FUZZY_OUT::FUZZY_OUT(), and SetTriangularSet().
void slifis::FUZZY_ROOT::SetTriangularSet | ( | REALVAL | vmin, |
REALVAL | vmax, | ||
size_t | NbFunc, | ||
EN_FUNCSPACING | spacing = FS_LIN |
||
) |
Creates in the set triangular membership functions.
For example, if 3 functions are requested between values 0 and 10, then 3 intermediate points will be created, and we end up with the following partition
Fuzzy Axis | | 1 | ^ ^ ^ | / \ / \ / \ | / \ / \ / \ | / X X \ | / / \ / \ \ | / / \ / \ \ 0 |------+-----+-----+-----+-----+---- Real Axis v1 v2 v3 v4 v5 0 2.5 5 7.5 10
References __IN__, __OUT__, slifis::ERR_BAD_VALUES, slifis::ERR_MFSET_INVALID_NB, slifis::FS_LIN, slifis::FS_LOG, SetTriangularSet(), SLIFIS_CATCH_RETHROW, SLIFIS_ERROR, SLIFIS_ERROR_2, and SLIFIS_MAXMFPERSET.
void slifis::FUZZY_ROOT::SetNormalisedSet | ( | const std::vector< REALVAL > & | v_pts | ) |
Creates in the set triangular membership functions plus one HL at the right, and one LH at the left, so set is normalised.
For exmple, if a vector of 4 values is given (10,20,30,40), the following set of functions will be built:
Fuzzy Axis | | 1 |------+ ^ ^ +------ | \ / \ / \ / | \ / \ / \ / 0.5 | X X X | / \ / \ / \ | / \ / \ / \ 0 |======+=====+=====+=====+======= Real Axis 10 20 30 40
References __IN__, __OUT__, AddMf(), Clear(), slifis::ERR_MFSET_NOT_ENOUGH_POINTS, slifis::MF_HL, slifis::MF_LH, slifis::MF_TRI, and SLIFIS_ERROR_2.
Referenced by slifis::FUZZY_IN::FUZZY_IN(), main(), and SetNormalisedSet().
void slifis::FUZZY_ROOT::SetNormalisedSet | ( | REALVAL | vmin, |
REALVAL | vmax, | ||
size_t | NbFunc, | ||
EN_FUNCSPACING | spacing = FS_LIN |
||
) |
Creates in the set triangular membership functions plus one HL at the right, and one LH at the left, so set is normalised.
For example, if NbFunc=4, vmin=10 and vmax=40, it will create the following partition:
Fuzzy Axis | | 1 |------+ ^ ^ +------ | \ / \ / \ / | \ / \ / \ / 0.5 | X X X | / \ / \ / \ | / \ / \ / \ 0 |======+=====+=====+=====+======= Real Axis 10 20 30 40
References __IN__, __OUT__, slifis::ERR_BAD_VALUES, slifis::ERR_MFSET_INVALID_NB, slifis::FS_LIN, slifis::FS_LOG, SetNormalisedSet(), SLIFIS_ERROR_2, and SLIFIS_MAXMFPERSET.
const MEMBFUNC & slifis::FUZZY_ROOT::GetMf | ( | size_t | idx | ) | const |
A 'const' version, so it can be called for read-only operation.
Simpler that way. Else, each call on 'GetMf()' using a const object needing some special tweak
References __IN__, __OUT__, _v_mf, slifis::ERR_MF_BAD_INDEX, GetNbMf(), and SLIFIS_ERROR_2.
Referenced by slifis_plot::PLOT_RB_2D::Draw(), slifis_plot::PLOT_RB_TEXT::Draw(), slifis_plot::PLOT_FS::DrawValue(), FindBestMf(), GenerateHistogramDataFile(), slifis::FUZZY_IN::GetFuzzyValue(), slifis::FUZZY_IN::GetInputFiringStrength(), slifis::RULE_IDX::GetRuleFiringStrength(), slifis::DATA_SET::GetSubset(), main(), slifis_plot::PLOT_FS::P_ComputeScale(), slifis_plot::PLOT_RB_2D::P_DrawIndexes(), slifis_plot::PLOT_FS::P_DrawPlot(), slifis::RULE_BASE::P_FindBestMf(), P_SetIsValid(), slifis::SLIFIS::P_Write_FCL(), P_Write_XML(), slifis::RULE_BASE::Print2(), slifis::PrintDifferences(), slifis::FUZZY_OUT::SetIsValid(), and SetMfName().
MEMBFUNC & slifis::FUZZY_ROOT::GetMf | ( | size_t | idx | ) |
Returns a reference on the function that has index idx
.
References __IN__, __OUT__, _v_mf, slifis::ERR_MF_BAD_INDEX, GetNbMf(), and SLIFIS_ERROR_2.
MEMBFUNC & slifis::FUZZY_ROOT::GetMf | ( | std::string | n | ) |
References __IN__, __OUT__, _v_mf, slifis::ERR_MF_NAME_NOT_FOUND, GetNbMf(), and SLIFIS_ERROR.
void slifis::FUZZY_ROOT::DeleteMf | ( | const std::string | name | ) |
Delete contained function identified by name name
.
References __IN__, __OUT__, _v_mf, _v_trigger, slifis::ERR_MFSET_NONAME, FindMf(), and SLIFIS_ERROR_2.
void slifis::FUZZY_ROOT::DeleteMf | ( | size_t | idx | ) |
Delete contained membership function identified by index idx
. Returns true on success, false if index is invalid.
References __IN__, __OUT__, _v_mf, _v_trigger, slifis::ERR_MFSET_BAD_INDEX, GetNbMf(), and SLIFIS_ERROR_2.
void slifis::FUZZY_ROOT::DeleteAllMf | ( | ) | [inline] |
References _v_mf, and ClearCounters().
bool slifis::FUZZY_ROOT::AddMf | ( | const MEMBFUNC & | mf | ) |
Adds the membership function mf
to the set (with checking)
References __IN__, __OUT__, _v_mf, _v_trigger, slifis::ERR_MF_NOT_VALID, FindMf(), slifis::MEMBFUNC::GetName(), slifis::MEMBFUNC::IsValid(), SLIFIS_ERROR, and SLIFIS_WARNING_1.
Referenced by main(), P_Read_XML(), Process(), SetNormalisedSet(), and SetTriangularSet().
void slifis::FUZZY_ROOT::Clear | ( | ) |
Clears vector of functions, keeps the name.
References _v_mf, and _v_trigger.
Referenced by main(), SetNormalisedSet(), and SetTriangularSet().
void slifis::FUZZY_ROOT::ClearCounters | ( | ) | const [inline] |
Clears all counters.
References _v_trigger.
Referenced by slifis::SLIFIS::ClearCounters(), and DeleteAllMf().
void slifis::FUZZY_ROOT::Trigger | ( | size_t | idx | ) | const |
Trigger function idx
.
References __IN__, __OUT__, _v_trigger, slifis::ERR_MFSET_BAD_INDEX, and SLIFIS_ERROR_2.
Referenced by slifis::RULE_BASE::AddNewRule(), and slifis::SLIFIS::P_Evaluate_M().
size_t slifis::FUZZY_ROOT::GetNbHits | ( | ) | const |
References _v_trigger.
Referenced by GenerateHistogramDataFile().
void slifis::FUZZY_ROOT::GenerateHistogramDataFile | ( | std::string | s, |
size_t | n = 0 |
||
) | const |
Creates a data file in the current folder with ready-to-plot data of the triggers.
s
= "in" if input data, and "out" if the (unique) output datan
will be 0 if output, or the index of the input (starting from 1)References __IN__, __OUT__, _v_trigger, slifis::ERR_IO_ERROR, GetMf(), GetName(), slifis::MEMBFUNC::GetName(), GetNbHits(), SLIFIS_ERROR_2, and SLIFIS_STAMP_S.
const std::vector< size_t > & slifis::FUZZY_ROOT::GetTriggerValues | ( | ) | const [inline] |
bool slifis::FUZZY_ROOT::operator== | ( | const FUZZY_ROOT & | fr2 | ) | const |
bool slifis::FUZZY_ROOT::operator!= | ( | const FUZZY_ROOT & | m | ) | const [inline] |
size_t slifis::FUZZY_ROOT::GetNbMf | ( | ) | const [inline] |
References _v_mf.
Referenced by slifis::SLIFIS::AddRule(), DeleteMf(), slifis_plot::PLOT_RB_2D::Draw(), slifis_plot::PLOT_FS::DrawValue(), FindBestMf(), FindMf(), slifis_plot::GetFiringStrengthVector(), slifis::FUZZY_IN::GetFuzzyValue(), slifis::FUZZY_IN::GetInputFiringStrength(), GetMf(), GetMfName(), slifis::RULE_IDX::GetRuleFiringStrength(), slifis::DATA_SET::GetSubset(), IsNormalised(), main(), Mouse_CB_rb_2D(), Mouse_CB_rb_text(), operator==(), slifis_plot::PLOT_RB_TEXT::p_ComputePlotSize(), slifis_plot::PLOT_FS::P_ComputeScale(), slifis::RULE_BASE::P_CoversAllInputValues(), slifis_plot::PLOT_FS::P_DrawPlot(), slifis::RULE_BASE::P_FindBestMf(), slifis::RULE_BASE::P_SelectBestRule(), P_SetIsValid(), P_Write_bin(), slifis::SLIFIS::P_Write_FCL(), P_Write_XML(), slifis::RULE_BASE::Print(), Print(), slifis::RULE_BASE::Print2(), slifis::PrintDifferences(), slifis::RULE_BASE::rbIsValid(), slifis_plot::PLOT_FS::SelectMf(), slifis::FUZZY_OUT::SetIsValid(), and SetMfName().
bool slifis::FUZZY_ROOT::IsNormalised | ( | ) | const |
Returns true if set is normalised, that is if for every x,.
Please note that an empty set will return false.
Method used :
References __IN__, __OUT__, _v_mf, slifis::MEMBFUNC::Fuzzify(), GetNbMf(), slifis::MEMBFUNC::GetNbPoints(), slifis::MEMBFUNC::GetPoint(), slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), and slifis::FUZZYVAL::IsOne().
virtual bool slifis::FUZZY_ROOT::SetIsValid | ( | ) | const [pure virtual] |
Implemented in slifis::FUZZY_IN, and slifis::FUZZY_OUT.
const std::string& slifis::FUZZY_ROOT::GetName | ( | ) | const [inline] |
References _name.
Referenced by slifis::INPUT_SETS::Add(), slifis::SLIFIS::AddRule(), slifis_plot::PLOT_RB_TEXT::Draw(), FindBestMf(), GenerateHistogramDataFile(), slifis::SLIFIS::GetOutputName(), slifis_plot::PLOT_FS::GetPlotName(), main(), slifis_plot::PLOT_RB_TEXT::p_ComputePlotSize(), slifis_plot::PLOT_FS::P_ComputeScale(), slifis_plot::PLOT_RB_2D::P_DrawIndexes(), slifis_plot::PLOT_FS::P_DrawPlot(), slifis::RULE_BASE::P_FindBestMf(), slifis::SLIFIS::P_Write_FCL(), P_Write_XML(), and slifis::RULE_BASE::Print2().
void slifis::FUZZY_ROOT::SetName | ( | std::string | s | ) | [inline] |
std::string slifis::FUZZY_ROOT::GetMfName | ( | size_t | idx | ) | const |
Returns a copy of the name of function that has index idx
.
References __IN__, __OUT__, _v_mf, slifis::ERR_MF_BAD_INDEX, GetNbMf(), and SLIFIS_ERROR_2.
Referenced by slifis::SLIFIS::AddRule(), slifis_plot::PLOT_RB_TEXT::Draw(), slifis_plot::PLOT_RB_TEXT::p_ComputePlotSize(), and slifis::SLIFIS::P_Write_FCL().
void slifis::FUZZY_ROOT::SetMfName | ( | size_t | idx, |
std::string | n | ||
) |
Edit name of one the the contained membership functions.
References __IN__, __OUT__, slifis::ERR_MF_BAD_INDEX, GetMf(), GetNbMf(), slifis::MEMBFUNC::SetName(), and SLIFIS_ERROR_2.
Referenced by main().
int slifis::FUZZY_ROOT::FindMf | ( | const std::string & | name | ) | const |
Searches set of functions, and returns index of function that has name name
. If not found, returns -1.
References __IN__, __OUT__, _v_mf, and GetNbMf().
Referenced by AddMf(), slifis::RULE_BASE::AddNewRule(), and DeleteMf().
bool slifis::FUZZY_ROOT::FindBestMf | ( | REALVAL | inval, |
size_t & | idx, | ||
FUZZYVAL & | max | ||
) | const |
Among the set of membership functions, finds the best function for input value inval
.
idx
the index of the best MF chosen, and in max
the value of this maximuminval | (in) The input value |
idx | (out) index of the best membership function |
max | (out) fuzzy value computed with the latter membership function |
References __IN__, __OUT__, slifis::MEMBFUNC::Fuzzify(), GetMf(), GetName(), GetNbMf(), slifis::FUZZYVAL::IsZero(), Print(), SLIFIS_ERROR_LOG, SLIFIS_WARNING, and SLIFIS_WARNING_1.
Referenced by slifis::SLIFIS::P_Evaluate_M().
void slifis::FUZZY_ROOT::Print | ( | FILE * | f = stderr | ) | const |
Prints out in f
content of set in a human-readable form, no particular formatting.
References _name, _v_mf, and GetNbMf().
Referenced by FindBestMf(), and slifis::RULE_BASE::P_FindBestMf().
bool slifis::FUZZY_ROOT::P_SetIsValid | ( | ) | const [protected] |
Return true if the set of functions is valid.
References __IN__, __OUT__, GetMf(), GetNbMf(), and slifis::MEMBFUNC::IsValid().
Referenced by slifis::FUZZY_OUT::SetIsValid(), and slifis::FUZZY_IN::SetIsValid().
bool slifis::FUZZY_ROOT::P_Write_bin | ( | std::ofstream & | f | ) | const [protected] |
Writes the set of membership function into the (opened) binary stream f
.
returns true on success, false if I/O error
References __IN__, __OUT__, _name, _v_mf, GetNbMf(), STREAM_OK_TEST, STREAM_WRITE_STRING, and STREAMCHECK_INIT.
bool slifis::FUZZY_ROOT::P_Read_bin | ( | std::ifstream & | f | ) | [protected] |
Reads the rule from the (opened) binary stream f
.
Assumes file pointer is correctly set This function is called only from SLIFIS::Read()
Please note that trigger values ARE NOT read and saved to/from file
References __IN__, __OUT__, _name, _v_mf, _v_trigger, slifis::MEMBFUNC::P_Read_bin(), STREAM_OK_TEST, STREAM_READ_STRING, and STREAMCHECK_INIT.
Referenced by slifis::SLIFIS::P_Read_bin().
bool slifis::FUZZY_ROOT::P_Write_XML | ( | TiXmlElement * | root | ) | const [protected] |
References __IN__, __OUT__, GetMf(), GetName(), GetNbMf(), slifis::MEMBFUNC::P_Write_XML(), and SLIFIS_ERROR_LOG.
bool slifis::FUZZY_ROOT::P_Read_XML | ( | TiXmlElement * | pElem | ) | [protected] |
References __IN__, __OUT__, AddMf(), slifis::MEMBFUNC::P_Read_XML(), SetName(), SLIFIS_ERROR_LOG, SLIFIS_XML_READ_INT_ATTRIB, and SLIFIS_XML_READ_STRING_ATTRIB.
Referenced by slifis::SLIFIS::P_Read_XML().
friend class SLIFIS [friend] |
std::vector<MEMBFUNC> slifis::FUZZY_ROOT::_v_mf [protected] |
The set of functions contained here.
Referenced by AddMf(), Clear(), DeleteAllMf(), DeleteMf(), FindMf(), GetMf(), GetMfName(), GetNbMf(), IsNormalised(), operator==(), P_Read_bin(), P_Write_bin(), and Print().
std::string slifis::FUZZY_ROOT::_name [protected] |
Name of this set of membership function (for example, "temperature").
Referenced by GetName(), P_Read_bin(), P_Write_bin(), Print(), and SetName().
std::vector<size_t> slifis::FUZZY_ROOT::_v_trigger [mutable, protected] |
Used for counting the nb of timer a membership function has been triggered by an input in the set (see Density information)
It can be accessed through 3 member functions:
Please note that for a given input value, several functions can be triggered, due to overlapping of functions.
If adding new code, please take care that this vector size must always be the same size than the the vec_mf
vector.
It is declared 'mutable' because it is not a "real" attribute of the set of functions, just an indicator of how well the set is chosen.
Referenced by AddMf(), Clear(), ClearCounters(), DeleteMf(), GenerateHistogramDataFile(), GetNbHits(), GetTriggerValues(), P_Read_bin(), and Trigger().