Class: FuzzyLogic

FuzzyLogic

The Fuzzy Logic engine

new FuzzyLogic(algorithm, crispAlgorithm)

/mnt/WORK/RxLab/src/RxOT/DuFuzzyLogic/src/JavaScript/FuzzyLogic.js, line 981
Creates a new Fuzzy Logic Engine.
Name Type Default Description
algorithm FuzzyLogicAlgorithm FuzzyLogicAlgorithm.LINEAR optional The algorithm to use for logic operations
crispAlgorithm FuzzyCrispAlgorithm FuzzyCrispAlgorithm.CENTROID optional The algorithm to use for crispification
Version:
  • 1.0.0
Author:
  • Nicolas Dufresne
License:
  • GPL-3.0

Methods

IF(fzVeracity){FuzzyVeracity}

/mnt/WORK/RxLab/src/RxOT/DuFuzzyLogic/src/JavaScript/FuzzyLogic.js, line 1050
This function internally stores the veracity to be used with FuzzyLogic.THEN.
Name Type Description
fzVeracity FuzzyVeracity optional The veracity of the statement.
Returns:
Type Description
FuzzyVeracity The value passed as argument.
Example
var logic = new FuzzyLogic();
var comfortable = logic.newSet("Warm", 17, 20);
var temperature = logic.newValue( 18 );
// Test if this temperature is comfortable
logic.IF(
   temperature.IS_NOT(comfortable)
)
// Set it very comfortable
logic.THEN( temperature, comfortable, "Very" );

newSet(name, shapeIn, shapeOut, plateauMin, plateauMax){FuzzySet}

/mnt/WORK/RxLab/src/RxOT/DuFuzzyLogic/src/JavaScript/FuzzyLogic.js, line 1030
Creates a new FuzzySet.
Name Type Default Description
name string The unique name of this set (e.g. "hot", "fast", "red", "flower addict"...). It must be unique!
shapeIn FuzzyShape FuzzyShape.LINEAR optional The shape (i.e. interpolation or transition) when getting in the set.
shapeOut FuzzyShape shapeIn optional The shape (i.e. interpolation or transition) when getting out of the set. By default, same as shape.
plateauMin Number optional The value above which it is considered completely included. By default, it is at the middle between min and max.
plateauMax Number optional The value under which it is considered completely included. By default, it is at the middle between min and max.
Properties:
Name Type Description
extremeValue Number One of the closest value which is not in the set (either above or below).
referenceValue Number The value which best fits in the set, the most extreme/maximum in the set.
Returns:
Type Description
FuzzySet The set.
Example
var logic = new FuzzyLogic();
// Temperatures between 15 and 25 will be considered comfortable, 20 being the most comfortable
var comfortable = logic.newSet("Warm", 15, 20);
// Temperatures under 17 are cold, and temperatures under 0 are the most cold (because of the constant shape below)
var cold = logic.newSet("Cold", 17, 0, FuzzyShape.CONSTANT);
// Temperatures above 23 are hot, and all temperatures above 35 are the most hot (because of the constant shape above)
var hot = logic.newSet("Hot", 23, 35, FuzzyShape.GAUSSIAN, FuzzyShape.CONSTANT);

newValue(value, unit){FuzzyValue}

/mnt/WORK/RxLab/src/RxOT/DuFuzzyLogic/src/JavaScript/FuzzyLogic.js, line 996
Creates a new FuzzyValue
Name Type Description
value Number optional The initial crisp value.
unit string optional The unit to display when returning this value as a string.
Returns:
Type Description
FuzzyValue The value.

newVeracity(veracity){FuzzyVeracity}

/mnt/WORK/RxLab/src/RxOT/DuFuzzyLogic/src/JavaScript/FuzzyLogic.js, line 1006
Creates a new FuzzyVeracity
Name Type Description
veracity Number The initial veracity, in the range [0.0, 1.0].
Returns:
Type Description
FuzzyVeracity The veracity.

THEN(value, set, quantifier)

/mnt/WORK/RxLab/src/RxOT/DuFuzzyLogic/src/JavaScript/FuzzyLogic.js, line 1077
This function sets a value in a new set, using the veracity resulting from the previous call to FuzzyLogic.IS.
It can be called several times after any call to IF.
Name Type Description
value FuzzyValue optional The value to set.
set FuzzySet optional The set the value has to be included in.
quantifier FuzzyQuantifier optional A quantifier to apply for setting the value.
Example
var logic = new FuzzyLogic();
var comfortable = logic.newSet("Warm", 17, 20);
var power = logic.newSet("Fan power", 0, 100);
var temperature = logic.newValue( 18 );
var fanPower = logic.newValue();
// Test if this temperature is comfortable
logic.IF(
   temperature.IS_NOT(comfortable);
)
// Set it very comfortable
logic.THEN ( temperature.SET(comfortable, "Very"); )
// and turn on the fan
logic.THEN ( fanPower.SET( power ); )