Skip to content

kenoma/adaptive-neuro-fuzzy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.NET ANFIS

This is WIP project

About

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 Bi
where 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).

Algorithm
  1. Perform clustering on datasets x and y, where x is an input dataset and y is a dataset of desired outputs .
  2. Initialize fuzzy sets Ai and consequences Bi with use of obtained clusters.
  3. Tune ANFIS parameters with backprop in order to improve inference of the system.
  4. (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.
Supported membership functions
  1. Triangle
  2. Bell-shaped
  3. Gaussian
Example of usage

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.

Releases

No releases published

Packages

No packages published

Languages