Exporter
Exporter
¶
FldExporter
¶
Bases: Exporter
Export the input values and output values of an engine to the FuzzyLite Dataset (FLD) format.
related
warning
FldExporter uses vectorization so it only works with the fuzzylite.activation.General activation method
todo
include option for non-vectorized export so other activation methods can be used
Attributes¶
Classes¶
ScopeOfValues
¶
Bases: Enum
Scope of the equally-distributed values to generate.
EachVariable
: Generates \(v\) values for each variable, resulting in a total resolution of \(-1 + \max(1, v^{\frac{1}{|I|})\) from all combinations, where \(I\) refers to the input variables.AllVariables
: Generates values for each variable such that the total resolution is \(v\).
Functions¶
__init__
¶
header
¶
to_file_from_reader
¶
Write the FuzzyLite Dataset to the file using the input values from the engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
path to the output file |
required |
engine
|
Engine
|
engine to export |
required |
reader
|
IO[str]
|
reader of a set of lines containing space-separated input values |
required |
skip_lines
|
int
|
number of lines to skip from the beginning. |
0
|
Returns:
Type | Description |
---|---|
None
|
FuzzyLite Dataset from the engine. |
to_file_from_scope
¶
to_file_from_scope(
path: Path,
engine: Engine,
values: int = 1024,
scope: ScopeOfValues = AllVariables,
active_variables: set[InputVariable] | None = None,
) -> None
Write the FuzzyLite Dataset from the engine to the file using the input values and their scope.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
file path |
required |
engine
|
Engine
|
engine to export |
required |
values
|
int
|
number of values to export |
1024
|
scope
|
ScopeOfValues
|
scope of the values |
AllVariables
|
active_variables
|
set[InputVariable] | None
|
set of input variables to set values for |
None
|
to_string
¶
Return a FuzzyLite Dataset from the engine using 1024 input values for all variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance
|
object
|
engine to export |
required |
Returns:
Type | Description |
---|---|
str
|
FuzzyLite Dataset from the engine |
Raises:
Type | Description |
---|---|
ValueError
|
if the instance is not an Engine. |
to_string_from_reader
¶
Return a FuzzyLite Dataset from the engine using the input values from the reader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
Engine
|
engine to export |
required |
reader
|
IO[str]
|
reader of a set of lines containing space-separated input values |
required |
skip_lines
|
int
|
number of lines to skip from the beginning |
0
|
Returns:
Type | Description |
---|---|
str
|
FuzzyLite Dataset from the engine. |
to_string_from_scope
¶
to_string_from_scope(
engine: Engine,
values: int = 1024,
scope: ScopeOfValues = AllVariables,
active_variables: set[InputVariable] | None = None,
) -> str
Return a FuzzyLite Dataset from the engine using the input values and their scope.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
Engine
|
engine to export |
required |
values
|
int
|
number of values to export |
1024
|
scope
|
ScopeOfValues
|
scope of the values |
AllVariables
|
active_variables
|
set[InputVariable] | None
|
input variables to set values for |
None
|
Returns:
Type | Description |
---|---|
str
|
FuzzyLite Dataset from the engine. |
write
¶
write_from_reader
¶
Write the FuzzyLite Dataset from the engine to the writer using the input values from the reader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
Engine
|
engine to export |
required |
writer
|
IO[str]
|
output to write the engine |
required |
reader
|
IO[str]
|
reader of a set of lines containing space-separated input values |
required |
skip_lines
|
int
|
number of lines to skip from the beginning. |
0
|
write_from_scope
¶
write_from_scope(
engine: Engine,
writer: IO[str],
values: int,
scope: ScopeOfValues,
active_variables: set[InputVariable] | None = None,
) -> None
Write a FuzzyLite dataset from the engine to the writer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
Engine
|
engine to export |
required |
writer
|
IO[str]
|
output to write the engine |
required |
values
|
int
|
number of values to export |
required |
scope
|
ScopeOfValues
|
scope of the values |
required |
active_variables
|
set[InputVariable] | None
|
input variables to generate values for. |
None
|
FllExporter
¶
Bases: Exporter
Export an engine and its components to the FuzzyLite Language.
Attributes¶
Functions¶
__init__
¶
activation
¶
activation(activation: Activation | None) -> str
Return the activation method in the FuzzyLite Language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activation
|
Activation | None
|
activation method to export |
required |
Returns:
Type | Description |
---|---|
str
|
activation method in the FuzzyLite Language |
defuzzifier
¶
defuzzifier(defuzzifier: Defuzzifier | None) -> str
Return the defuzzifier in the FuzzyLite Language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
defuzzifier
|
Defuzzifier | None
|
defuzzifier to export |
required |
Returns:
Type | Description |
---|---|
str
|
defuzzifier in the FuzzyLite Language |
engine
¶
format
¶
Format the arguments according to the FuzzyLite Language.
formatting table
value | formatted |
---|---|
None |
none |
bool |
true , false |
float |
0.999 using fuzzylite.library.Settings.decimals |
list|set|tuple |
space-separated values, each formatted with this method |
object | anything else uses the object's __str__() method |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str | None
|
name of the property |
required |
value
|
Any
|
value to format |
required |
Returns:
Type | Description |
---|---|
str
|
formatted (key and) value according to the FuzzyLite Language |
input_variable
¶
input_variable(variable: InputVariable) -> str
Return the input variable in the FuzzyLite Language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable
|
InputVariable
|
input variable to export |
required |
Returns: input variable in the FuzzyLite Language
norm
¶
output_variable
¶
output_variable(variable: OutputVariable) -> str
Return the output variable in the FuzzyLite Language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable
|
OutputVariable
|
output variable to export |
required |
Returns:
Type | Description |
---|---|
str
|
output variable in the FuzzyLite Language |
rule
¶
rule_block
¶
term
¶
to_string
¶
variable
¶
PythonExporter
¶
Bases: Exporter
Export an engine and its components to Python.
related
Attributes¶
Functions¶
__init__
¶
activation
¶
activation(activation: Activation | None) -> str
Return the code to construct the activation method in Python.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activation
|
Activation | None
|
activation method to export |
required |
Returns:
Type | Description |
---|---|
str
|
code to construct the activation method in Python |
defuzzifier
¶
defuzzifier(defuzzifier: Defuzzifier | None) -> str
Return the code to construct the defuzzifier in Python.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
defuzzifier
|
Defuzzifier | None
|
defuzzifier to export |
required |
Returns:
Type | Description |
---|---|
str
|
code to construct the defuzzifier in Python |
encapsulate
¶
Encapsulate the instance in a new class if it is an engine, or in a create method otherwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance
|
Any
|
object to encapsulate |
required |
Returns:
Type | Description |
---|---|
str
|
if the instance is an engine, then the class constructing the engine during initialization; |
str
|
otherwise a method constructing the object |
engine
¶
format
¶
Format the code using the black
formatter if it is installed, otherwise no effects on the code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
str
|
code to format. |
required |
**kwargs
|
Any
|
keyword arguments to pass to |
{}
|
Returns:
code formatted if black
is installed, otherwise the code without format
input_variable
¶
input_variable(input_variable: InputVariable) -> str
Return the code to construct the input variable in Python.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_variable
|
InputVariable
|
input variable to export |
required |
Returns:
Type | Description |
---|---|
str
|
code to construct the input variable in Python |
norm
¶
output_variable
¶
output_variable(output_variable: OutputVariable) -> str
Return the code to construct the output variable in Python.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_variable
|
OutputVariable
|
output variable to export |
required |
Returns:
Type | Description |
---|---|
str
|
code to construct the output variable in Python |