jFuzzyLogic: Open Source Fuzzy Logic (Java)

Optimization example

Java code to optimize fuzzy sets' parameters and fuzzy rule's weights

//---
// Load FIS (Fuzzy Inference System)
//---
FIS fis = FIS.load("fcl/qualify.fcl");
RuleBlock ruleBlock = fis.getFunctionBlock().getRuleBlock();

//---
// Create a list of parameter to optimize
//---
ArrayList parameterList = new ArrayList();

// Add variables. 
// Note: Fuzzy sets' parameters for these 
// variables will be optimized
Parameter.parameterListAddVariable(parameterList
                                    , fis.getVariable("scoring"));
Parameter.parameterListAddVariable(parameterList
                                    , fis.getVariable("credLimMul"));

// Add every rule's weight
for( Rule rule = ruleBlock ) 
    Parameter.parameterListAddRule(parameterList, rule);

//---
// Create an error function to be 
// optimzed (i.e. minimized)
//---
ErrorFunctionQualify errorFunction = new ErrorFunctionQualify();

//---
// Optimize (using 'Delta jump optimization')
//---
OptimizationDeltaJump optimizationDeltaJump = 
        new OptimizationDeltaJump(ruleBlock
                , errorFunction, parameterList);

// Number optimization of iterations
optimizationDeltaJump.setMaxIterations(20);

optimizationDeltaJump.optimize(true);

The error funcion (in this particular case, ErrorFunctionQualify) can be just any error function, the structure for the code should be like this:
public class ErrorFunctionQualify extends ErrorFunction {
    public double evaluate(RuleBlock ruleBlock) {
        double error;
        // Caculate your desired error here...
        return error;
    }
}    

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Author: Pablo Cingolani (pcingola@users.sourceforge.net)
Key words (for search engines):
Fuzzy logic
Fuzzy logic software
Fuzzy logic package
Fuzzy logic library
Fuzzy logic sourceforge sf.net
Open source
GNU
GPL LGPL
java
Windows Linux OSX
FCL
IEC 1131
IEC 61131
IEC 61131 part 7
IEC 61131-7
Fuzzy logic Wikipedia