AForge.Fuzzy
This class represents a fuzzy clause, a linguistic expression of the type "Variable IS Value".
A Fuzzy Clause is used to verify if a linguistic variable can be considered
as a specific value at a specific moment. Linguistic variables can only assume value of
their linugistic labels. Because of the nature of the Fuzzy Logic, a Variable can be
several of its labels at the same time, with different membership values.
For example, a linguistic variable "temperature" can be "hot" with a membership 0.3
and "warm" with a membership 0.7 at the same time. To obtain those memberships, Fuzzy Clauses
"temperature is hot" and "temperature is war" can be built.
Typically Fuzzy Clauses are used to build Fuzzy Rules ().
Sample usage:
// create a linguistic variable to represent temperature
LinguisticVariable lvTemperature = new LinguisticVariable( "Temperature", 0, 80 );
// create the linguistic labels (fuzzy sets) that compose the temperature
TrapezoidalFunction function1 = new TrapezoidalFunction( 10, 15, TrapezoidalFunction.EdgeType.Right );
FuzzySet fsCold = new FuzzySet( "Cold", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 10, 15, 20, 25 );
FuzzySet fsCool = new FuzzySet( "Cool", function2 );
TrapezoidalFunction function3 = new TrapezoidalFunction( 20, 25, 30, 35 );
FuzzySet fsWarm = new FuzzySet( "Warm", function3 );
TrapezoidalFunction function4 = new TrapezoidalFunction( 30, 35, TrapezoidalFunction.EdgeType.Left );
FuzzySet fsHot = new FuzzySet( "Hot" , function4 );
// adding labels to the variable
lvTemperature.AddLabel( fsCold );
lvTemperature.AddLabel( fsCool );
lvTemperature.AddLabel( fsWarm );
lvTemperature.AddLabel( fsHot );
// creating the Clause
Clause fuzzyClause = new Clause( lvTemperature, fsHot );
// setting the numerical input of the variable to evaluate the Clause
lvTemperature.NumericInput = 35;
float result = fuzzyClause.Evaluate( );
Console.WriteLine ( result.ToString( ) );
Gets the of the .
Gets the of the .
Initializes a new instance of the class.
Linguistic variable of the clause.
Label of the linguistic variable, a fuzzy set used as label into the linguistic variable.
The label indicated was not found in the linguistic variable.
Evaluates the fuzzy clause.
Degree of membership [0..1] of the clause.
Returns the fuzzy clause in its linguistic representation.
A string representing the fuzzy clause.
This class implements the centroid defuzzification method.
In many applications, a Fuzzy Inference System is used to perform linguistic
computation, but at the end of the inference process, a numerical value is needed. It does
not mean that the system needs precision, but simply that a numerical value is required,
most of the times because it will be used to control another system that needs the number.
To obtain this numer, a defuzzification method is performed.
This class implements the centroid defuzzification method. The output of a Fuzzy
Inference System is a set of rules (see ) with firing strength greater
than zero. Those firing strength apply a constraint to the consequent fuzzy sets
(see ) of the rules. Putting all those fuzzy sets togheter results
in a a shape that is the linguistic output meaning.
The centroid method calculates the center of the area of this shape to obtain the
numerical representation of the output. It uses a numerical approximation, so a number
of intervals must be choosen. As the number of intervals grow, the precision of the
numerical ouput grows.
For a sample usage of the see
class.
Initializes a new instance of the class.
Number of segments that the speech universe will be splited
to perform the numerical approximation of the center of area.
Centroid method to obtain the numerical representation of a fuzzy output. The numerical
value will be the center of the shape formed by the several fuzzy labels with their
constraints.
A containing the output of several
rules of a Fuzzy Inference System.
A operator to be used when constraining
the label to the firing strength.
The numerical representation of the fuzzy output.
The numerical output is unavaliable. All memberships are zero.
Interface which specifies set of methods required to be implemented by all defuzzification methods
that can be used in Fuzzy Inference Systems.
In many applications, a Fuzzy Inference System is used to perform linguistic computation,
but at the end of the inference process, a numerical value is needed. It does not mean that the system
needs precision, but simply that a numerical value is required, most of the times because it will be used to
control another system that needs the number. To obtain this numer, a defuzzification method is performed.
Several deffuzification methods were proposed, and they can be created as classes that
implements this interface.
Defuzzification method to obtain the numerical representation of a fuzzy output.
A containing the output of
several rules of a Fuzzy Inference System.
A operator to be used when constraining
the label to the firing strength.
The numerical representation of the fuzzy output.
The class represents the output of a Fuzzy Inference System.
The class keeps set of rule's output - pairs with the output fuzzy label
and the rule's firing strength.
Sample usage:
// linguistic labels (fuzzy sets) that compose the distances
FuzzySet fsNear = new FuzzySet( "Near",
new TrapezoidalFunction( 15, 50, TrapezoidalFunction.EdgeType.Right ) );
FuzzySet fsMedium = new FuzzySet( "Medium",
new TrapezoidalFunction( 15, 50, 60, 100 ) );
FuzzySet fsFar = new FuzzySet( "Far",
new TrapezoidalFunction( 60, 100, TrapezoidalFunction.EdgeType.Left ) );
// front distance (input)
LinguisticVariable lvFront = new LinguisticVariable( "FrontalDistance", 0, 120 );
lvFront.AddLabel( fsNear );
lvFront.AddLabel( fsMedium );
lvFront.AddLabel( fsFar );
// linguistic labels (fuzzy sets) that compose the angle
FuzzySet fsZero = new FuzzySet( "Zero",
new TrapezoidalFunction( -10, 5, 5, 10 ) );
FuzzySet fsLP = new FuzzySet( "LittlePositive",
new TrapezoidalFunction( 5, 10, 20, 25 ) );
FuzzySet fsP = new FuzzySet( "Positive",
new TrapezoidalFunction( 20, 25, 35, 40 ) );
FuzzySet fsVP = new FuzzySet( "VeryPositive",
new TrapezoidalFunction( 35, 40, TrapezoidalFunction.EdgeType.Left ) );
// angle
LinguisticVariable lvAngle = new LinguisticVariable( "Angle", -10, 50 );
lvAngle.AddLabel( fsZero );
lvAngle.AddLabel( fsLP );
lvAngle.AddLabel( fsP );
lvAngle.AddLabel( fsVP );
// the database
Database fuzzyDB = new Database( );
fuzzyDB.AddVariable( lvFront );
fuzzyDB.AddVariable( lvAngle );
// creating the inference system
InferenceSystem IS = new InferenceSystem( fuzzyDB, new CentroidDefuzzifier( 1000 ) );
// going straight
IS.NewRule( "Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero" );
// turning left
IS.NewRule( "Rule 2", "IF FrontalDistance IS Near THEN Angle IS Positive" );
...
// inference section
// setting inputs
IS.SetInput( "FrontalDistance", 20 );
// getting outputs
try
{
FuzzyOutput fuzzyOutput = IS.ExecuteInference ( "Angle" );
// showing the fuzzy output
foreach ( FuzzyOutput.OutputConstraint oc in fuzzyOutput.OutputList )
{
Console.WriteLine( oc.Label + " - " + oc.FiringStrength.ToString( ) );
}
}
catch ( Exception )
{
...
}
Inner class to store the pair fuzzy label / firing strength of
a fuzzy output.
Initializes a new instance of the class.
A string representing the output label of a .
The firing strength of a , to be applied to its output label.
The representing the output label of a .
The firing strength of a , to be applied to its output label.
A list with of a Fuzzy Inference System's output.
Gets the acting as a Fuzzy Inference System Output.
Initializes a new instance of the class.
A representing a Fuzzy Inference System's output.
Adds an output to the Fuzzy Output.
The name of a label representing a fuzzy rule's output.
The firing strength [0..1] of a fuzzy rule.
The label indicated was not found in the linguistic variable.
Removes all the linguistic variables of the database.
This class represents a Fuzzy Inference System.
A Fuzzy Inference System is a model capable of executing fuzzy computing.
It is mainly composed by a with the linguistic variables
(see ) and a
with the fuzzy rules (see ) that represent the behavior of the system.
The typical operation of a Fuzzy Inference System is:
- Get the numeric inputs;
- Use the with the linguistic variables
(see ) to obtain linguistic meaning for each
numerical input;
- Verify which rules (see ) of the are
activated by the input;
- Combine the consequent of the activated rules to obtain a ;
- Use some defuzzifier (see ) to obtain a numerical output.
The following sample usage is a Fuzzy Inference System that controls an
auto guided vehicle avoing frontal collisions:
// linguistic labels (fuzzy sets) that compose the distances
FuzzySet fsNear = new FuzzySet( "Near",
new TrapezoidalFunction( 15, 50, TrapezoidalFunction.EdgeType.Right ) );
FuzzySet fsMedium = new FuzzySet( "Medium",
new TrapezoidalFunction( 15, 50, 60, 100 ) );
FuzzySet fsFar = new FuzzySet( "Far",
new TrapezoidalFunction( 60, 100, TrapezoidalFunction.EdgeType.Left ) );
// front distance (input)
LinguisticVariable lvFront = new LinguisticVariable( "FrontalDistance", 0, 120 );
lvFront.AddLabel( fsNear );
lvFront.AddLabel( fsMedium );
lvFront.AddLabel( fsFar );
// linguistic labels (fuzzy sets) that compose the angle
FuzzySet fsZero = new FuzzySet( "Zero",
new TrapezoidalFunction( -10, 5, 5, 10 ) );
FuzzySet fsLP = new FuzzySet( "LittlePositive",
new TrapezoidalFunction( 5, 10, 20, 25 ) );
FuzzySet fsP = new FuzzySet( "Positive",
new TrapezoidalFunction( 20, 25, 35, 40 ) );
FuzzySet fsVP = new FuzzySet( "VeryPositive",
new TrapezoidalFunction( 35, 40, TrapezoidalFunction.EdgeType.Left ) );
// angle
LinguisticVariable lvAngle = new LinguisticVariable( "Angle", -10, 50 );
lvAngle.AddLabel( fsZero );
lvAngle.AddLabel( fsLP );
lvAngle.AddLabel( fsP );
lvAngle.AddLabel( fsVP );
// the database
Database fuzzyDB = new Database( );
fuzzyDB.AddVariable( lvFront );
fuzzyDB.AddVariable( lvAngle );
// creating the inference system
InferenceSystem IS = new InferenceSystem( fuzzyDB, new CentroidDefuzzifier( 1000 ) );
// going Straight
IS.NewRule( "Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero" );
// Turning Left
IS.NewRule( "Rule 2", "IF FrontalDistance IS Near THEN Angle IS Positive" );
...
// inference section
// setting inputs
IS.SetInput( "FrontalDistance", 20 );
// getting outputs
try
{
float newAngle = IS.Evaluate( "Angle" );
}
catch ( Exception )
{
...
}
Initializes a new Fuzzy .
A fuzzy containing the system linguistic variables.
A defuzzyfier method used to evaluate the numeric uotput of the system.
Initializes a new Fuzzy .
A fuzzy containing the system linguistic
variables.
A defuzzyfier method used to evaluate the numeric otput
of the system.
A operator used to evaluate the norms
in the . For more information of the norm evaluation see .
A operator used to evaluate the
conorms in the . For more information of the conorm evaluation see .
Creates a new and add it to the of the
.
Name of the to create.
A string representing the fuzzy rule.
The new reference.
Sets a numerical input for one of the linguistic variables of the .
Name of the .
Numeric value to be used as input.
The variable indicated in
was not found in the database.
Gets one of the of the .
Name of the to get.
The variable indicated in
was not found in the database.
Gets one of the Rules of the .
Name of the to get.
The rule indicated in
was not found in the rulebase.
Executes the fuzzy inference, obtaining a numerical output for a choosen output
linguistic variable.
Name of the to evaluate.
The numerical output of the Fuzzy Inference System for the choosen variable.
The variable indicated was not found in the database.
Executes the fuzzy inference, obtaining the of the system for the required
.
Name of the to evaluate.
A containing the fuzzy output of the system for the
specified in .
The variable indicated was not found in the database.
Membership function used in fuzzy singletons: fuzzy sets that have just one point with membership value 1.
Sometimes it is needed to represent crisp (classical) number in the fuzzy domain. Several approaches
can be used, like adding some uncertain (fuzziness) in the original number (the number one, for instance, can be seen as a
with -0.5, 1.0 and 0.5 parameters). Another approach is to declare fuzzy singletons: fuzzy sets with only one point returning a none zero membership.
While trapezoidal and half trapezoidal are classic functions used in fuzzy functions, this class supports any function
or approximation that can be represented as a sequence of lines.
Sample usage:
// creating the instance
SingletonFunction membershipFunction = new SingletonFunction( 10 );
// getting membership for several points
for ( int i = 0; i < 20; i++ )
Console.WriteLine( membershipFunction.GetMembership( i ) );
The unique point where the membership value is 1.
The leftmost x value of the membership function, the same value of the support.
The rightmost x value of the membership function, the same value of the support.
Initializes a new instance of the class.
Support is the only value of x where the membership function is 1.
Calculate membership of a given value to the singleton function.
Value which membership will to be calculated.
Degree of membership {0,1} since singletons do not admit memberships different from 0 and 1.
NOT operator, used to calculate the complement of a fuzzy set.
The NOT operator definition is (1 - m) for all the values of membership m of the fuzzy set.
Sample usage:
// creating a fuzzy sets to represent Cool (Temperature)
TrapezoidalFunction function1 = new TrapezoidalFunction( 13, 18, 23, 28 );
FuzzySet fsCool = new FuzzySet( "Cool", function1 );
// getting membership
float m1 = fsCool.GetMembership( 15 );
// computing the membership of "NOT Cool"
NotOperator NOT = new NotOperator( );
float result = NOT.Evaluate( m1 );
// show result
Console.WriteLine( result );
Calculates the numerical result of the NOT operation applied to
a fuzzy membership value.
A fuzzy membership value, [0..1].
The numerical result of the unary operation NOT applied to .
Interface with the common methods of Fuzzy Unary Operator.
All fuzzy operators that act as a Unary Operator (NOT, VERY, LITTLE) must implement this interface.
Calculates the numerical result of a Unary operation applied to one
fuzzy membership value.
A fuzzy membership value, [0..1].
The numerical result of the operation applied to .
The class represents a fuzzy rulebase, a set of fuzzy rules used in a Fuzzy Inference System.
Initializes a new instance of the class.
Adds a fuzzy rule to the database.
A fuzzy to add to the database.
The fuzzy rule was not initialized.
The fuzzy rule name already exists in the rulebase.
Removes all the fuzzy rules of the database.
Returns an existing fuzzy rule from the rulebase.
Name of the fuzzy to retrieve.
Reference to named .
The rule indicated in ruleName was not found in the rulebase.
Gets all the rules of the rulebase.
An array with all the rulebase rules.
The class represents a fuzzy database, a set of linguistic variables used in a Fuzzy
Inference System.
Initializes a new instance of the class.
Adds a linguistic variable to the database.
A linguistic variable to add.
The linguistic variable was not initialized.
The linguistic variable name already exists in the database.
Removes all the linguistic variables of the database.
Returns an existing linguistic variable from the database.
Name of the linguistic variable to retrieve.
Reference to named .
The variable indicated was not found in the database.
Maximum CoNorm, used to calculate the linguistic value of a OR operation.
The maximum CoNorm uses a maximum operator to compute the OR
among two fuzzy memberships.
Sample usage:
// creating 2 fuzzy sets to represent Cool (Temperature) and Near (Distance)
TrapezoidalFunction function1 = new TrapezoidalFunction( 13, 18, 23, 28 );
FuzzySet fsCool = new FuzzySet( "Cool", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 23, 28, 33, 38 );
FuzzySet fsNear = new FuzzySet( "Near", function2 );
// getting memberships
float m1 = fsCool.GetMembership( 15 );
float m2 = fsNear.GetMembership( 35 );
// computing the membership of "Cool OR Near"
MaximumCoNorm OR = new MaximumCoNorm( );
float result = OR.Evaluate( m1, m2 );
// show result
Console.WriteLine( result );
Calculates the numerical result of the OR operation applied to
two fuzzy membership values.
A fuzzy membership value, [0..1].
A fuzzy membership value, [0..1].
The numerical result of the binary operation OR applied to
and .
This class represents a Fuzzy Rule, a linguistic expression representing some behavioral
aspect of a Fuzzy Inference System.
A Fuzzy Rule is a fuzzy linguistic instruction that can be executed by a fuzzy system.
The format of the Fuzzy Rule is:
IF antecedent THEN consequent
The antecedent is composed by a set of fuzzy clauses (see ) connected
by fuzzy operations, like AND or OR. The operator NOT can be used to negate expressions:
...Clause1 AND (Clause2 OR Clause3) AND NOT Clause4 ...
Fuzzy clauses are written in form Variable IS Value. The NOT operator can be used to negate linguistic values as well:
...Variable1 IS Value1 AND Variable2 IS NOT Value2 ...
The consequent is a single of fuzzy clauses (). To perform the
linguistic computing, the evaluates the clauses and then applies the fuzzy
operators. Once this is done a value representing the confidence in the antecedent being
true is obtained, and this is called firing strength of the .
The firing strength is used to discover with how much confidence the consequent
of a rule is true.
Sample usage:
// create the linguistic labels (fuzzy sets) that compose the temperature
TrapezoidalFunction function1 = new TrapezoidalFunction(
10, 15, TrapezoidalFunction.EdgeType.Right );
FuzzySet fsCold = new FuzzySet( "Cold", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 10, 15, 20, 25 );
FuzzySet fsCool = new FuzzySet( "Cool", function2 );
TrapezoidalFunction function3 = new TrapezoidalFunction( 20, 25, 30, 35 );
FuzzySet fsWarm = new FuzzySet( "Warm", function3 );
TrapezoidalFunction function4 = new TrapezoidalFunction(
30, 35, TrapezoidalFunction.EdgeType.Left );
FuzzySet fsHot = new FuzzySet( "Hot", function4 );
// create a linguistic variable to represent steel temperature
LinguisticVariable lvSteel = new LinguisticVariable( "Steel", 0, 80 );
// adding labels to the variable
lvSteel.AddLabel( fsCold );
lvSteel.AddLabel( fsCool );
lvSteel.AddLabel( fsWarm );
lvSteel.AddLabel( fsHot );
// create a linguistic variable to represent stove temperature
LinguisticVariable lvStove = new LinguisticVariable( "Stove", 0, 80 );
// adding labels to the variable
lvStove.AddLabel( fsCold );
lvStove.AddLabel( fsCool );
lvStove.AddLabel( fsWarm );
lvStove.AddLabel( fsHot );
// create the linguistic labels (fuzzy sets) that compose the pressure
TrapezoidalFunction function5 = new TrapezoidalFunction(
20, 40, TrapezoidalFunction.EdgeType.Right );
FuzzySet fsLow = new FuzzySet( "Low", function5 );
TrapezoidalFunction function6 = new TrapezoidalFunction( 20, 40, 60, 80 );
FuzzySet fsMedium = new FuzzySet( "Medium", function6 );
TrapezoidalFunction function7 = new TrapezoidalFunction(
60, 80, TrapezoidalFunction.EdgeType.Left );
FuzzySet fsHigh = new FuzzySet( "High", function7 );
// create a linguistic variable to represent pressure
LinguisticVariable lvPressure = new LinguisticVariable( "Pressure", 0, 100 );
// adding labels to the variable
lvPressure.AddLabel( fsLow );
lvPressure.AddLabel( fsMedium );
lvPressure.AddLabel( fsHigh );
// create a linguistic variable database
Database db = new Database( );
db.AddVariable( lvSteel );
db.AddVariable( lvStove );
db.AddVariable( lvPressure );
// sample rules just to test the expression parsing
Rule r1 = new Rule( db, "Test1", "IF Steel is not Cold and Stove is Hot then Pressure is Low" );
Rule r2 = new Rule( db, "Test2", "IF Steel is Cold and not (Stove is Warm or Stove is Hot) then Pressure is Medium" );
Rule r3 = new Rule( db, "Test3", "IF Steel is Cold and Stove is Warm or Stove is Hot then Pressure is High" );
// testing the firing strength
lvSteel.NumericInput = 12;
lvStove.NumericInput = 35;
float result = r1.EvaluateFiringStrength( );
Console.WriteLine( result.ToString( ) );
The name of the fuzzy rule.
The fuzzy that represents the consequent of the .
Initializes a new instance of the class.
A fuzzy containig the linguistic variables
(see ) that will be used in the Rule.
Name of this .
A string representing the . It must be a "IF..THEN" statement.
For a more detailed description see class.
A class that implements a interface to
evaluate the AND operations of the Rule.
A class that implements a interface
to evaluate the OR operations of the Rule.
Initializes a new instance of the class using as
CoNorm the and as Norm the .
A fuzzy containig the linguistic variables
(see ) that will be used in the .
Name of this .
A string representing the . It must be a "IF..THEN"
statement. For a more detailed description see class.
Converts the RPN fuzzy expression into a string representation.
String representation of the RPN fuzzy expression.
Defines the priority of the fuzzy operators.
A fuzzy operator or openning parenthesis.
A number indicating the priority of the operator, and zero for openning
parenthesis.
Converts the Fuzzy Rule to RPN (Reverse Polish Notation). For debug proposes, the string representation of the
RPN expression can be acessed by calling method.
Performs a preprocessing on the rule, placing unary operators in proper position and breaking the string
space separated tokens.
Rule in string format.
An array of strings with tokens of the rule.
Evaluates the firing strength of the Rule, the degree of confidence that the consequent of this Rule
must be executed.
The firing strength [0..1] of the Rule.
The class represents a linguistic variable.
Linguistic variables are variables that store linguistic values (labels). Fuzzy Inference Systems (FIS)
use a set of linguistic variables, called the FIS database, to execute fuzzy computation (computing with words). A linguistic
variable has a name and is composed by a set of called its linguistic labels. When declaring fuzzy
statements in a FIS, a linguistic variable can be only assigned or compared to one of its labels.
Let us consider, for example, a linguistic variable temperature. In a given application, temperature can be
cold, cool, warm or hot. Those will be the variable's linguistic labels, each one a fuzzy set with its own membership
function. Ideally, the labels will represent concepts related to the variable's meaning. Futhermore, fuzzy statements like
"temperature is warm" or "temperature is not cold" can be used to build a Fuzzy Inference Systems.
Sample usage:
// create a linguistic variable to represent temperature
LinguisticVariable lvTemperature = new LinguisticVariable( "Temperature", 0, 80 );
// create the linguistic labels (fuzzy sets) that compose the temperature
TrapezoidalFunction function1 = new TrapezoidalFunction( 10, 15, TrapezoidalFunction.EdgeType.Right );
FuzzySet fsCold = new FuzzySet( "Cold", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 10, 15, 20, 25 );
FuzzySet fsCool = new FuzzySet( "Cool", function2 );
TrapezoidalFunction function3 = new TrapezoidalFunction( 20, 25, 30, 35 );
FuzzySet fsWarm = new FuzzySet( "Warm", function3 );
TrapezoidalFunction function4 = new TrapezoidalFunction( 30, 35, TrapezoidalFunction.EdgeType.Left );
FuzzySet fsHot = new FuzzySet( "Hot" , function4 );
// adding labels to the variable
lvTemperature.AddLabel( fsCold );
lvTemperature.AddLabel( fsCool );
lvTemperature.AddLabel( fsWarm );
lvTemperature.AddLabel( fsHot );
// showing the shape of the linguistic variable - the shape of its labels memberships from start to end
Console.WriteLine( "Cold; Cool; Warm; Hot" );
for ( float x = 0; x < 80; x += 0.2 )
{
float y1 = lvTemperature.GetLabelMembership( "Cold", x );
float y2 = lvTemperature.GetLabelMembership( "Cool", x );
float y3 = lvTemperature.GetLabelMembership( "Warm", x );
float y4 = lvTemperature.GetLabelMembership( "Hot" , x );
Console.WriteLine( String.Format( "{0:N}; {1:N}; {2:N}; {3:N}", y1, y2, y3, y4 ) );
}
Numerical value of the input of this linguistic variable.
Name of the linguistic variable.
Left limit of the valid variable range.
Right limit of the valid variable range.
Initializes a new instance of the class.
Name of the linguistic variable.
Left limit of the valid variable range.
Right limit of the valid variable range.
Adds a linguistic label to the variable.
A that will be a linguistic label of the linguistic variable.
Linguistic labels are fuzzy sets (). Each
label of the variable must have a unique name. The range of the label
(left and right limits) cannot be greater than
the linguistic variable range (start/end).
The fuzzy set was not initialized.
The linguistic label name already exists in the linguistic variable.
The left limit of the fuzzy set can not be lower than the linguistic variable's starting point.
"The right limit of the fuzzy set can not be greater than the linguistic variable's ending point."
Removes all the linguistic labels of the linguistic variable.
Returns an existing label from the linguistic variable.
Name of the label to retrieve.
Reference to named label ().
The label indicated was not found in the linguistic variable.
Calculate the membership of a given value to a given label. Used to evaluate linguistics clauses like
"X IS A", where X is a value and A is a linguistic label.
Label (fuzzy set) to evaluate value's membership.
Value which label's membership will to be calculated.
Degree of membership [0..1] of the value to the label (fuzzy set).
The label indicated in labelName was not found in the linguistic variable.
The class represents a fuzzy set.
The fuzzy sets are the base for all fuzzy applications. In a classical set, the membership of
a given value to the set can always be defined as true (1) or false (0). In fuzzy sets, this membership can be
a value in the range [0..1], representing the imprecision existent in many real world applications.
Let us consider, for example, fuzzy sets representing some temperature. In a given application, there is the
need to represent a cool and warm temperature. Like in real life, the precise point when the temperature changes from
cool to warm is not easy to find, and does not makes sense. If we consider the cool around 20 degrees and warm around
30 degrees, it is not simple to find a break point. If we take the mean, we can consider values greater than or equal
25 to be warm. But we can still consider 25 a bit cool. And a bit warm at the same time. This is where fuzzy sets can
help.
Fuzzy sets are often used to compose Linguistic Variables, used in Fuzzy Inference Systems.
Sample usage:
// creating 2 fuzzy sets to represent Cool and Warm
TrapezoidalFunction function1 = new TrapezoidalFunction( 13, 18, 23, 28 );
FuzzySet fsCool = new FuzzySet( "Cool", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 23, 28, 33, 38 );
FuzzySet fsWarm = new FuzzySet( "Warm", function2 );
// show membership to the Cool set for some values
Console.WriteLine( "COOL" );
for ( int i = 13; i <= 28; i++ )
Console.WriteLine( fsCool.GetMembership( i ) );
// show membership to the Warm set for some values
Console.WriteLine( "WARM" );
for ( int i = 23; i <= 38; i++ )
Console.WriteLine( fsWarm.GetMembership( i ) );
Name of the fuzzy set.
The leftmost x value of the fuzzy set's membership function.
The rightmost x value of the fuzzy set's membership function.
Initializes a new instance of the class.
Name of the fuzzy set.
Membership function that will define the shape of the fuzzy set.
Calculate membership of a given value to the fuzzy set.
Value which membership needs to be calculated.
Degree of membership [0..1] of the value to the fuzzy set.
Interface which specifies set of methods required to be implemented by all membership
functions.
All membership functions must implement this interface, which is used by
class to calculate value's membership to a particular fuzzy set.
Calculate membership of a given value to the fuzzy set.
Value which membership will to be calculated.
Degree of membership [0..1] of the value to the fuzzy set.
The leftmost x value of the membership function.
The rightmost x value of the membership function.
Membership function composed by several connected linear functions.
The piecewise linear is a generic function used by many specific fuzzy membership
functions, like the trappezoidal function. This class must
be instantiated with a sequence of points representing the edges of each one of the lines composing the
piecewise function.
The x-axis points must be ordered (crescent), so the function will use each X value
as an ending point for one line and starting point of the next.
While trapezoidal and half trapezoidal are classic functions used in fuzzy functions, this class supports any function
or approximation that can be represented as a sequence of lines.
Sample usage:
// creating an array of points representing a typical trapezoidal function /-\
Point [] points = new Point[4];
// point where membership starts to rise
points[0] = new Point( 10, 0 );
// maximum membership (1) reached at the second point
points[1] = new Point( 20, 1 );
// membership starts to fall at the third point
points[2] = new Point( 30, 1 );
// membership gets to zero at the last point
points[3] = new Point( 40, 0 );
// creating the instance
PiecewiseLinearFunction membershipFunction = new PiecewiseLinearFunction( points );
// getting membership for several points
for ( int i = 5; i < 45; i++ )
Console.WriteLine( membershipFunction.GetMembership( i ) );
Vector of (X,Y) coordinates for end/start of each line.
The leftmost x value of the membership function, given by the first (X,Y) coordinate.
Points of the membership function are not initialized.
The rightmost x value of the membership function, given by the last (X,Y) coordinate.
Points of the membership function are not initialized.
Initializes a new instance of the class.
This constructor must be used only by inherited classes to create the
points vector after the instantiation.
Initializes a new instance of the class.
Array of (X,Y) coordinates of each start/end of the lines.
Specified point must be in crescent order on X axis and their Y value
must be in the range of [0, 1].
Points must be in crescent order on X axis.
Y value of points must be in the range of [0, 1].
Calculate membership of a given value to the piecewise function.
Value which membership will to be calculated.
Degree of membership [0..1] of the value to the fuzzy set.
Points of the membership function are not initialized.
Membership function in the shape of a trapezoid. Can be a half trapzoid if the left or the right side is missing.
Since the can represent any piece wise linear
function, it can represent trapezoids too. But as trapezoids are largely used in the creation of
Linguistic Variables, this class simplifies the creation of them.
Sample usage:
// creating a typical triangular fuzzy set /\
TrapezoidalFunction function1 = new TrapezoidalFunction( 10, 20, 30 );
// creating a right fuzzy set, the rigth side of the set is fuzzy but the left is opened
TrapezoidalFunction function2 = new TrapezoidalFunction( 10, 20, 30, TrapezoidalFunction.EdgeType.Right );
Enumeration used to create trapezoidal membership functions with half trapezoids.
If the value is Left, the trapezoid has the left edge, but right
is open (/--). If the value is Right, the trapezoid has the right edge, but left
is open (--\).
The fuzzy side of the trapezoid is at the left side.
The fuzzy side of the trapezoid is at the right side.
A private constructor used only to reuse code inside of this default constructor.
Size of points vector to create. This size depends of the shape of the
trapezoid.
Initializes a new instance of the class.
With four points the shape is known as flat fuzzy number or fuzzy interval (/--\).
X value where the degree of membership starts to raise.
X value where the degree of membership reaches the maximum value.
X value where the degree of membership starts to fall.
X value where the degree of membership reaches the minimum value.
The maximum value that the membership will reach, [0, 1].
The minimum value that the membership will reach, [0, 1].
Initializes a new instance of the class.
With four points the shape is known as flat fuzzy number or fuzzy interval (/--\).
X value where the degree of membership starts to raise.
X value where the degree of membership reaches the maximum value.
X value where the degree of membership starts to fall.
X value where the degree of membership reaches the minimum value.
Maximum membership value is set to 1.0 and the minimum is set to 0.0.
Initializes a new instance of the class.
With three points the shape is known as triangular fuzzy number or just fuzzy number (/\).
X value where the degree of membership starts to raise.
X value where the degree of membership reaches the maximum value and starts to fall.
X value where the degree of membership reaches the minimum value.
The maximum value that the membership will reach, [0, 1].
The minimum value that the membership will reach, [0, 1].
Initializes a new instance of the class.
With three points the shape is known as triangular fuzzy number or just fuzzy number (/\).
X value where the degree of membership starts to raise.
X value where the degree of membership reaches the maximum value and starts to fall.
X value where the degree of membership reaches the minimum value.
Maximum membership value is set to 1.0 and the minimum is set to 0.0.
Initializes a new instance of the class.
With two points and an edge this shape can be a left fuzzy number (/) or a right fuzzy number (\).
Edge = Left: X value where the degree of membership starts to raise.
Edge = Right: X value where the function starts, with maximum degree of membership.
Edge = Left: X value where the degree of membership reaches the maximum.
Edge = Right: X value where the degree of membership reaches minimum value.
The maximum value that the membership will reach, [0, 1].
The minimum value that the membership will reach, [0, 1].
Trapezoid's .
Initializes a new instance of the class.
With three points and an edge this shape can be a left fuzzy number (/--) or a right fuzzy number (--\).
Edge = Left: X value where the degree of membership starts to raise.
Edge = Right: X value where the function starts, with maximum degree of membership.
Edge = Left: X value where the degree of membership reaches the maximum.
Edge = Right: X value where the degree of membership reaches minimum value.
Trapezoid's .
Maximum membership value is set to 1.0 and the minimum is set to 0.0.
Product Norm, used to calculate the linguistic value of a AND operation.
The product Norm uses a multiplication operator to compute the
AND among two fuzzy memberships.
Sample usage:
// creating 2 fuzzy sets to represent Cool (Temperature) and Near (Distance)
TrapezoidalFunction function1 = new TrapezoidalFunction( 13, 18, 23, 28 );
FuzzySet fsCool = new FuzzySet( "Cool", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 23, 28, 33, 38 );
FuzzySet fsNear = new FuzzySet( "Near", function2 );
// getting memberships
float m1 = fsCool.GetMembership( 15 );
float m2 = fsNear.GetMembership( 35 );
// computing the membership of "Cool AND Near"
ProductNorm AND = new ProductNorm( );
float result = AND.Evaluate( m1, m2 );
// show result
Console.WriteLine( result );
Calculates the numerical result of the AND operation applied to
two fuzzy membership values using the product rule.
A fuzzy membership value, [0..1].
A fuzzy membership value, [0..1].
The numerical result of the AND operation applied to
and .
Interface with the common methods of a Fuzzy CoNorm.
All fuzzy operators that act as a CoNorm must implement this interface.
Calculates the numerical result of a CoNorm (OR) operation applied to
two fuzzy membership values.
A fuzzy membership value, [0..1].
A fuzzy membership value, [0..1].
The numerical result the operation OR applied to
and .
Interface with the common methods of a Fuzzy Norm.
All fuzzy operators that act as a Norm must implement this interface.
Calculates the numerical result of a Norm (AND) operation applied to
two fuzzy membership values.
A fuzzy membership value, [0..1].
A fuzzy membership value, [0..1].
The numerical result the operation AND applied to
and .
Minimum Norm, used to calculate the linguistic value of a AND operation.
The minimum Norm uses a minimum operator to compute the AND
among two fuzzy memberships.
Sample usage:
// creating 2 fuzzy sets to represent Cool (Temperature) and Near (Distance)
TrapezoidalFunction function1 = new TrapezoidalFunction( 13, 18, 23, 28 );
FuzzySet fsCool = new FuzzySet( "Cool", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 23, 28, 33, 38 );
FuzzySet fsNear = new FuzzySet( "Near", function2 );
// getting memberships
float m1 = fsCool.GetMembership( 15 );
float m2 = fsNear.GetMembership( 35 );
// computing the membership of "Cool AND Near"
MinimumNorm AND = new MinimumNorm( );
float result = AND.Evaluate( m1, m2 );
// show result
Console.WriteLine( result );
Calculates the numerical result of the AND operation applied to
two fuzzy membership values using the minimum rule.
A fuzzy membership value, [0..1].
A fuzzy membership value, [0..1].
The numerical result of the AND operation applied to
and .