Skip to content

FldExporter

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

headers instance-attribute

headers = headers

input_values instance-attribute

input_values = input_values

output_values instance-attribute

output_values = output_values

separator instance-attribute

separator = separator

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\).
Attributes
AllVariables class-attribute instance-attribute
AllVariables = auto()
EachVariable class-attribute instance-attribute
EachVariable = auto()

Functions

__init__

__init__(separator: str = ' ', headers: bool = True, input_values: bool = True, output_values: bool = True) -> None

Constructor.

Parameters:

Name Type Description Default
separator str

separator of the dataset columns

' '
headers bool

whether to export the header of the dataset

True
input_values bool

whether to export the input values

True
output_values bool

whether to export the output values.

True

header

header(engine: Engine) -> str

Return the header of the dataset for the engine.

Parameters:

Name Type Description Default
engine Engine

engine to export

required

Returns:

Type Description
str

header of the dataset for the engine.

to_file_from_reader

to_file_from_reader(path: Path, engine: Engine, reader: IO[str], skip_lines: int = 0) -> None

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 = 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

to_string(instance: object) -> str

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

to_string_from_reader(engine: Engine, reader: IO[str], skip_lines: int = 0) -> str

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 = 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(engine: Engine, writer: IO[str], input_values: Scalar) -> None

Write a FuzzyLite Dataset line from the engine to the writer using the input values.

Parameters:

Name Type Description Default
engine Engine

engine to export

required
writer IO[str]

output where the engine will be written to

required
input_values Scalar

matrix of input values.

required

write_from_reader

write_from_reader(engine: Engine, writer: IO[str], reader: IO[str], skip_lines: int = 0) -> None

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