Click or drag to resize
Accord.NET (logo)

InferenceSystem Class

This class represents a Fuzzy Inference System.
Inheritance Hierarchy
SystemObject
  Accord.FuzzyInferenceSystem

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

The InferenceSystem type exposes the following members.

Constructors
  NameDescription
Public methodInferenceSystem(Database, IDefuzzifier)
Initializes a new Fuzzy InferenceSystem.
Public methodInferenceSystem(Database, IDefuzzifier, INorm, ICoNorm)
Initializes a new Fuzzy InferenceSystem.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodEvaluate
Executes the fuzzy inference, obtaining a numerical output for a choosen output linguistic variable.
Public methodExecuteInference
Executes the fuzzy inference, obtaining the FuzzyOutput of the system for the required LinguisticVariable.
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 methodGetLinguisticVariable
Gets one of the LinguisticVariable of the Database.
Public methodGetRule
Gets one of the Rules of the Rulebase.
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 methodNewRule
Creates a new Rule and add it to the Rulebase of the InferenceSystem.
Public methodSetInput
Sets a numerical input for one of the linguistic variables of the Database.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
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.)
Top
Remarks

A Fuzzy Inference System is a model capable of executing fuzzy computing. It is mainly composed by a Database with the linguistic variables (see LinguisticVariable) and a Rulebase with the fuzzy rules (see Rule) that represent the behavior of the system. The typical operation of a Fuzzy Inference System is:

  • Get the numeric inputs;
  • Use the Database with the linguistic variables (see LinguisticVariable) to obtain linguistic meaning for each numerical input;
  • Verify which rules (see Rule) of the Rulebase are activated by the input;
  • Combine the consequent of the activated rules to obtain a FuzzyOutput;
  • Use some defuzzifier (see IDefuzzifier) 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 )
{
...
}
See Also