FuzzyLogic(algorithmopt, crispAlgorithmopt)

The Fuzzy Logic engine

new FuzzyLogic(algorithmopt, crispAlgorithmopt)

Creates a new Fuzzy Logic Engine.
Parameters:
Name Type Attributes Default Description
algorithm FuzzyLogicAlgorithm <optional>
FuzzyLogicAlgorithm.LINEAR The algorithm to use for logic operations
crispAlgorithm FuzzyCrispAlgorithm <optional>
FuzzyCrispAlgorithm.CENTROID The algorithm to use for crispification
Version:
  • 1.0.0
Author:
  • Nicolas Dufresne
License:
  • GPL-3.0

Methods

IF(fzVeracityopt) → {FuzzyVeracity}

This function internally stores the veracity to be used with FuzzyLogic.THEN.
Parameters:
Name Type Attributes Description
fzVeracity FuzzyVeracity <optional>
The veracity of the statement.
Returns:
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.SET(comfortable, "Very"); )

newSet(name, shapeBelowopt, shapeAboveopt, plateauMinopt, plateauMaxopt) → {FuzzySet}

Creates a new FuzzySet.
Parameters:
Name Type Attributes Default Description
name string The unique name of this set (e.g. "hot", "fast", "red", "flower addict"...). It must be unique!
shapeBelow FuzzyShape <optional>
FuzzyShape.LINEAR The shape (i.e. interpolation or transition) when getting in the set.
shapeAbove FuzzyShape <optional>
shape 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.
Returns:
FuzzySet - The set.
Properties:
Name Type Description
valueNOT Number One of the closest value which is not in the set (either above or below).
valueIS Number The value which best fits in the set, the most extreme/maximum in the set.
Example
var logic = new FuzzyLogic();
// Temperatures between 15 and 25 will be considered comfortable, 20 being the most comfortable
var comfortabble = 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(valueopt, unitopt) → {FuzzyValue}

Creates a new FuzzyValue
Parameters:
Name Type Attributes Description
value Number <optional>
The initial crisp value.
unit string <optional>
The unit to display when returning this value as a string.
Returns:
FuzzyValue - The value.

newVeracity(veracity) → {FuzzyVeracity}

Creates a new FuzzyVeracity
Parameters:
Name Type Description
veracity Number The initial veracity, in the range [0.0, 1.0].
Returns:
FuzzyVeracity - The veracity.

THEN(valueopt, setopt, quantifieropt)

This function sets a value in a new set, using the veracity resulting from the previous call to FuzzyLogic.IS.
Parameters:
Name Type Attributes 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 ); )