A fuzzy logic C++ library
Private Member Functions | Private Attributes | Friends
slifis::MEMBFUNC Class Reference

A membership function, defined as a vector of points. More...

#include <membfunc.hpp>

+ Collaboration diagram for slifis::MEMBFUNC:

List of all members.

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
FPOINTGetPoint (size_t idx)
 Returns a point from a function, identified by its index.
const FPOINTGetPoint (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< FPOINTv_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 ( $ y = \min(1,a+b) $ )
void FuzzyPSum (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out)
 Performs Probabilistic sum between two functions ( $ y = a+b-a.b $ )
void FuzzyLukas (const MEMBFUNC &f1, const MEMBFUNC &f2, MEMBFUNC &out)
 Performs Łukasiewicz t-norm between two functions ( $ y = \max \{ 0, a+b-1 \} $ )
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.

Detailed Description

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.


Constructor & Destructor Documentation

slifis::MEMBFUNC::MEMBFUNC ( std::string  name = "-unnamedMF-")

Constructor 1 for empty function, only name given.

References __IN__, __OUT__, and Clear().

slifis::MEMBFUNC::MEMBFUNC ( FUZZYVAL  val,
std::string  name = "-unnamedMF-" 
)

Constructor 6, for empty function.

References __IN__, __OUT__, Clear(), and SetName().

slifis::MEMBFUNC::MEMBFUNC ( EN_MF_TYPE  t,
std::string  name,
const std::vector< REALVAL > &  v 
)

Constructor 2, for any standart type.

References __IN__, __OUT__, and Set().

slifis::MEMBFUNC::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.

References __IN__, __OUT__, and Set().

slifis::MEMBFUNC::MEMBFUNC ( EN_MF_TYPE  t,
std::string  name,
REALVAL  v1,
REALVAL  v2,
REALVAL  v3 
)

Constructor 4, for MF_TRI type (3 values)

References __IN__, __OUT__, and Set().

slifis::MEMBFUNC::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)

References __IN__, __OUT__, and Set().


Member Function Documentation

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)

Copies src into the current function, except for name, that remains unchanged.

This differs from the assignement operator (=), that also copies the name of the function

References _MaxValue, _MinValue, and v_pts.

void slifis::MEMBFUNC::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.

References __IN__, __OUT__, and _mf_Name.

Referenced by main(), MEMBFUNC(), and Set().

void slifis::MEMBFUNC::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.

References __IN__, __OUT__, _mf_Name, and Set().

void slifis::MEMBFUNC::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.

References __IN__, __OUT__, _mf_Name, and Set().

void slifis::MEMBFUNC::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.

References __IN__, __OUT__, _mf_Name, and Set().

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.

  • If t = MF_HL or MF_LH, then v1 and v2 are the two real values, and must be in increasing order ( v1 < v2 )
  • If t = MF_TRI, then v1 is the center value, and v2 is the half-width

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)

  • if type is MF_TRI, creates 3 points at values v1, v2, v3
  • if type is MF_LL, creates a symmetric trapezoidal function (4 points), with:
    • v2: half width at y=1
    • v3: 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

Equality operator, returns true if functions are the same, up to their name.

References _MaxValue, _MinValue, and v_pts.

bool slifis::MEMBFUNC::operator!= ( const MEMBFUNC m) const [inline]
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]

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().

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().

Returns first point of function.

  • Equivalent to GetPoint( 0 )
  • If function is empty, raises an error, except if SLIFIS_NO_CHECKING is defined, then unknow behaviour (probably crash...)

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().

Returns last point of function.

  • Equivalent to GetPoint( GetNbPoints()-1 )
  • If function is empty, raises an error, except if SLIFIS_NO_CHECKING is defined, then unknow behaviour (probably crash...)

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().

bool slifis::MEMBFUNC::IsEmpty ( ) const [inline]
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 :

  • if v_pts is empty, then _MaxValue and _MinValue must hold the same value. else,
  • Must have at least 2 points
  • The points _are_ sorted in increasing x order
  • Max value >= Min value
  • the points MUST NOT have an equal x value

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:

  • compute the slope before and after
  • if the slopes are /\ then new max
  • if the slopes are -\ then new max
  • if the slopes are /- then new max

In the following, the slopes are coded as follows:

  • constant, no slope : 0
  • up slope : 1
  • down slope : -1

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().

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().

AlphaCuts the function (see Unary operations)

