A fuzzy logic C++ library
Definition: Fuzzy inference systems have their inputs and outputs partionned through "sets" of membership functions. So basically, it is a group of several membership functions related to the same physical input (or output).
Two kinds are provided, input sets (FUZZY_IN) and output sets (FUZZY_OUT). They both are inherited from FUZZY_ROOT (that shouldn't be used by user). Also, note that a SLIFIS object only holds ONE (1) output (set of membership functions) at present. The differences between FUZZY_IN and FUZZY_OUT is that when using "automatic building" (that is, letting the constructor automatically define the membership function), behavior is not the same (see below).
Naming: You can give them a name, but an empty constructor is also provided. For input sets, a incremental name will be generated, so no set can have the same name in this case (except, of course, if you MANUALLY give to a set a name identical as one the was automatically generated...)
You can create a set of membership functions by several ways. Either you want the contained functions to be generated automatically, either you want to have more control on these functions, and build them yourself.
FUZZY_IN fin( "Temperature" ); MEMBFUNC f1( "Cold", MF_HL, 10., 20. ); MEMBFUNC f2( "Warm", MF_LL, 10., 20., 40., 50. ); MEMBFUNC f3( "Quite Hot", MF_TRI, 40., 50., 60. ); MEMBFUNC f4( "Hot", MF_LH, 50., 60. ); fin.AddMf( f1 ); fin.AddMf( f2 ); fin.AddMf( f3 ); fin.AddMf( f4 ); SLIFIS fis; fis.AddInput( fin );
This will produce the following set:
Or, you an also directly pass a function using a constructor:
The other way to create a set is to use the provided automatic generation functions that will generate triangular functions. Two things can be done:
Functions names are generated automatically by the fis (see below). But we need to distinguish between input sets and output sets, because output sets need to have "left" and "right" values equal to 0. Else, we won't be able to do proper defuzzification, using a Center of Gravity method. For input sets, the most left and right functions will have a left and right value equal to 1.
If you want to give the points (4 points is the minimum):
std::vector<REALVAL> vect; vect.push_back( 10.0 ); vect.push_back( 20.0 ); vect.push_back( 40.0 ); vect.push_back( 70.0 ); FUZZY_OUT fout( vect ); SLIFIS fis; fis.SetOutputSet( fout );
This will produce the following set:
If you only need regularly spaced functions, then you can just give minimum and maximum values, and the number of functions you want : (2 functions minimum)
FUZZY_OUT fs( 1.0, 5.0, n ); // args: min, max, nb_functions SLIFIS fis; fis.SetOutputSet( fout );
If you know min/max values, but you noticed that data isn't evenly spaced, then you can used the "log" spacing. For 2 functions, it is the same as the latter method.
FUZZY_OUT fs( 1.0, 5.0, n, FS_LOG ); // args: min, max, nb_functions SLIFIS fis; fis.SetOutputSet( fout );
If you want to give the points (in this case, 3 points is the minimum) :
std::vector<REALVAL> vect; vect.push_back( 10.0 ); vect.push_back( 50.0 ); vect.push_back( 70.0 ); FUZZY_IN fs( "Input 1", vect );
If you want regularly spaced functions (2 functions minimum):
FUZZY_IN fs( 1.0, 5.0, n ); // args: min, max, nb_functions
If you know min/max values, but you noticed that data is'nt evenly spaced, then you can used the "log" spacing. For 2 functions, it is the same as the latter method.
FUZZY_IN fs( 1.0, 5.0, n, FS_LOG ); // args: min, max, nb_functions
See FUZZY_ROOT::FUZZY_ROOT(const std::vector<REALVAL>&) and FUZZY_ROOT::SetTriangularSet() for details.
If you need to edit a membership function that is contained into a set of functions, the method FUZZY_ROOT::GetMf() returns a reference on the contained membership function. You can then edit the points as you like using their index, as in following example :
... MEMBFUNC& mf = fs.GetMF( "warm" ); mf.ModifyPoint( 1, x, y ); ...
Beware, accessing an invalid index will trigger the error handler, and app will exit with error message written in log file.