# fuzzylite/jfuzzylite

jfuzzylite: a fuzzy logic control library in Java
Java Matlab
 Failed to load latest commit information. examples Jan 6, 2016 jfuzzylite May 17, 2016 .travis.yml Apr 13, 2015 AUTHOR Jul 12, 2014 COPYING Jul 12, 2014 COPYING.LESSER Jul 12, 2014 ChangeLog Apr 19, 2015 INSTALL Apr 20, 2015 NEWS Apr 20, 2015 README.md Apr 20, 2015 jfuzzylite.png Jun 16, 2014

# jfuzzylite ™

## A Fuzzy Logic Control Library in Java

Current version: 5.0 (April, 2015)

### Introduction

jfuzzylite is a free and open-source fuzzy logic control library programmed in Java, thereby making it available for multiple platforms (Windows, Linux, Mac), and especially for Android. Its goal is to allow you to easily create fuzzy logic controllers in a few steps utilizing object-oriented programming without requiring any third-party libraries.

#### Reference

If you are using jfuzzylite, please cite the following reference in your article:

Juan Rada-Vilela. fuzzylite: a fuzzy logic control library, 2014. URL http://www.fuzzylite.com.

 @misc{fl::fuzzylite,
title={fuzzylite: a fuzzy logic control library},
url={http://www.fuzzylite.com},
year={2014}}


jfuzzylite 5.0 is dual licensed under the GNU Lesser General Public License (LGPL) v3.0 and a paid commercial license. If your application requires a commercial license, please contact sales@fuzzylite.com. For further information on your rights, please refer to the GNU LGPL.

The change of license is an attempt to raise funds in order to be able to work part-time in the development of the fuzzylite family of products, namely fuzzylite (C++), jfuzzylite (Java), pyfuzzylite (Python), and QtFuzzyLite (Windows/Linux/Mac).

There are still many things to do!

Besides donations, you can significantly contribute by purchasing a license of the entirely new QtFuzzyLite commercial application. In addition, if you require (paid) private support, please contact jcrada@fuzzylite.com.

### Features

Controllers Types (5) Mamdani, Takagi-Sugeno, Larsen, Tsukamoto, Inverse Tsukamoto

Linguistic terms Basic (4) triangle, trapezoid, rectangle, discrete. Extended (9) bell, cosine, gaussian, gaussian product, pi-shape, sigmoid difference, sigmoid product, spike. Edges (4) concave, ramp, sigmoid, s-shape, z-shape. Functions (3) constant, linear, function.

Conjunction and Activation T-Norm (7) minimum, algebraic product, bounded difference, drastic product, einstein product, hamacher product, nilpotent minimum.

Disjunction and Accumulation S-Norm (8) maximum, algebraic sum, bounded sum, normalized sum, drastic sum, einstein sum, hamacher sum, nilpotent maximum.

Defuzzifiers Integral (5) centroid, bisector, smallest of maximum, largest of maximum, mean of maximum, Weighted (2) weighted average, weighted sum.

Hedges Types (6) any, not, extremely, seldom, somewhat, very.

Import Types (3) FuzzyLite Language fll, Fuzzy Inference System fis, Fuzzy Control Language fcl.

Export Types (6) C++, Java, FuzzyLite Language fll, FuzzyLite Dataset fld, Fuzzy Inference System fis, Fuzzy Control Language fcl.

Examples (30+) of Mamdani, Takagi-Sugeno and Tsukamoto controllers from fuzzylite, Octave and Matlab, each included in the following formats: C++, Java, fll, fld, fis, and fcl.

### Example

import com.fuzzylite.Engine;
import com.fuzzylite.FuzzyLite;
import com.fuzzylite.Op;
import com.fuzzylite.defuzzifier.Centroid;
import com.fuzzylite.imex.FldExporter;
import com.fuzzylite.norm.s.Maximum;
import com.fuzzylite.norm.t.Minimum;
import com.fuzzylite.rule.Rule;
import com.fuzzylite.rule.RuleBlock;
import com.fuzzylite.term.Triangle;
import com.fuzzylite.variable.InputVariable;
import com.fuzzylite.variable.OutputVariable;

public class Example {

public static void main(String[] args){
Engine engine = new Engine();
engine.setName("simple-dimmer");

InputVariable ambient = new InputVariable();
ambient.setName("Ambient");
ambient.setRange(0.000, 1.000);

OutputVariable power = new OutputVariable();
power.setName("Power");
power.setRange(0.000, 1.000);
power.setDefaultValue(Double.NaN);

RuleBlock ruleBlock = new RuleBlock();
ruleBlock.addRule(Rule.parse("if Ambient is DARK then Power is HIGH", engine));
ruleBlock.addRule(Rule.parse("if Ambient is MEDIUM then Power is MEDIUM", engine));
ruleBlock.addRule(Rule.parse("if Ambient is BRIGHT then Power is LOW", engine));

engine.configure("", "", "Minimum", "Maximum", "Centroid");

StringBuilder status = new StringBuilder();
throw new RuntimeException("Engine not ready. "
+ "The following errors were encountered:\n" + status.toString());
}

for (int i = 0; i < 50; ++i) {
double light = ambient.getMinimum() + i * (ambient.range() / 50);
ambient.setInputValue(light);
engine.process();
FuzzyLite.logger().info(String.format(
"Ambient.input = %s -> Power.output = %s",
Op.str(light), Op.str(power.getOutputValue())));
}
}
}