Algorithm:

  • Find intersection points between function and constant function of value alpha
  • For each of them
    • fetch their x value
    • if even, add a point of value (x-epsilon, 0), else add a point of value (x+epsilon, 0)
  • Add the intersection points
  • Add all the points of original function that are above 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().

Truncate the function to alpha (see Unary operations)

  • Formally, this is done by doing a AND operation with an empty function of fuzzy value 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().

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().

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().

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().

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 
)
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]
const std::string& slifis::MEMBFUNC::GetName ( ) const [inline]
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

Deprecated:
not useful any more, kept for potential future usage.

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.

Warning:
WIP, testing is in file test_membfunc.cpp

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.

  • This function achieves 4 steps :
    1. Remove duplicate points.
    2. Remove useless points, i.e. points where segment before and after has the same slope.
    3. Check for emptyness
    4. Compute min/max values of function

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().

Center Of Gravity defuzzyfication method (private)

References __IN__, __OUT__, GetNbPoints(), GetPoint(), slifis::FPOINT::GetX(), and slifis::FPOINT::GetY().

Referenced by Defuzzify().

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().

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().

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().

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)

  • Assumes p1.x < p2.x
  • Index of first point will be in id1
  • Index of last point will be in id2
  • Returns id2-id1+1 (if interval found)

Be careful, don't use these two values if return value is 0 !

Bug:
An assert gets triggered here when playing with demo3, investigate...

References __IN__, __OUT__, GetFirstPoint(), GetLastPoint(), GetNbPoints(), slifis::FPOINT::GetX(), and v_pts.

Referenced by slifis::P_FIP_OneSide().

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.

  • Q : Function can have 3 points and being empty !!! How is this handled ?
  • A : Yes, but function is supposed to be going through P_RemoveUselessPoints() before, so it is this latter function task to remove useless points, until the number of points gets down to 2

References __IN__, __OUT__, Clear(), GetNbPoints(), SLIFIS_EPSILON_FUZZY, and v_pts.

Referenced by Cleanup().

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.

  • Returns true on success, false if I/O error
  • See also: MEMBFUNC::Read()

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.

  • Assumes :
    • file pointer is correctly set.
    • function is empty.
  • Returns true on success, false if I/O error
  • See also: MEMBFUNC::Write()

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]
bool slifis::MEMBFUNC::P_Read_XML ( TiXmlElement *  pElem) [private]

Friends And Related Function Documentation

friend class FUZZY_ROOT [friend]
void FuzzyMax ( const MEMBFUNC f1,
const MEMBFUNC f2,
MEMBFUNC out 
) [friend]

Performs fuzzy MAX between two functions.

Warning:
in1 and in2 cannot be used as out

See Binary operations

void FuzzyMin ( const MEMBFUNC f1,
const MEMBFUNC f2,
MEMBFUNC out 
) [friend]

Performs fuzzy MIN between two functions.

Warning:
in1 and in2 cannot be used as out

See Binary operations

Referenced by Truncate().

void FuzzyProduct ( const MEMBFUNC f1,
const MEMBFUNC f2,
MEMBFUNC out 
) [friend]

Performs fuzzy product between two functions.

out = in1 * in2

See Binary operations

Warning:
in1 and in2 cannot be used as out
void FuzzyBSum ( const MEMBFUNC f1,
const MEMBFUNC f2,
MEMBFUNC out 
) [friend]

Performs bounded sum between two functions ( $ y = \min(1,a+b) $ )

See Binary operations

void FuzzyPSum ( const MEMBFUNC f1,
const MEMBFUNC f2,
MEMBFUNC out 
) [friend]

Performs Probabilistic sum between two functions ( $ y = a+b-a.b $ )

See Binary operations

void FuzzyLukas ( const MEMBFUNC f1,
const MEMBFUNC f2,
MEMBFUNC out 
) [friend]

Performs Łukasiewicz t-norm between two functions ( $ y = \max \{ 0, a+b-1 \} $ )

See Binary operations

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.

  • function out is cleared, its size is the number of intersections found
  • the return value of P_FIP_OneSide() is only there for potential debugging needs

The 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.

  • Please note that the output function _may_ be not valid ! (i.e., it can hold only one point)
  • This method needs to achieve two steps:
    • consider all points of fa, and compare to y value of fb
    • consider all points of fb, and compare to y value of fa
  • Finally, it removes duplicate points, if any.
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.

  • Adds the point (x,y) to function out if real value x is stricly higher than x1 and strictly lower than x2

Member Data Documentation

std::vector<FPOINT> slifis::MEMBFUNC::v_pts [private]
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().