This is WIP project
This C# implementation of ANFIS (Adaptive Neuro Fuzzy Inference System) is designed to solve task y=f(x) in form of IF–THEN rules
if x is Ai then y is Biwhere x is an m dimensional input vector, and y is an n dimensional vector of desired output, Ai is fuzzy set and Bi is consequence part of *i*-th rule.
Current version performs inference based on zero-order Sugeno fuzzy model (special case of the Mamdani Fuzzy inference system).
- Perform clustering on datasets x and y, where x is an input dataset and y is a dataset of desired outputs .
- Initialize fuzzy sets Ai and consequences Bi with use of obtained clusters.
- Tune ANFIS parameters with backprop in order to improve inference of the system.
- (Optional) if during training occurs situation when input case is not firing any rule, then it is possible to add new rule to database or adjust parameters of existing rules to fix issue.
- Triangle
- Bell-shaped
- Gaussian
Following code generates training datasets of logistic map evolution in form (xn-1, xn) → xn+1 and build ANFIS which can predict xn+1 on two previouse values (xn-1, xn) (testing and crossvalidation are omitted for simplicity).
int trainingSamples = 2000;
double[][] x = new double[trainingSamples][];
double[][] y = new double[trainingSamples][];
double px = 0.1;
double r = 3.8;
double lx = r * px * (1 - px);
//generate training set
for (int i = 0; i < trainingSamples; i++)
{
x[i] = new double[] { px, lx };
px = lx;
lx = r * lx * (1 - lx);
y[i] = new double[] { lx };
}
//initialize trainig algorithm
Backprop bprop = new Backprop(1e-2);
//if during training you faced an unknown sample which is not firing any rule
// you can manage this situation with callback bprop.UnknownCaseFaced += .... ;
//initialize clustering algo to provide initial rule set
KMEANSExtractorIO extractor = new KMEANSExtractorIO(10);
//Build IS with Gaussian membershib functions, backprop training and kmeans for rule initialization
ANFIS fis = ABuilder<GaussianRule>.Build(x, y, extractor, bprop, 1000);
//[Backprop - GaussianRule] Error 0,000690883407351925 Elapsed 00:00:31.1691934 RuleBase 10
Now you can use trained fis
as folowing
double[] y = fis.Inference(x);
For more examples look into testANFIS.cs
.