A fuzzy logic C++ library
|
A membership function, defined as a vector of points. More...
#include <membfunc.hpp>
Public Member Functions | |
Constructors and associated functions | |
MEMBFUNC (std::string name="-unnamedMF-") | |
Constructor 1 for empty function, only name given. | |
MEMBFUNC (FUZZYVAL val, std::string name="-unnamedMF-") | |
Constructor 6, for empty function. | |
MEMBFUNC (EN_MF_TYPE t, std::string name, const std::vector< REALVAL > &v) | |
Constructor 2, for any standart type. | |
MEMBFUNC (EN_MF_TYPE t, std::string name, REALVAL v1, REALVAL v2) | |
Constructor 3, for MF_HL, MF_LH, MF_TRI (2 values) or MF_GAUSS type. | |
MEMBFUNC (EN_MF_TYPE t, std::string name, REALVAL v1, REALVAL v2, REALVAL v3) | |
Constructor 4, for MF_TRI type (3 values) | |
MEMBFUNC (EN_MF_TYPE t, std::string name, REALVAL v1, REALVAL v2, REALVAL v3, REALVAL v4) | |
Constructor 5, for MF_LL type (trapezoidal, 4 values required) | |
void | Clear (FUZZYVAL v=0.0) |
Resets function, except name, that remains unchanged. | |
void | SetFrom (const MEMBFUNC &src) |
Copies src into the current function, except for name, that remains unchanged. | |
void | Set (EN_MF_TYPE t, const std::string &name, const std::vector< REALVAL > &v) |
Clears function and sets it according to type t and given values. | |
void | Set (EN_MF_TYPE t, const std::string &name, REALVAL v1, REALVAL v2) |
Clears function and sets it according to type t and given 2 values. | |
void | Set (EN_MF_TYPE t, const std::string &name, REALVAL v1, REALVAL v2, REALVAL v3) |
Clears function and sets it according to type t and given 4 values. | |
void | Set (EN_MF_TYPE t, const std::string &name, REALVAL v1, REALVAL v2, REALVAL v3, REALVAL v4) |
Clears function and sets it according to type t and given 4 values. | |
void | Set (EN_MF_TYPE t, const std::vector< REALVAL > &v) |
Clears function and sets it according to type t and given values. | |
void | Set (EN_MF_TYPE t, REALVAL v1, REALVAL v2) |
Clears function and sets it according to type t and given 2 values. | |
void | Set (EN_MF_TYPE t, REALVAL v1, REALVAL v2, REALVAL v3) |
Clears function and sets it according to t (MF_TRI or MF_LL) | |
void | Set (EN_MF_TYPE t, REALVAL v1, REALVAL v2, REALVAL v3, REALVAL v4) |
Clears function and sets it according to type t and given 4 values. | |
Operators | |
bool | operator== (const MEMBFUNC &m) const |
Equality operator, returns true if functions are the same, up to their name. | |
bool | operator!= (const MEMBFUNC &m) const |
Accessing points, (mostly) const functions | |
FPOINT & | GetPoint (size_t idx) |
Returns a point from a function, identified by its index. | |
const FPOINT & | GetPoint (size_t idx) const |
Returns a point from a function, identified by its index. | |
size_t | GetNbPoints () const |
FUZZYVAL | GetLeftValue () const |
Return "Left" value of function (= first point x-value, if function is not empty, or maximum value if it is) | |
FUZZYVAL | GetRightValue () const |
Return "Right" value of function (= last point y-value, if function is not empty, or maximum value if it is) | |
FPOINT | GetFirstPoint () const |
Returns first point of function. | |
FPOINT | GetLastPoint () const |
Returns last point of function. | |
FUZZYVAL | GetMaxValue () const |
FUZZYVAL | GetMinValue () const |
Information functions (all const) | |
bool | IsEmpty () const |
Returns true if function has no points (but can have a constant value !) | |
bool | IsNull () const |
Returns true if function is null (no points AND 0 value ) | |
bool | IsFinite () const |
Returns true if function value is 0 on left and right sides. | |
bool | IsValid () const |
Returns true if function is valid. | |
size_t | GetNbMaximums (std::vector< FPOINT > *pv_MaxValues=0) const |
Returns nb of maximums that the function has. | |
Fuzzification | |
bool | Defuzzify (REALVAL &val, EN_DEFUZZMETHOD meth=DF_COG) const |
Defuzzyfication, return false if not possible (val unchanged in this case). For current default method, see slifis::EN_DEFUZZMETHOD. | |
FUZZYVAL | Fuzzify (REALVAL v) const |
Returns the fuzzy value corresponding to a real value. | |
Transforming function (unary operators) | |
void | AlphaCut (FUZZYVAL f) |
AlphaCuts the function (see Unary operations) | |
void | Truncate (FUZZYVAL f) |
Truncate the function to alpha (see Unary operations) | |
void | Scale (FUZZYVAL f) |
Scales the function with alpha (see Unary operations) | |
void | Complement () |
Complements the function : mf(after) = 1-mf(before) | |
Editing points | |
void | SetLeftValue (FUZZYVAL v) |
Changes the Left value of the function. | |
void | SetRightValue (FUZZYVAL v) |
Changes the Right value of the function (and the last point y ) | |
void | DeletePoint (size_t idx) |
Remove point of index idx in the function. | |
void | Shift (double val) |
Shifts all the points horizontally, by value val (if not empty) | |
void | AddPoint (const FPOINT &pt) |
Adds a point to the function, sets the _MaxValue , and sorts the points. | |
void | AddPoint (REALVAL, FUZZYVAL) |
Adds a point to the function, sets the _MaxValue , and sorts the points. | |
void | ModifyPoint (size_t idx, REALVAL x, FUZZYVAL y) |
Replace point idx with given values. | |
void | ModifyPoint (size_t idx, FPOINT pt) |
Replace point idx with values of point pt ) | |
void | ModifyPoint (size_t idx, FUZZYVAL y) |
Replace fuzzyvalue of point idx with y . | |
Name related | |
Set name of function. | |
void | SetName (std::string n) |
const std::string & | GetName () const |
Returns name of function. | |
Misc. \xrefitem todo2 "Medium Priority Todo" "Todo medium priority list" These two functions don't seem to be used anywhere, maybe remove them ? | |
bool | GetRange (REALVAL &v1, REALVAL &v2) const |
Get the range (2 real values) of the function. | |
void | GetPointsAtY (FUZZYVAL v, std::vector< FPOINT > &v_pt) const |
Returns in v_pt a vector of points lying on the function at y = v . | |
I/O functions | |
void | Print (FILE *f=stderr, const char *msg=NULL) const |
Prints function points in human-readable form, into file stream f . Can print user random message in msg (default is none). | |
Private Member Functions | |
void | Cleanup () |
Cleanup of function used in post processing of OR, AND, and PROD operations. | |
REALVAL | P_Defuzz_COG () const |
Center Of Gravity defuzzyfication method (private) | |
REALVAL | P_Defuzz_COA () const |
Center Of Area (COA) defuzzyfication method (private) | |
REALVAL | P_Defuzz_MAX () const |
Maximum defuzzyfication method (private) | |
REALVAL | P_Defuzz_MEMAX (bool DoWeightedAvg=false) const |
Mean of max values defuzzyfication method (private) | |
void | P_RemoveDuplicates () |
Remove duplicate points in function, assumes points are sorted. | |
void | P_MaxMinSearch () |
Max and min value search (private) | |
size_t | P_GetIntervalPointsVector (const FPOINT &p1, const FPOINT &p2, size_t &id1, size_t &id2) const |
Returns the number of FPOINT's that lie in the absiss interval of p1.x and p2.x (Private) | |
bool | P_CheckForEmptyness () |
Check if function has only one point or two points of equal value, and make function empty if true Returns true if function made empty, false if not, whatever the reason. | |
void | P_RemoveUselessPoints () |
This function removes points where function slope before and after the point is the same. | |
void | P_SetGaussian (double x0, double sigma) |
Pseudo-Gaussian function, approximated with lines. | |
bool | P_PointIsTooClose (const FPOINT &pt) |
Returns true is pt is equal (or close) to another point of the function (to avoid vertical segments in the function) | |
void | P_AddPoint (const FPOINT &pt) |
Adds a point to the function, sets the _MaxValue , and sorts the points (NO EQUAL VALUE CHECKING!) | |
bool | P_Write_bin (std::ofstream &f) const |
Writes the membership function into the (opened) binary stream f . | |
bool | P_Read_bin (std::ifstream &f) |
Reads the membership function from the (opened) binary stream f . | |
bool | P_Write_XML (TiXmlElement *parent) const |
bool | P_Read_XML (TiXmlElement *pElem) |
Private Attributes | |
FUZZYVAL | _MaxValue |
maximum fuzzy value of the function, computed by P_MaxMinSearch() | |
FUZZYVAL | _MinValue |
minimum fuzzy value of the function, computed by P_MaxMinSearch() | |
std::vector< FPOINT > | v_pts |
vector of points defining this function. Function must have 2 points to be valid | |
std::string | _mf_Name |
(optional) name of this membership function (for example, "cold") | |
Friends | |
class | FUZZY_ROOT |
void | FuzzyMax (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out) |
Performs fuzzy MAX between two functions. | |
void | FuzzyMin (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out) |
Performs fuzzy MIN between two functions. | |
void | FuzzyProduct (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out) |
Performs fuzzy product between two functions. | |
void | FuzzyBSum (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out) |
Performs bounded sum between two functions ( ) | |
void | FuzzyPSum (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out) |
Performs Probabilistic sum between two functions ( ) | |
void | FuzzyLukas (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out) |
Performs Łukasiewicz t-norm between two functions ( ) | |
void | P_FindIntersectionPoints (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out) |
Finds all intersection points between f1 and f2 , and adds them to out . | |
size_t | P_FIP_OneSide (const MEMBFUNC *f1, const MEMBFUNC *f2, MEMBFUNC *out) |
Finds all intersection points between f1 and f2 , and adds them to out . | |
void | P_ProcessPoints (const MEMBFUNC &fa, const MEMBFUNC &fb, MEMBFUNC &out, EN_MERGE_OP op) |
Considers all points of fa and fb , and adds them to out . Local function, not exported. | |
void | P_Process_OneSide (const MEMBFUNC &fa, const MEMBFUNC &fb, MEMBFUNC &out, EN_MERGE_OP op) |
Consider all points of fa , and compare to y value of fb . Add point to out if operation op tells to do so. | |
void | P_AddPointIfInInterval (MEMBFUNC *out, REALVAL x, FUZZYVAL y, REALVAL x1, REALVAL x2) |
Local function, not exported. |
A membership function, defined as a vector of points.
Creating : several constructors are provided (see below); some use the EN_MF_TYPE enum to create quickly standard "0 - 1" functions.
Constraint used here : the set of point is always sorted in ascending x-values order.
See also Users guide, on page Membership Functions.
slifis::MEMBFUNC::MEMBFUNC | ( | std::string | name = "-unnamedMF-" | ) |
slifis::MEMBFUNC::MEMBFUNC | ( | FUZZYVAL | val, |
std::string | name = "-unnamedMF-" |
||
) |
slifis::MEMBFUNC::MEMBFUNC | ( | EN_MF_TYPE | t, |
std::string | name, | ||
const std::vector< REALVAL > & | v | ||
) |
slifis::MEMBFUNC::MEMBFUNC | ( | EN_MF_TYPE | t, |
std::string | name, | ||
REALVAL | v1, | ||
REALVAL | v2 | ||
) |
slifis::MEMBFUNC::MEMBFUNC | ( | EN_MF_TYPE | t, |
std::string | name, | ||
REALVAL | v1, | ||
REALVAL | v2, | ||
REALVAL | v3 | ||
) |
slifis::MEMBFUNC::MEMBFUNC | ( | EN_MF_TYPE | t, |
std::string | name, | ||
REALVAL | v1, | ||
REALVAL | v2, | ||
REALVAL | v3, | ||
REALVAL | v4 | ||
) |
void slifis::MEMBFUNC::Clear | ( | FUZZYVAL | v = 0.0 | ) |
Resets function, except name, that remains unchanged.
_MinValue and _MaxValue are initialised to v, default value is 0.0
References _MaxValue, _MinValue, and v_pts.
Referenced by slifis::FuzzyBSum(), slifis::FuzzyLukas(), slifis::FuzzyMax(), slifis::FuzzyMin(), slifis::FuzzyProduct(), slifis::FuzzyPSum(), main(), MEMBFUNC(), P_CheckForEmptyness(), slifis::P_FindIntersectionPoints(), Scale(), Set(), and Truncate().
void slifis::MEMBFUNC::SetFrom | ( | const MEMBFUNC & | src | ) |
void slifis::MEMBFUNC::Set | ( | EN_MF_TYPE | t, |
const std::string & | name, | ||
const std::vector< REALVAL > & | v | ||
) |
void slifis::MEMBFUNC::Set | ( | EN_MF_TYPE | t, |
const std::string & | name, | ||
REALVAL | v1, | ||
REALVAL | v2 | ||
) |
void slifis::MEMBFUNC::Set | ( | EN_MF_TYPE | t, |
const std::string & | name, | ||
REALVAL | v1, | ||
REALVAL | v2, | ||
REALVAL | v3 | ||
) |
void slifis::MEMBFUNC::Set | ( | EN_MF_TYPE | t, |
const std::string & | name, | ||
REALVAL | v1, | ||
REALVAL | v2, | ||
REALVAL | v3, | ||
REALVAL | v4 | ||
) |
void slifis::MEMBFUNC::Set | ( | EN_MF_TYPE | t, |
const std::vector< REALVAL > & | v | ||
) |
Clears function and sets it according to type t
and given values.
References slifis::MF_GAUSS, slifis::MF_HL, slifis::MF_LH, slifis::MF_LL, slifis::MF_TRI, Set(), SLIFIS_WARNING_1, and SWITCH_ERROR.
void slifis::MEMBFUNC::Set | ( | EN_MF_TYPE | t, |
REALVAL | v1, | ||
REALVAL | v2 | ||
) |
Clears function and sets it according to type t
and given 2 values.
References __IN__, __OUT__, _MaxValue, Clear(), slifis::ERR_BAD_VALUES, slifis::ERR_MF_BAD_TYPE, slifis::MF_GAUSS, slifis::MF_HL, slifis::MF_LH, slifis::MF_TRI, P_SetGaussian(), SLIFIS_ERROR_1, SLIFIS_ERROR_2, and v_pts.
void slifis::MEMBFUNC::Set | ( | EN_MF_TYPE | t, |
REALVAL | v1, | ||
REALVAL | v2, | ||
REALVAL | v3 | ||
) |
Clears function and sets it according to t
(MF_TRI or MF_LL)
v1
, v2
, v3
v2:
half width at y=1v3:
half width at y=0 References __IN__, __OUT__, _MaxValue, Clear(), slifis::ERR_BAD_VALUES, slifis::ERR_MF_BAD_TYPE, slifis::MF_LL, slifis::MF_TRI, SLIFIS_ERROR, SLIFIS_ERROR_1, SLIFIS_ERROR_2, SLIFIS_ERROR_LOG, and v_pts.
void slifis::MEMBFUNC::Set | ( | EN_MF_TYPE | t, |
REALVAL | v1, | ||
REALVAL | v2, | ||
REALVAL | v3, | ||
REALVAL | v4 | ||
) |
Clears function and sets it according to type t
and given 4 values.
References __IN__, __OUT__, _MaxValue, Clear(), slifis::ERR_BAD_VALUES, slifis::ERR_MF_BAD_TYPE, slifis::MF_LL, SLIFIS_ERROR, SLIFIS_ERROR_LOG, and v_pts.
bool slifis::MEMBFUNC::operator== | ( | const MEMBFUNC & | m | ) | const |
bool slifis::MEMBFUNC::operator!= | ( | const MEMBFUNC & | m | ) | const [inline] |
FPOINT & slifis::MEMBFUNC::GetPoint | ( | size_t | idx | ) |
Returns a point from a function, identified by its index.
References __IN__, __OUT__, slifis::ERR_MF_BAD_INDEX, GetNbPoints(), SLIFIS_ERROR_2, and v_pts.
Referenced by AlphaCut(), Fuzzify(), slifis::FuzzyBSum(), slifis::FuzzyLukas(), slifis::FuzzyProduct(), slifis::FuzzyPSum(), GetNbMaximums(), GetPointsAtY(), slifis::FUZZY_ROOT::IsNormalised(), IsValid(), main(), P_Defuzz_COA(), P_Defuzz_COG(), P_Defuzz_MAX(), slifis_plot::PLOT_FUZZY::P_DrawMembFunc(), slifis_plot::PLOT_MF::P_DrawPlot(), slifis::P_FIP_OneSide(), P_PointIsTooClose(), slifis::P_Process_OneSide(), slifis::SLIFIS::P_Write_FCL(), P_Write_XML(), and Scale().
const FPOINT & slifis::MEMBFUNC::GetPoint | ( | size_t | idx | ) | const |
Returns a point from a function, identified by its index.
References __IN__, __OUT__, slifis::ERR_MF_BAD_INDEX, GetNbPoints(), SLIFIS_ERROR_2, and v_pts.
size_t slifis::MEMBFUNC::GetNbPoints | ( | ) | const [inline] |
References v_pts.
Referenced by AddPoint(), AlphaCut(), Complement(), DeletePoint(), Fuzzify(), slifis::FuzzyBSum(), slifis::FuzzyLukas(), slifis::FuzzyProduct(), slifis::FuzzyPSum(), GetFirstPoint(), GetLastPoint(), GetLeftValue(), GetNbMaximums(), GetPoint(), GetPointsAtY(), GetRightValue(), slifis::FUZZY_ROOT::IsNormalised(), IsValid(), main(), ModifyPoint(), P_AddPoint(), P_CheckForEmptyness(), slifis_plot::PLOT_MF::P_CheckSelection(), slifis_plot::PLOT_MF::P_ComputeScale(), P_Defuzz_COA(), P_Defuzz_COG(), P_Defuzz_MAX(), slifis_plot::PLOT_FUZZY::P_DrawMembFunc(), slifis_plot::PLOT_MF::P_DrawPlot(), slifis::P_FIP_OneSide(), P_GetIntervalPointsVector(), P_MaxMinSearch(), P_PointIsTooClose(), slifis::P_Process_OneSide(), P_RemoveUselessPoints(), P_Write_bin(), slifis::SLIFIS::P_Write_FCL(), P_Write_XML(), Print(), Scale(), slifis_plot::PLOT_MF::SelectPoint(), SetLeftValue(), SetRightValue(), and Shift().
FUZZYVAL slifis::MEMBFUNC::GetLeftValue | ( | ) | const |
Return "Left" value of function (= first point x-value, if function is not empty, or maximum value if it is)
References _MaxValue, _MinValue, GetFirstPoint(), GetNbPoints(), and slifis::FPOINT::GetY().
Referenced by Fuzzify(), IsFinite(), and slifis::P_FIP_OneSide().
FUZZYVAL slifis::MEMBFUNC::GetRightValue | ( | ) | const |
Return "Right" value of function (= last point y-value, if function is not empty, or maximum value if it is)
References _MaxValue, _MinValue, GetLastPoint(), GetNbPoints(), and slifis::FPOINT::GetY().
Referenced by Fuzzify(), IsFinite(), slifis_plot::PLOT_FUZZY::P_DrawMembFunc(), and slifis::P_FIP_OneSide().
FPOINT slifis::MEMBFUNC::GetFirstPoint | ( | ) | const |
Returns first point of function.
References __IN__, __OUT__, slifis::ERR_MF_NO_POINT, GetNbPoints(), SLIFIS_ERROR, and v_pts.
Referenced by DrawDefuzz(), Fuzzify(), GetLeftValue(), GetNbMaximums(), GetRange(), slifis::DATA_SET::GetSubset(), slifis_plot::PLOT_FS::P_ComputeScale(), slifis_plot::PLOT_MF::P_ComputeScale(), P_Defuzz_MAX(), slifis_plot::PLOT_FUZZY::P_DrawMembFunc(), slifis::P_FindLowestFunction(), slifis::P_FIP_OneSide(), and P_GetIntervalPointsVector().
FPOINT slifis::MEMBFUNC::GetLastPoint | ( | ) | const |
Returns last point of function.
References __IN__, __OUT__, slifis::ERR_MF_NO_POINT, GetNbPoints(), SLIFIS_ERROR, and v_pts.
Referenced by DrawDefuzz(), Fuzzify(), GetRange(), GetRightValue(), slifis::DATA_SET::GetSubset(), slifis_plot::PLOT_FS::P_ComputeScale(), slifis_plot::PLOT_MF::P_ComputeScale(), and P_GetIntervalPointsVector().
FUZZYVAL slifis::MEMBFUNC::GetMaxValue | ( | ) | const [inline] |
References _MaxValue.
Referenced by slifis::FuzzyMax(), IsNull(), and slifis_plot::PLOT_FUZZY::P_DrawMembFunc().
FUZZYVAL slifis::MEMBFUNC::GetMinValue | ( | ) | const [inline] |
References _MinValue.
Referenced by slifis::FuzzyBSum(), slifis::FuzzyLukas(), slifis::FuzzyMin(), slifis::FuzzyProduct(), and slifis::FuzzyPSum().
bool slifis::MEMBFUNC::IsEmpty | ( | ) | const [inline] |
Returns true if function has no points (but can have a constant value !)
References v_pts.
Referenced by Defuzzify(), slifis::FuzzyBSum(), slifis::FuzzyLukas(), slifis::FuzzyMax(), slifis::FuzzyMin(), slifis::FuzzyProduct(), slifis::FuzzyPSum(), GetNbMaximums(), GetPointsAtY(), GetRange(), IsNull(), IsValid(), slifis_plot::PLOT_FS::P_ComputeScale(), slifis_plot::PLOT_FUZZY::P_DrawMembFunc(), slifis_plot::PLOT_MF::P_DrawPlot(), slifis::P_FindLowestFunction(), and Shift().
bool slifis::MEMBFUNC::IsNull | ( | ) | const [inline] |
Returns true if function is null (no points AND 0 value )
References GetMaxValue(), and IsEmpty().
Referenced by slifis::SLIFIS::P_Evaluate_M().
bool slifis::MEMBFUNC::IsFinite | ( | ) | const [inline] |
Returns true if function value is 0 on left and right sides.
References GetLeftValue(), and GetRightValue().
Referenced by Defuzzify(), slifis::DATA_SET::GetSubset(), and slifis::FUZZY_OUT::SetIsValid().
bool slifis::MEMBFUNC::IsValid | ( | ) | const |
Returns true if function is valid.
This function is useful for debug, but not only
A valid function respects the following conditions :
References _MaxValue, _MinValue, GetNbPoints(), GetPoint(), slifis::FPOINT::GetX(), IsEmpty(), Print(), SLIFIS_EPSILON_FUZZY, and SLIFIS_EPSILON_REAL.
Referenced by slifis::FUZZY_ROOT::AddMf(), Cleanup(), Defuzzify(), GetPointsAtY(), slifis_plot::PLOT_FS::P_ComputeScale(), slifis_plot::PLOT_MF::P_ComputeScale(), slifis_plot::PLOT_FUZZY::P_DrawMembFunc(), slifis_plot::PLOT_MF::P_DrawPlot(), slifis::FUZZY_ROOT::P_SetIsValid(), Scale(), SetLeftValue(), SetRightValue(), and Truncate().
size_t slifis::MEMBFUNC::GetNbMaximums | ( | std::vector< FPOINT > * | pv_MaxValues = 0 | ) | const |
Returns nb of maximums that the function has.
Additionally, if a pointer on a vector is given, this vector will hold the maximums values upon return.
In case of a function with a flat segment, this function will return 2 values for the segment, one at the beginning, and one at the end.
Algorithm:
For all the points:
In the following, the slopes are coded as follows:
References GetFirstPoint(), GetNbPoints(), GetPoint(), slifis::FPOINT::GetY(), and IsEmpty().
Referenced by P_Defuzz_MEMAX().
bool slifis::MEMBFUNC::Defuzzify | ( | REALVAL & | val, |
EN_DEFUZZMETHOD | meth = DF_COG |
||
) | const |
Defuzzyfication, return false if not possible (val
unchanged in this case). For current default method, see slifis::EN_DEFUZZMETHOD.
References __IN__, __OUT__, slifis::DF_COA, slifis::DF_COG, slifis::DF_MAX, slifis::DF_MEMAX, slifis::DF_WMEMAX, GetName(), IsEmpty(), IsFinite(), IsValid(), P_Defuzz_COA(), P_Defuzz_COG(), P_Defuzz_MAX(), P_Defuzz_MEMAX(), SLIFIS_WARNING_1, and SWITCH_ERROR.
Referenced by DrawDefuzz(), and Process().
FUZZYVAL slifis::MEMBFUNC::Fuzzify | ( | REALVAL | x | ) | const |
Returns the fuzzy value corresponding to a real value.
Say we have a typical L-H-L function, given 'x', it will return 'y' :
| 1 |- - - - -------- | / \ | / \ y |---- / \ | /| \ | / | \ 0 |---------------------------- x
Please note that in order to avoid numerical issues, we search separately if the input value is equal to one of the points, and if it is in an interval of two points.
Handles vertical segments in membership functions (defined as 2 points of same value)
References __IN__, __OUT__, _MaxValue, slifis::ERR_MF_INVALID_VALUE, FLOAT_ARE_EQUAL, GetFirstPoint(), GetLastPoint(), GetLeftValue(), GetNbPoints(), GetPoint(), GetRightValue(), slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), Print(), SLIFIS_DEBUG_LOG, SLIFIS_ERROR_1, and v_pts.
Referenced by DrawDefuzz(), slifis_plot::PLOT_FS::DrawValue(), slifis_plot::PLOT_MF::DrawValue(), slifis::FUZZY_ROOT::FindBestMf(), slifis::FuzzyBSum(), slifis::FuzzyLukas(), slifis::FuzzyProduct(), slifis::FuzzyPSum(), slifis::FUZZY_IN::GetFuzzyValue(), slifis::FUZZY_IN::GetInputFiringStrength(), slifis::RULE_IDX::GetRuleFiringStrength(), slifis::DATA_SET::GetSubset(), slifis::FUZZY_ROOT::IsNormalised(), main(), slifis::RULE_BASE::P_FindBestMf(), slifis::P_FIP_OneSide(), and slifis::P_Process_OneSide().
void slifis::MEMBFUNC::AlphaCut | ( | FUZZYVAL | alpha | ) |
AlphaCuts the function (see Unary operations)
Algorithm:
alpha
alpha
References AddPoint(), Cleanup(), GetName(), GetNbPoints(), GetPoint(), slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), P_FindIntersectionPoints, SetName(), and SLIFIS_EPSILON_REAL.
Referenced by DrawDefuzz(), and main().
void slifis::MEMBFUNC::Truncate | ( | FUZZYVAL | alpha | ) |
Truncate the function to alpha
(see Unary operations)
alpha
References __IN__, __OUT__, Cleanup(), Clear(), slifis::ERR_MF_NOT_VALID, FuzzyMin, GetName(), slifis::FUZZYVAL::IsOne(), IsValid(), slifis::FUZZYVAL::IsZero(), and SLIFIS_ERROR.
Referenced by main(), and slifis::SLIFIS::P_Evaluate_M().
void slifis::MEMBFUNC::Scale | ( | FUZZYVAL | f | ) |
Scales the function with alpha
(see Unary operations)
References __IN__, __OUT__, Cleanup(), Clear(), slifis::ERR_MF_NOT_VALID, GetNbPoints(), GetPoint(), slifis::FPOINT::GetY(), slifis::FUZZYVAL::IsOne(), IsValid(), slifis::FUZZYVAL::IsZero(), slifis::FPOINT::SetY(), and SLIFIS_ERROR.
Referenced by main(), and slifis::SLIFIS::P_Evaluate_M().
void slifis::MEMBFUNC::Complement | ( | ) |
Complements the function : mf(after) = 1-mf(before)
References __IN__, __OUT__, GetNbPoints(), slifis::FPOINT::GetY(), P_MaxMinSearch(), slifis::FPOINT::SetY(), and v_pts.
Referenced by main().
void slifis::MEMBFUNC::SetLeftValue | ( | FUZZYVAL | v | ) |
Changes the Left value of the function.
Beware : if function has no points ( =IsEmpty() ), it will change min and max values
References __IN__, __OUT__, _MaxValue, _MinValue, GetNbPoints(), IsValid(), P_MaxMinSearch(), and v_pts.
Referenced by main().
void slifis::MEMBFUNC::SetRightValue | ( | FUZZYVAL | v | ) |
Changes the Right value of the function (and the last point y )
Beware : if function has no points ( => IsEmpty() == true ), it will also change the left value !!!
References __IN__, __OUT__, _MaxValue, _MinValue, GetNbPoints(), IsValid(), P_MaxMinSearch(), and v_pts.
Referenced by main().
void slifis::MEMBFUNC::DeletePoint | ( | size_t | idx | ) |
Remove point of index idx
in the function.
Please note that the 'assert()' on validity of function has been commented out on 20120823 (rev. 216) because this function is used to delete points when merging membership functions, and during that process, the function can be temporarly in a non-valid state.
References __IN__, __OUT__, slifis::ERR_MF_BAD_INDEX, slifis::ERR_MF_NOREMOVE, GetNbPoints(), P_MaxMinSearch(), SLIFIS_ERROR, SLIFIS_ERROR_2, and v_pts.
Referenced by main(), and P_RemoveUselessPoints().
void slifis::MEMBFUNC::Shift | ( | double | val | ) |
Shifts all the points horizontally, by value val
(if not empty)
References __IN__, __OUT__, slifis::FPOINT::AddX(), GetNbPoints(), IsEmpty(), and v_pts.
Referenced by main().
void slifis::MEMBFUNC::AddPoint | ( | const FPOINT & | pt | ) |
Adds a point to the function, sets the _MaxValue
, and sorts the points.
References __IN__, __OUT__, slifis::ERR_MF_CANT_ADD_POINT, GetNbPoints(), slifis::FPOINT::GetX(), P_AddPoint(), P_PointIsTooClose(), and SLIFIS_ERROR_1.
Referenced by AddPoint(), AlphaCut(), main(), P_Read_XML(), and P_SetGaussian().
void slifis::MEMBFUNC::AddPoint | ( | REALVAL | x, |
FUZZYVAL | y | ||
) |
Adds a point to the function, sets the _MaxValue
, and sorts the points.
References __IN__, __OUT__, and AddPoint().
void slifis::MEMBFUNC::ModifyPoint | ( | size_t | idx, |
REALVAL | x, | ||
FUZZYVAL | y | ||
) |
Replace point idx
with given values.
References __IN__, __OUT__, slifis::ERR_MF_BAD_INDEX, GetNbPoints(), P_MaxMinSearch(), SLIFIS_ERROR_2, and v_pts.
Referenced by slifis::FuzzyBSum(), slifis::FuzzyLukas(), slifis::FuzzyProduct(), slifis::FuzzyPSum(), main(), and ModifyPoint().
void slifis::MEMBFUNC::ModifyPoint | ( | size_t | idx, |
FPOINT | pt | ||
) |
Replace point idx
with values of point pt )
References slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), and ModifyPoint().
void slifis::MEMBFUNC::ModifyPoint | ( | size_t | idx, |
FUZZYVAL | y | ||
) |
Replace fuzzyvalue of point idx
with y
.
References __IN__, __OUT__, slifis::ERR_MF_BAD_INDEX, GetNbPoints(), P_MaxMinSearch(), SLIFIS_ERROR_2, and v_pts.
void slifis::MEMBFUNC::SetName | ( | std::string | n | ) | [inline] |
References _mf_Name.
Referenced by AlphaCut(), main(), MEMBFUNC(), slifis::SLIFIS::P_Evaluate_M(), P_Read_XML(), and slifis::FUZZY_ROOT::SetMfName().
const std::string& slifis::MEMBFUNC::GetName | ( | ) | const [inline] |
Returns name of function.
References _mf_Name.
Referenced by slifis::FUZZY_ROOT::AddMf(), AlphaCut(), Defuzzify(), slifis_plot::PLOT_RB_2D::Draw(), slifis_plot::PLOT_RB_TEXT::Draw(), slifis::FUZZY_ROOT::GenerateHistogramDataFile(), slifis_plot::PLOT_MF::GetPlotName(), main(), slifis_plot::PLOT_MF::P_ComputeScale(), slifis_plot::PLOT_RB_2D::P_DrawIndexes(), slifis_plot::PLOT_FUZZY::P_DrawMembFunc(), slifis_plot::PLOT_FS::P_DrawPlot(), slifis_plot::PLOT_MF::P_DrawPlot(), slifis::SLIFIS::P_Write_FCL(), P_Write_XML(), slifis::RULE_BASE::Print2(), and Truncate().
bool slifis::MEMBFUNC::GetRange | ( | REALVAL & | vL, |
REALVAL & | vH | ||
) | const |
Get the range (2 real values) of the function.
The range is defined as the first point and the last point of the function
Returns false if no range (constant function), with vL and vH unchanged
References __IN__, __OUT__, GetFirstPoint(), GetLastPoint(), slifis::FPOINT::GetX(), and IsEmpty().
void slifis::MEMBFUNC::GetPointsAtY | ( | FUZZYVAL | v, |
std::vector< FPOINT > & | v_pt | ||
) | const |
Returns in v_pt
a vector of points lying on the function at y = v
.
In case there is an infinity of points (for example, if there is a flat segment lying at value v
), then we return only the first and the last point of the segment.
References __IN__, __OUT__, GetNbPoints(), GetPoint(), slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), IsEmpty(), and IsValid().
void slifis::MEMBFUNC::Print | ( | FILE * | f = stderr , |
const char * | msg = NULL |
||
) | const |
Prints function points in human-readable form, into file stream f
. Can print user random message in msg
(default is none).
References _MaxValue, _mf_Name, _MinValue, GetNbPoints(), and v_pts.
Referenced by Cleanup(), Fuzzify(), IsValid(), slifis::SLIFIS::P_Evaluate_M(), slifis::P_FIP_OneSide(), and slifis::PrintDifferences().
void slifis::MEMBFUNC::Cleanup | ( | ) | [private] |
Cleanup of function used in post processing of OR, AND, and PROD operations.
References __IN__, __OUT__, IsValid(), P_CheckForEmptyness(), P_MaxMinSearch(), P_RemoveDuplicates(), P_RemoveUselessPoints(), and Print().
Referenced by AlphaCut(), slifis::FuzzyBSum(), slifis::FuzzyLukas(), slifis::FuzzyMax(), slifis::FuzzyMin(), slifis::FuzzyProduct(), slifis::FuzzyPSum(), Scale(), and Truncate().
REALVAL slifis::MEMBFUNC::P_Defuzz_COG | ( | ) | const [private] |
Center Of Gravity defuzzyfication method (private)
References __IN__, __OUT__, GetNbPoints(), GetPoint(), slifis::FPOINT::GetX(), and slifis::FPOINT::GetY().
Referenced by Defuzzify().
REALVAL slifis::MEMBFUNC::P_Defuzz_COA | ( | ) | const [private] |
Center Of Area (COA) defuzzyfication method (private)
For each pair of points, we compute separately area and center of gravity of triangle (cT) and rectangle (cR). The center of gravity of both is located on the line joining cT and cR.
| /|y2 | / | | / | | / | | / | | / T | | y1/______| | | | | | | | | R | | | | ---------------------------- x1 x2
References __IN__, __OUT__, GetNbPoints(), GetPoint(), slifis::FPOINT::GetX(), and slifis::FPOINT::GetY().
Referenced by Defuzzify().
REALVAL slifis::MEMBFUNC::P_Defuzz_MAX | ( | ) | const [private] |
Maximum defuzzyfication method (private)
If function has several plateau of same (maximum) value, then only the first one will be considered
See code below for more details about what happens with more complex situations, IMHO, it is not very realistic, but who knows...
References __IN__, __OUT__, GetFirstPoint(), GetNbPoints(), GetPoint(), slifis::FPOINT::GetX(), and slifis::FPOINT::GetY().
Referenced by Defuzzify().
REALVAL slifis::MEMBFUNC::P_Defuzz_MEMAX | ( | bool | DoWeightedAvg = false | ) | const [private] |
Mean of max values defuzzyfication method (private)
Please note that any flat area of a function will be considered as a max value
References GetNbMaximums(), slifis::FPOINT::GetX(), and slifis::FPOINT::GetY().
Referenced by Defuzzify().
void slifis::MEMBFUNC::P_RemoveDuplicates | ( | ) | [private] |
Remove duplicate points in function, assumes points are sorted.
Relies on FPOINT::operator ==
References __IN__, __OUT__, and v_pts.
Referenced by Cleanup(), slifis::P_FindIntersectionPoints(), and slifis::P_ProcessPoints().
void slifis::MEMBFUNC::P_MaxMinSearch | ( | ) | [private] |
Max and min value search (private)
References __IN__, __OUT__, _MaxValue, _MinValue, GetNbPoints(), and v_pts.
Referenced by Cleanup(), Complement(), DeletePoint(), ModifyPoint(), P_Read_bin(), SetLeftValue(), and SetRightValue().
size_t slifis::MEMBFUNC::P_GetIntervalPointsVector | ( | const FPOINT & | p1, |
const FPOINT & | p2, | ||
size_t & | id1, | ||
size_t & | id2 | ||
) | const [private] |
Returns the number of FPOINT's that lie in the absiss interval of p1.x
and p2.x
(Private)
id1
id2
Be careful, don't use these two values if return value is 0 !
References __IN__, __OUT__, GetFirstPoint(), GetLastPoint(), GetNbPoints(), slifis::FPOINT::GetX(), and v_pts.
Referenced by slifis::P_FIP_OneSide().
bool slifis::MEMBFUNC::P_CheckForEmptyness | ( | ) | [private] |
Check if function has only one point or two points of equal value, and make function empty if true Returns true if function made empty, false if not, whatever the reason.
References __IN__, __OUT__, Clear(), GetNbPoints(), SLIFIS_EPSILON_FUZZY, and v_pts.
Referenced by Cleanup().
void slifis::MEMBFUNC::P_RemoveUselessPoints | ( | ) | [private] |
This function removes points where function slope before and after the point is the same.
References __IN__, __OUT__, DeletePoint(), GetNbPoints(), slifis::FPOINT::GetX(), slifis::FPOINT::GetY(), slifis::FPOINT::Set(), SLIFIS_DEBUG_LOG, and v_pts.
Referenced by Cleanup().
void slifis::MEMBFUNC::P_SetGaussian | ( | double | x0, |
double | sigma | ||
) | [private] |
Pseudo-Gaussian function, approximated with lines.
See Gaussian function approximation
References AddPoint(), and GAUSS_FUNC.
Referenced by Set().
bool slifis::MEMBFUNC::P_PointIsTooClose | ( | const FPOINT & | pt | ) | [private] |
Returns true is pt
is equal (or close) to another point of the function (to avoid vertical segments in the function)
References FLOAT_ARE_EQUAL, GetNbPoints(), GetPoint(), slifis::FPOINT::GetX(), SLIFIS_DEBUG_LOG, and SLIFIS_ERROR_LOG.
Referenced by AddPoint().
void slifis::MEMBFUNC::P_AddPoint | ( | const FPOINT & | pt | ) | [private] |
Adds a point to the function, sets the _MaxValue
, and sorts the points (NO EQUAL VALUE CHECKING!)
References __IN__, __OUT__, _MaxValue, _MinValue, GetNbPoints(), slifis::FPOINT::GetY(), and v_pts.
Referenced by AddPoint(), slifis::P_AddPointIfInInterval(), slifis::P_FIP_OneSide(), and slifis::P_Process_OneSide().
bool slifis::MEMBFUNC::P_Write_bin | ( | std::ofstream & | f | ) | const [private] |
Writes the membership function into the (opened) binary stream f
.
References __IN__, __OUT__, _mf_Name, GetNbPoints(), STREAM_OK_TEST, STREAM_WRITE_STRING, STREAMCHECK_INIT, and v_pts.
bool slifis::MEMBFUNC::P_Read_bin | ( | std::ifstream & | f | ) | [private] |
Reads the membership function from the (opened) binary stream f
.
References __IN__, __OUT__, _mf_Name, P_MaxMinSearch(), slifis::FPOINT::P_Read_bin(), STREAM_OK_TEST, STREAM_READ_STRING, STREAMCHECK_INIT, and v_pts.
Referenced by slifis::FUZZY_ROOT::P_Read_bin().
bool slifis::MEMBFUNC::P_Write_XML | ( | TiXmlElement * | parent | ) | const [private] |
References GetName(), GetNbPoints(), and GetPoint().
Referenced by slifis::FUZZY_ROOT::P_Write_XML().
bool slifis::MEMBFUNC::P_Read_XML | ( | TiXmlElement * | pElem | ) | [private] |
References AddPoint(), slifis::FPOINT::P_Read_XML(), SetName(), SLIFIS_ERROR_LOG, SLIFIS_XML_READ_INT_ATTRIB, and SLIFIS_XML_READ_STRING_ATTRIB.
Referenced by slifis::FUZZY_ROOT::P_Read_XML().
friend class FUZZY_ROOT [friend] |
Performs fuzzy MAX between two functions.
in1
and in2
cannot be used as out
Performs fuzzy MIN between two functions.
in1
and in2
cannot be used as out
Referenced by Truncate().
void FuzzyProduct | ( | const MEMBFUNC & | f1, |
const MEMBFUNC & | f2, | ||
MEMBFUNC & | out | ||
) | [friend] |
Performs fuzzy product between two functions.
out = in1 * in2
in1
and in2
cannot be used as out
Performs bounded sum between two functions ( )
Performs Probabilistic sum between two functions ( )
void FuzzyLukas | ( | const MEMBFUNC & | f1, |
const MEMBFUNC & | f2, | ||
MEMBFUNC & | out | ||
) | [friend] |
Performs Łukasiewicz t-norm between two functions ( )
void P_FindIntersectionPoints | ( | const MEMBFUNC & | f1, |
const MEMBFUNC & | f2, | ||
MEMBFUNC & | out | ||
) | [friend] |
Finds all intersection points between f1
and f2
, and adds them to out
.
out
is cleared, its size is the number of intersections foundThe function needs to call twice the "real" code (P_FIP_OneSide() ), because this latter function parses only one of the two membership functions, searching for intersections, and there can be some intersections AFTER the last point of the first MF.
Referenced by AlphaCut().
size_t P_FIP_OneSide | ( | const MEMBFUNC * | f1, |
const MEMBFUNC * | f2, | ||
MEMBFUNC * | out | ||
) | [friend] |
Finds all intersection points between f1
and f2
, and adds them to out
.
Algorithm:
- For each segment s_i of function f1
- count how many points n of f2 lie in the x-interval of segment s_i, and fetch their index values id1 and id2
- IF n!=0
- Build segment s_j made of f2(id1) and f2(id1-1) (or horizontal line if id1=0)
- IF s_j intersects with s_i
- Add intersection point
- ENDIF
- FOR each point j of f2 from id1 to id2
- Build segment s_j made of f2(j) and f2(j+1) (or horizontal line if j is last point of f2)
- IF s_i intersects s_j
- Add intersection point
- ENDIF
- ENDFOR
- ELSE (n=0)
- compute the segment s_k of f2 in the x-range of s_i
- IF s_k and s_i intersect
- add intersection point
- ENDIF
- ENDIF
- ENDFOR
void P_ProcessPoints | ( | const MEMBFUNC & | fa, |
const MEMBFUNC & | fb, | ||
MEMBFUNC & | out, | ||
EN_MERGE_OP | op | ||
) | [friend] |
Considers all points of fa
and fb
, and adds them to out
. Local function, not exported.
fa
, and compare to y value of fb
fb
, and compare to y value of fa
void P_Process_OneSide | ( | const MEMBFUNC & | fa, |
const MEMBFUNC & | fb, | ||
MEMBFUNC & | out, | ||
EN_MERGE_OP | op | ||
) | [friend] |
Consider all points of fa
, and compare to y value of fb
. Add point to out
if operation op
tells to do so.
void P_AddPointIfInInterval | ( | MEMBFUNC * | out, |
REALVAL | x, | ||
FUZZYVAL | y, | ||
REALVAL | x1, | ||
REALVAL | x2 | ||
) | [friend] |
Local function, not exported.
out
if real value x
is stricly higher than x1
and strictly lower than x2
FUZZYVAL slifis::MEMBFUNC::_MaxValue [private] |
maximum fuzzy value of the function, computed by P_MaxMinSearch()
Referenced by Clear(), Fuzzify(), GetLeftValue(), GetMaxValue(), GetRightValue(), IsValid(), operator==(), P_AddPoint(), P_MaxMinSearch(), Print(), Set(), SetFrom(), SetLeftValue(), and SetRightValue().
FUZZYVAL slifis::MEMBFUNC::_MinValue [private] |
minimum fuzzy value of the function, computed by P_MaxMinSearch()
Referenced by Clear(), GetLeftValue(), GetMinValue(), GetRightValue(), IsValid(), operator==(), P_AddPoint(), P_MaxMinSearch(), Print(), SetFrom(), SetLeftValue(), and SetRightValue().
std::vector<FPOINT> slifis::MEMBFUNC::v_pts [private] |
vector of points defining this function. Function must have 2 points to be valid
Referenced by Clear(), Complement(), DeletePoint(), Fuzzify(), GetFirstPoint(), GetLastPoint(), GetNbPoints(), GetPoint(), IsEmpty(), ModifyPoint(), operator==(), P_AddPoint(), P_CheckForEmptyness(), P_GetIntervalPointsVector(), P_MaxMinSearch(), P_Read_bin(), P_RemoveDuplicates(), P_RemoveUselessPoints(), P_Write_bin(), Print(), Set(), SetFrom(), SetLeftValue(), SetRightValue(), and Shift().
std::string slifis::MEMBFUNC::_mf_Name [private] |
(optional) name of this membership function (for example, "cold")
Referenced by GetName(), P_Read_bin(), P_Write_bin(), Print(), Set(), and SetName().