### What's Next?

• Source code documentation
• Type-2 Fuzzy Logic Controllers
• Adaptive Neuro-Fuzzy Inference System (ANFIS)
• Fuzzy C-means data clustering

### Building from Source

Building from source requires you to have either Ant or Maven installed.

$ant -f build.xml The Ant script will create the library bin/jfuzzylite.jar and the library sources bin/jfuzzylite-src.jar. #### Maven $ mvn install

The Maven script will create the library target/jfuzzylite-5.0.jar and library sources target/jfuzzylite-5.0-sources.jar.

### Binaries

Besides the library, the binaries contain the FuzzyLite Console application. The application can be executed using the following command.

#### Integral Defuzzifiers

• (important) Proper handling of indefinite integral defuzzification, that is, returning fl::nan when [minimum|maximum]=[NaN|Inf].
• Default resolution of integration is defined as static int IntegralDefuzzifier::defaultResolution=200, and can be changed via static IntegralDefuzzifier::setDefaultResolution().
• (important) In fuzzylite, the accumulation operator has been for several versions associated with the output variables and not with the rule blocks, despite that the FCL format and other fuzzy logic control libraries associate the accumulation operator with the rule blocks. The argument for such a decision is that fuzzylite provides coherent support for multiple rule blocks operating on the same engine and on the same output variables. For example, if multiple rule blocks operate on the same output variables, it only makes sense to have a single accumulation operator associated with each output variable such that the defuzzifier can naturally operate over the accumulated fuzzy output. Differently, if the accumulation operator were associated with the rule block, the possibility of having different accumulation operators in different rule blocks questions (1) the possibility of having multiple rule blocks operating over the same output variables; and (2) the usage of different accumulation operators over the accumulation and defuzzification processes. Certainly, if (1) is not possible, i.e, different rule blocks only operate on different output variables, then (2) is not a problem because the accumulation process and defuzzification of each variable will only have a single accumulation operator. It is therefore that the association of the accumulation operator with the output variable in fuzzylite provides a better design and an additional feature that allows having multiple rule blocks operating over the same output variables.
• Added method Defuzzifier::clone().

#### Importers and Exporters

