Skip to content

Factory

ActivationFactory

Bases: ConstructionFactory[Activation]

Construction factory of activation methods for rule blocks.

related

Functions

__init__

__init__() -> None

Constructor.

CloningFactory

Bases: Generic[T]

Base class for a factory whose objects are created by a deep copy of registered instances.

related

Attributes

objects instance-attribute

objects = objects or {}

Functions

__getitem__

__getitem__(key: str) -> T

Return the object by the key.

Returns:

Type Description
T

object by the key.

Raises: KeyError: when the key is not in the factory

__init__

__init__(objects: dict[str, T] | None = None) -> None

Constructor.

__iter__

__iter__() -> Iterator[str]

Return the iterator of the factory.

Returns:

Type Description
Iterator[str]

iterator of the factory.

__len__

__len__() -> int

Return the number of objects in the factory.

Returns:

Type Description
int

number of objects in the factory.

__repr__

__repr__() -> str

Return the Python code to construct the factory.

Returns:

Type Description
str

Python code to construct the factory.

__setitem__

__setitem__(key: str, value: T) -> None

Set the value for the key.

Parameters:

Name Type Description Default
key str

name of the object

required
value T

instance to be deep copied

required

__str__

__str__() -> str

Return the class name of the factory.

Returns:

Type Description
str

class name of the factory.

copy

copy(key: str) -> T

Create a deep copy of the object registered by the key.

Parameters:

Name Type Description Default
key str

name of the object

required

Returns:

Type Description
T

deep copy of the object registered by the key

Raises:

Type Description
ValueError

when the key is not registered.

ConstructionFactory

Bases: Generic[T]

Base class for a factory whose objects are created from a registered constructor.

related

Attributes

constructors instance-attribute

constructors = constructors or {}

Functions

__getitem__

__getitem__(key: str) -> type[T]

Return the type by the key.

Returns:

Type Description
type[T]

type by the key.

Raises:

Type Description
KeyError

when the key is not in the constructors

__init__

__init__(constructors: dict[str, type[T]] | None = None) -> None

Constructor.

Parameters:

Name Type Description Default
constructors dict[str, type[T]] | None

dictionary of constructors

None

__iter__

__iter__() -> Iterator[str]

Return the iterator of the factory.

Returns:

Type Description
Iterator[str]

iterator of the factory.

__len__

__len__() -> int

Return the number of constructors in the factory.

Returns:

Type Description
int

number of constructors in the factory.

__repr__

__repr__() -> str

Return the Python code to construct the factory.

Returns:

Type Description
str

Python code to construct the factory.

__setitem__

__setitem__(key: str, value: type[T]) -> None

Set the value for the key.

Parameters:

Name Type Description Default
key str

name of the constructor

required
value type[T]

type of the constructor

required

__str__

__str__() -> str

Return the class name of the factory.

Returns:

Type Description
str

class name of the factory.

construct

construct(key: str, **kwargs: Any) -> T

Create an object from the constructor registered by the key.

Parameters:

Name Type Description Default
key str

name of the constructor

required
**kwargs Any

parameters to pass to the constructor

{}

Returns:

Type Description
T

object created from the constructor registered by the key

Raises:

Type Description
ValueError

when the key is not registered

import_from

import_from(module: ModuleType, cls: type[T]) -> list[type[T]]

Import constructors from the module.

Parameters:

Name Type Description Default
module ModuleType

module to import constructors

required
cls type[T]

class of constructors to import

required

Returns:

Type Description
list[type[T]]

list of constructors imported from the module.

DefuzzifierFactory

Bases: ConstructionFactory[Defuzzifier]

Factory of defuzzifiers.

related

Functions

__init__

__init__() -> None

Constructor.

FactoryManager

Manager that groups different factories to facilitate access across the library.

related

Attributes

activation instance-attribute

activation = activation or ActivationFactory()

defuzzifier instance-attribute

defuzzifier = defuzzifier or DefuzzifierFactory()

function instance-attribute

function = function or FunctionFactory()

hedge instance-attribute

hedge = hedge or HedgeFactory()

snorm instance-attribute

snorm = snorm or SNormFactory()

term instance-attribute

term = term or TermFactory()

tnorm instance-attribute

tnorm = tnorm or TNormFactory()

Functions

__init__

__init__(
    tnorm: TNormFactory | None = None,
    snorm: SNormFactory | None = None,
    activation: ActivationFactory | None = None,
    defuzzifier: DefuzzifierFactory | None = None,
    term: TermFactory | None = None,
    hedge: HedgeFactory | None = None,
    function: FunctionFactory | None = None,
) -> None

Constructor.

Parameters:

Name Type Description Default
tnorm TNormFactory | None

factory of TNorms

None
snorm SNormFactory | None

factory of SNorms

None
activation ActivationFactory | None

factory of activation methods

None
defuzzifier DefuzzifierFactory | None

factory of defuzzifiers

None
term TermFactory | None

factory of terms

None
hedge HedgeFactory | None

factory of hedges

None
function FunctionFactory | None

factory of functions

None

FunctionFactory

Bases: CloningFactory[Element]

Factory of operators and functions used by the Function term.

related

Functions

__init__

__init__() -> None

Constructor.

_create_functions

_create_functions() -> list[Element]

Return the list of functions.

Returns:

Type Description
list[Element]

list of functions

_create_operators

_create_operators() -> list[Element]

Return the list of function operators.

Returns:

Type Description
list[Element]

list of function operators

_precedence

_precedence(importance: int) -> int

Inverts the priority of precedence of operations, mapping 0-10 in ascending order to 100-0 in descending order.

Parameters:

Name Type Description Default
importance int

value between 0 and 10, where 0 is the most important

required

Returns:

Type Description
int

precedence between 100 and 0, where 100 is the most important

functions

functions() -> dict[str, Element]

Return a dictionary of the functions available.

Returns:

Type Description
dict[str, Element]

dictionary of the functions available.

operators

operators() -> dict[str, Element]

Return a dictionary of the operators available.

Returns:

Type Description
dict[str, Element]

dictionary of the operators available.

HedgeFactory

Bases: ConstructionFactory[Hedge]

Factory of hedges.

related

Functions

__init__

__init__() -> None

Constructor.

SNormFactory

Bases: ConstructionFactory[SNorm]

Factory of SNorms.

related

Functions

__init__

__init__() -> None

Constructor.

TNormFactory

Bases: ConstructionFactory[TNorm]

Factory of TNorms.

related

Functions

__init__

__init__() -> None

Constructor.

TermFactory

Bases: ConstructionFactory[Term]

Factory of terms.

related

Functions

__init__

__init__() -> None

Constructor.