A fuzzy logic C++ library

NAVIGATION
Once you have completely defined FIS (i.e., output fuzzy partition, inputs partition, and rules are defined), you can use it in production. You can programmaticaly do this in your code, but you can also load a previously saved fis.
Using it in production means computing an output value, given a set of input values.
int main() { SLIFIS fis; fis.Load( "myfis.fis" ); // this will throw an error if file not found. // give input values fis.SetInputValue( 0, ... ); // one line for each input fis.SetInputValue( 1, ... ); ... // compute crisp output value REALVAL out_val = GetOutputValue( out_val ); cout << "output value = " << out_val << endl; }
Internally, the FIS takes in charge the required following steps, usually called "fuzzy logic inference". The first step is common to Mamdani and TS Fis. It computes the "firing strength of each rule", that is, how much the given set of input values trigger the rule. The output is a crisp value.
For a Mamdani Fis type, the inference process is done is SLIFIS::P_Evaluate_M(). It can be described by the following algorithm:
For a TS type Fis, the inference process is done in SLIFIS::P_Evaluate_TS(). It can be described by the following algorithm:
For example, say we have for a 2input fis these two rules:
r_1: IF x1 is "red" AND x2 is "good" THEN y = 2 x1 + 3 x2 r_2: IF x1 is "blue" AND x2 is "bad" THEN y = 3 x1 + 4 x2
Say we have , and the membership functions ot the two inputs are defined such that the firing strength of the rules have the following values:
Then, we can compute for each rule an output value:
The global output value will be computed as the weighted average of the two ouput values:
At each step of this inference process, several parameters can be adjusted:
Each rule uses either the "OR" or the "AND" operation for term aggregation. For "AND" operation, any tnorm among slifis::EN_TNORM can be used, and for "OR" operations, any snorm amont slifis::EN_SNORM can be used. These can be adjusted by a call to SLIFIS::SetRuleInferenceMethod().
The inference parameters can be edited with the SLIFIS::GetInferenceParams() by assigning values to the INF_PARAMS struct, such as in the following example:
fis.GetInferenceParams().DefuzzMethod = DF_COG;
It can also be printed out:
fis.GetInferenceParams().Print( stderr );
Defuzzification is the operation of computing a crisp value given some membership function. This is required in the Mamdani inference process, that computes a global membership function produced by merging together the output of each rule. Defuzzification requires that the function is finite (i.e. it has left and right zero values). This can be checked by a call to MEMBFUNC::IsFinite().
Actually, the following methods are implemented (the most common), through slifis::EN_DEFUZZMETHOD:
See MEMBFUNC::Defuzzify() for details, and demo app demo3.cpp, in folder src/demo.
For a fis, this is done automatically by SLIFIS::GetOutputValue().