Button 0Button 1Button 2Button 3Button 4

Fuzzy Theory

Linguistic Variables and Membership Functions

Linguistic variables closely interact with both Java code and fuzzy rules. The same linguistic variable can participate in fuzzy evaluations performed by different fuzzy engines. Each fuzzy assignment will be accounted for during defuzzification. Each linguistic variable has an arbitrary number of associated membership functions: each membership function is represented by a trapezoid. Trapezoidal membership functions allow simple implementation of the most widely used forms: rectangle, triangle and trapezoid.

Creating and Defining a Linguistic Variable
Step Example Note

1. Allocation of a linguistic variable

LinguisticVariable angle = Factory.makeLinguisticVariable("angle");

The String argument is the name/label of this particular linguistic variable in the rules

2. Definition of membership functions

angle.add("negative", -3.14, -3.14, 0.0314, 0);

"Negative" here is the name that will be used to address this membership function (if angle is negative ...), other four parameters define four key points of a trapezoid. They follow in the order of left bottom, left top, right top and right bottom points.


Hedges allow to express different degrees of membership in a fuzzy set. The package has three predefined hedges:

"not" -
"very" -
"somewhat" -

Arbitrary hedges can be defined by deriving classes from the base class Hedge. Method getName() should return a string containing the hedge name. Method hedgeIt() should perform the desired hedge operation.

Fuzzy Rules

All fuzzy evaluations are based on the rules in the symbolic representation. Linguistic variables, membership functions, hedges and fuzzy operations are referenced by their respective symbolic names. Symbolic representation of the rules allows easy understanding of the rules and simplifies the debugging process. Fuzzy rules are represented by text strings in the following format:

<label> if LV1 is <hedge ...> MF1 <and/or LV2 is <hedge ...> MF2 and/or ...> then LVN is <hedge ...> MFN ... < and rule label weight is <hedge ...> weightMF>

<label> set LV1 is <hedge ...> MF1 <and LV2 is <hedge ...> MF2 ...> <and rule label weight is <hedge ...> weightMF>


Parts of a Fuzzy Rule
Part Description


A text label assigned to a rule. A rule's default weight is 1.0. The weight can be changed by executing expression of the form
"rule label weight is weightMF"
in the right part of a rule. The same label can be assigned to more than one rule. In this case weight change will affect all of the labeled rules.

Example: start: if angle is ...


A service word indicating the beginning of the left part (evaluation part) of a fuzzy rule.


A linguistic variable. Linguistic variables are addressed by their names. Each linguistic variable has one or more associated membership functions.


A service word separating linguistic variable and hedges/membership function.


The engine has 3 predefined hedges: "not", "very" and "somewhat". The user can define arbitrary hedges and use them in rules.

Example: if weather is not very nice ...


A membership function. Membership functions are addressed by their names. Each membership function is defined as a trapezoid.


Service words indicating logical operation to be performed on the neighboring fuzzy expressions. Priority of the and/or operations decreases from left to right and may be changed by applying parenthesis. The engine supports arbitrary number of expressions on the left part, arbitrary nesting and and/or operations.

Example: if angle is wide or (angle is normal and (speed is high or speed is normal)) ...


A service word separating left part of expression from the right part (execution part). Result obtained from evaluation of the left part is used to perform fuzzy assignments in the right part. The form of fuzzy expressions is the same as in the evaluation part, except assignment is performed instead of evaluation. During the assignment, hedges apply to the result of evaluation part. Application of the hedges is local for each fuzzy expression. If more than one assignment is to be performed, then fuzzy expression should separated by the service word "and" .

Example: ... then power is very low and steering is toTheLeft


This is a reserved linguistic variable. Linguistic variable "weight" is defined by the user and serves for the purpose of changing a rule's weight. A copy of this LV is created for each unique label. Changes of weight are performed by defuzzification of the copy assigned to a particular label, thus multiple weight changes are carried out in fuzzy manner. How much a rule's weight will be changed depends both on definition of membership functions for "weight", evaluation result after application of hedges and number of assignments.


LinguisticVariable weight= Factory.makeLinguisticVariable("weight");
fuzzyEngine.evaluateRule("start: if angle is wide then rule start: weight is low");

When weight assignment is performed on the same rule that assigns the weight (see Example) then only one iteration of weight change is performed, i.e. it does not fall into an endless loop of weight change.


A service word for unconditional assignments. If "set" is encountered instead of "if", result of the left part evaluation is assumed to be 1.0 and all assignments are performed for that value.

Example: set power is low ...

Evaluating Rules

All fuzzy evaluations are performed by a fuzzy engine. This Java class allows parsing and evaluation of fuzzy rules. The following example illustrates the main steps necessary for performing a fuzzy evaluation:

Steps to Evaluating Rules


1. Create linguistic variables and define membership functions

Factory factory = Factory.getFactory();

LinguisticVariable angle = factory.makeLinguisticVariable("angle");


LinguisticVariable power = factory.makeLinguisticVariable("power");


2. Create a fuzzy context

FuzzyState state = factory.makeFuzzyState();

3. Register all linguistic variables


4. Load and parse rules

Reader ruleTextReader = /* create a java.io.Reader to the text rules */ ;
RuleBlock ruleBlock = fuzzyState.createRuleExecutionSet(ruleTextReader);

5. Peform fuzzy evaluations


6. Obtain the result(s)

double result = power.defuzzify();

Linguistic variables must be defined (registered) before parsing can occur. Parsing is performed on a java.io.Reader to provide a great deal of flexibility in how rules are loaded. The RuleBlock may be used to execute the rules over and over.

SourceForge.net Logo