Click or drag to resize
Accord.NET (logo)

LinguisticVariable Class

The class represents a linguistic variable.
Inheritance Hierarchy

Namespace:  Accord.Fuzzy
Assembly:  Accord.Fuzzy (in Accord.Fuzzy.dll) Version: 3.8.0
public class LinguisticVariable
Request Example View Source

The LinguisticVariable type exposes the following members.

Public methodLinguisticVariable
Initializes a new instance of the LinguisticVariable class.
Public propertyEnd
Right limit of the valid variable range.
Public propertyName
Name of the linguistic variable.
Public propertyNumericInput
Numerical value of the input of this linguistic variable.
Public propertyStart
Left limit of the valid variable range.
Public methodAddLabel
Adds a linguistic label to the variable.
Public methodClearLabels
Removes all the linguistic labels of the linguistic variable.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetLabel
Returns an existing label from the linguistic variable.
Public methodGetLabelMembership
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.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Extension Methods
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)

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 FuzzySet 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 ) );
See Also