• (EXTREMELY important) Since terms have a new height property, [Fll|Fis|Fcl]Exporter exports terms with an additional double at the end, which indicates the height of the term. However, if height=1.0, the additional scalar is not exported.
• (EXTREMELY important) In [Fll|Fis|Fcl]Importer, when importing terms, if there is an additional double it will be assumed as the height of the term. For example, term: high Gaussian 1.0 0.5 0.75 will create a Gaussian term with mean 1.0, standard deviation 0.5 and height 0.75. This is extremely important because there are some examples from Matlab in fis format that append a useless 0.0 to some terms.
• (EXTREMELY important) In FisExporter, if the Takagi-Sugeno controller has no activation or accumulation operators (as it should generally be the case), Octave and Matlab will not be able to import the fis file. To overcome this issue, you will have to set ImpMethod="min" and AggMethod="max", where ImpMethod and AggMethod are just dummy operators that can be set to any TNorm and SNorm, respectively.
• (important) Improved compatibility of the exported code obtained with [Fis|Fcl]Exporter by exporting the additional features of jfuzzylite only when these are different from the default operation. For example, the following features will not be exported given their values: [Input|Output]Variable::enabled = true;, OutputVariable::lock-previous = false;, OutputVariable::lock-range = false;, amongst others.
• (important) Renamed FLL property 'lock-valid' to 'lock-previous'.
• (important) Renamed FIS property 'LockValid' to 'LockPrevious'.
• (important) Renamed FCL property 'LOCK: VALID' to 'LOCK: PREVIOUS'.
• (important) Export your controllers to files using [Fll|Fld|Fis|Fcl]Exporter::toFile().
• (important) Import your controllers from files using [Fll|Fis|Fcl]Importer::fromFile().
• (important) FldExporter exports the FuzzyLite Dataset of an engine utilizing the input values of another FuzzyLite Dataset.
• (important) Renamed method FldExporter::toWriter() to FldExporter::write().
• Removed variable and methods for property int FldExporter::maximum.
• Added option in CppExporter to prepend the namespace prefix fl:: to the classes, and by default it does not prepend prefix.
• Improvement accuracy of FisImporter when importing fis files whose double values have more than three decimal numbers.
• Renamed methods in [Fis|Fcl]Importer::extract* to [Fis|Fcl]Importer::parse*.

#### Factories

• Created a generic CloningFactory<T> to create clones of objects.
• (important) Created FunctionFactory based on CloningFactory<Function::Element> where function operators and methods are stored to be cloned as necessary by Function. Additional functions and operators can be easily registered.
• (VERY important) Moved built-in functions and operators from Function to FunctionFactory.
• Renamed methods Factory<T>::[register|deregister]Class() to Factory<T>::[register|deregister]Constructor().
• (important) Renamed Factory<T> to ConstructionFactory<T>.

#### Examples

• (important) Added two examples for basic rule chaining: mamdani/SimpleDimmerInverse.fll and mamdani/Laundry.fll.
• Included the original example files in fis format.
• Added conversion of examples/original/*.fis to examples/original/*.fll.
• Modified original/takagi-sugeno examples to reflect activation: none; accumulation: none;.
• Updated FLD examples produced from the original examples.
• (important) Added file fuzzylite/src/m/compare.m to compare the output values of your fuzzylite engines with the evaluation of the same engine in Octave/Matlab.
• (important) Added file examples/examples.mat containing the comparison of the output values between fuzzylite and Matlab's Fuzzy Logic Toolbox.
• Added code to perform benchmarks.

#### Console

• (important) Console includes option to import custom input dataset from file and export its respective output values.
• (important) Created the FuzzyLite Interactive Console, which can be started by specifying an input file and the output format, e.g., fuzzylite -i SimpleDimmer.fll -of fld.
• (important) Fixed operation when using multiple hedges to operate from right-most to left-most, e.g. if Ambient is not very extremely bright evaluates as follows not(very(extremely(bright))).
• (important) Fixed membership functions of specific cases of Triangle when a=b or b=c, and Trapezoid when a=b or c=d.