Engine
Engine
¶
Core class of the library that groups the necessary components of a fuzzy logic controller.
Attributes¶
input_values
property
writable
¶
input_values: ScalarArray
Get/Set 2D array where columns represent input variables and rows their input values.
Getter¶
Returns:
Type | Description |
---|---|
ScalarArray
|
2D array of input values (rows) for each input variable (columns) |
Setter¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
ScalarArray
|
input values of the engine. |
required |
Tip
when values is a: |
the result: |
---|---|
single scalar value | sets the values of all input variables |
1D array on an engine with a single variable | sets the values for the input variable |
1D array on an engine with multiple variables | sets each value to each input variable |
2D array | sets each column of values to each input variable |
Raises:
Type | Description |
---|---|
RuntimeError
|
when there are no input variables |
ValueError
|
when the dimensionality of values is greater than 2 |
ValueError
|
when the number of columns in the values is different from the number of input variables |
output_values
property
¶
output_values: ScalarArray
Return a 2D array of output values (rows) for each output variable (columns).
Returns:
Type | Description |
---|---|
ScalarArray
|
2D array of output values (rows) for each output variable (columns). |
values
property
¶
values: ScalarArray
Return a 2D array of current input and output values.
Returns:
Type | Description |
---|---|
ScalarArray
|
2D array of current input and output values. |
variables
property
¶
variables: list[InputVariable | OutputVariable]
Return the list of input and output variables.
Returns:
Type | Description |
---|---|
list[InputVariable | OutputVariable]
|
list of input and output variables. |
Classes¶
Functions¶
__getitem__
¶
__getitem__(item: str) -> InputVariable | OutputVariable | RuleBlock
Allow operation of engines as engine["power"].value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
str
|
name of the component to find in input variables, output variables, or rule blocks |
required |
Returns:
Type | Description |
---|---|
InputVariable | OutputVariable | RuleBlock
|
first component found with the name |
__init__
¶
__init__(
name: str = "",
description: str = "",
input_variables: Iterable[InputVariable] | None = None,
output_variables: Iterable[OutputVariable] | None = None,
rule_blocks: Iterable[RuleBlock] | None = None,
load: bool = True,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the engine |
''
|
description |
str
|
description of the engine |
''
|
input_variables |
Iterable[InputVariable] | None
|
list of input variables |
None
|
output_variables |
Iterable[OutputVariable] | None
|
list of output variables |
None
|
rule_blocks |
Iterable[RuleBlock] | None
|
list of rule blocks |
None
|
load |
bool
|
whether to automatically update references to this engine and load the rules in the rule blocks. |
True
|
__repr__
¶
__repr__() -> str
Return the code to construct the engine in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the engine in Python. |
__str__
¶
__str__() -> str
Return the code to construct the engine in the FuzzyLite Language.
Returns:
Type | Description |
---|---|
str
|
code to construct the engine in the FuzzyLite Language. |
configure
¶
configure(
conjunction: TNorm | str | None = None,
disjunction: SNorm | str | None = None,
implication: TNorm | str | None = None,
aggregation: SNorm | str | None = None,
defuzzifier: Defuzzifier | str | None = None,
activation: Activation | str | None = None,
) -> None
Configure the engine with the given operators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conjunction |
TNorm | str | None
|
object or name of TNorm registered in the TNormFactory |
None
|
disjunction |
SNorm | str | None
|
object or name of SNorm registered in the SNormFactory |
None
|
implication |
TNorm | str | None
|
object or name of TNorm registered in the TNormFactory |
None
|
aggregation |
SNorm | str | None
|
object or name of SNorm registered in the SNormFactory |
None
|
defuzzifier |
Defuzzifier | str | None
|
object or name of defuzzifier registered in the DefuzzifierFactory |
None
|
activation |
Activation | str | None
|
object or name of activation method registered in the ActivationFactory |
None
|
infer_type
¶
input_variable
¶
input_variable(name_or_index: str | int) -> InputVariable
Find the input variable by the name or index.
The best performance is \(O(1)\) when using indices, and the worst performance is \(O(n)\) when using names, where \(n\) is the number of input variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_or_index |
str | int
|
name or index of the input variable |
required |
Returns:
Type | Description |
---|---|
InputVariable
|
input variable by the name or index |
Raises:
Type | Description |
---|---|
ValueError
|
when there is no variable by the given name. |
IndexError
|
when the index is out of range |
is_ready
¶
Determine whether the engine is configured correctly and ready for operation.
Note
In advanced engines, the result of this method should be taken as a suggestion and not as a prerequisite to operate the engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
errors |
list[str] | None
|
optional output list that stores the errors found if the engine is not ready |
None
|
Returns:
Type | Description |
---|---|
bool
|
whether the engine is ready. |
output_variable
¶
output_variable(name_or_index: str | int) -> OutputVariable
Find the output variable of the given name or at the given index.
The best performance is \(O(1)\) when using indices, and the worst performance is \(O(n)\) when using names, where \(n\) is the number of output variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_or_index |
str | int
|
name or index of the output variable |
required |
Returns:
Type | Description |
---|---|
OutputVariable
|
output variable by the given name or at the given index |
Raises:
Type | Description |
---|---|
ValueError
|
when there is no variable with the given name. |
IndexError
|
when the index is out of range |
process
¶
Process the engine in its current state as follows.
- clear the aggregated fuzzy output variables,
- activate the rule blocks, and
- defuzzify the output variables
restart
¶
Restart the engine as follows.
- setting the values of the input variables to nan,
- reloading the rules of the rule blocks, and
- clearing the output variables
rule_block
¶
Find the rule block of the given name or at the given index.
The best performance is \(O(1)\) when using indices, and the worst performance is \(O(n)\) when using names, where \(n\) is the number of rule blocks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_or_index |
str | int
|
name or index of the rule block |
required |
Returns:
Type | Description |
---|---|
RuleBlock
|
rule block by the given name or at the given index |
Raises:
Type | Description |
---|---|
ValueError
|
when there is no variable with the given name. |
IndexError
|
when the index is out of range |
variable
¶
Find the variable by the name, iterating first over the input variables and then over the output variables.
The cost of this method is \(O(n)\), where \(n\) is the number of variables in the engine. For better performance, get the variables by index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the input or output variable |
required |
Returns:
Type | Description |
---|---|
Variable
|
variable of the given name |
Raises:
Type | Description |
---|---|
ValueError
|
when there is no variable by the given name. |