Skip to content

Term

Activated

Bases: Term

Special term that represents the activation of terms when processing the antecedent of a rule.

Equation

\(\mu(x) = \alpha_a \otimes \mu_a(x)\)

where

  • \(\alpha_a\): activation degree of term \(a\)
  • \(\otimes\): implication operator
  • \(\mu_a\): activated term \(a\)
related

Attributes

degree property writable

degree: Scalar

Get/Set the activation degree of the term.

Getter

Returns:

Type Description
Scalar

activation degree of the term.

Setter

Parameters:

Name Type Description Default
value Scalar

activation degree of the term, with replacements of {nan: 0.0, -inf: 0.0, inf: 1.0}

required
Note

replacements of {nan: 0.0, -inf: 0.0, inf: 1.0} are made to sensibly deal with non-finite activations (eg, NaN input values)

implication instance-attribute

implication = implication

term instance-attribute

term = term

Functions

__init__

__init__(term: Term, degree: Scalar = 1.0, implication: TNorm | None = None) -> None

Constructor.

Parameters:

Name Type Description Default
term Term

activated term

required
degree Scalar

activation degree of the term

1.0
implication TNorm | None

implication operator

None

__repr__

__repr__() -> str

Return the code to construct the term in Python.

Returns:

Type Description
str

code to construct the term in Python.

fuzzy_value

fuzzy_value(padding: bool = False) -> Array[str_]

Return fuzzy value in the form {degree}/{name}.

Parameters:

Name Type Description Default
padding bool

whether to pad the degree sign (eg, " - " when True and "-" otherwise)

False

Returns:

Type Description
Array[str_]

fuzzy value in the form {degree}/{name}

membership

membership(x: Scalar) -> Scalar

Compute the implication of the activation degree and the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \alpha_a \otimes \mu_a(x)\)

parameters

parameters() -> str

Return the space-separated parameters of the term.

Returns:

Type Description
str

degree * term if not implication else implication(degree, term)

Aggregated

Bases: Term

Special term that represents a fuzzy set of activated terms to mainly serve as the fuzzy output value of output variables.

Equation

\(\mu(x)=\bigoplus_i^n\alpha_i\otimes\mu_i(x) = \alpha_1\otimes\mu_1(x) \oplus \ldots \oplus \alpha_n\otimes\mu_n(x)\)

where

  • \(\alpha_i\): activation degree of term \(i\)
  • \(\mu_i\): membership function of term \(i\)
  • \(\otimes\): implication operator
  • \(\oplus\): aggregation operator
related

Attributes

aggregation instance-attribute

aggregation = aggregation

maximum instance-attribute

maximum = maximum

minimum instance-attribute

minimum = minimum

terms instance-attribute

terms = list(terms or [])

Functions

__init__

__init__(
    name: str = "",
    minimum: float = nan,
    maximum: float = nan,
    aggregation: SNorm | None = None,
    terms: Iterable[Activated] | None = None,
) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the aggregated term

''
minimum float

minimum value of the range of the fuzzy set

nan
maximum float

maximum value of the range of the fuzzy set

nan
aggregation SNorm | None

aggregation operator

None
terms Iterable[Activated] | None

list of activated terms

None

__repr__

__repr__() -> str

Return the code to construct the term in Python.

Returns:

Type Description
str

code to construct the term in Python.

activation_degree

activation_degree(term: Term) -> Scalar

Compute the aggregated activation degree of the term.

Parameters:

Name Type Description Default
term Term

term to compute the aggregated activation degree

required

Returns:

Type Description
Scalar

aggregated activation degree for the term.

clear

clear() -> None

Clear the list of activated terms.

grouped_terms

grouped_terms() -> dict[str, Activated]

Group the activated terms and aggregate their activation degrees.

Returns:

Type Description
dict[str, Activated]

grouped activated terms by name with aggregated activation degrees.

related

highest_activated_term

highest_activated_term() -> Activated | None

Find the term with the maximum aggregated activation degree.

Returns:

Type Description
Activated | None

term with the maximum aggregated activation degree.

Raises:

Type Description
ValueError

when working with vectorization (eg, size(activation_degree) > 1)

membership

membership(x: Scalar) -> Scalar

Aggregate the activated terms' membership function values of \(x\) using the aggregation operator.

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x)=\bigoplus_i^n\alpha_i\otimes\mu_i(x) = \alpha_1\otimes\mu_1(x) \oplus \ldots \oplus \alpha_n\otimes\mu_n(x)\)

parameters

parameters() -> str

Return the space-separated parameters of the term.

Returns:

Type Description
str

aggregation minimum maximum terms

range

range() -> float

Return the magnitude of the range of the fuzzy set.

Returns:

Type Description
float

maximum - minimum

Arc

Bases: Term

Edge term that represents the arc-shaped membership function.

Equation

\(\mu(x)=\dfrac{h\sqrt{r^2 - (x-c)^2}}{|r|}\)

where

  • \(h\): height of the Term
  • \(r\): radius of the Arc
  • \(c\): center of the Arc

Attributes

end instance-attribute

end = end

start instance-attribute

start = start

Functions

__init__

__init__(name: str = '', start: float = nan, end: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
start float

start of the Arc

nan
end float

end of the Arc

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

start end [height]

required

is_monotonic

is_monotonic() -> bool

Return True because the term is monotonic.

Returns:

Type Description
bool

True

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x)=\dfrac{h\sqrt{r^2 - (x-c)^2}}{|r|}\), clipped accordingly

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

start end

tsukamoto

tsukamoto(y: Scalar) -> Scalar

Compute the tsukamoto value of the monotonic term for activation degree \(y\).

Equation

\(y=\dfrac{h\sqrt{r^2 - (x-c)^2}}{|r|}\)

\(x=c\pm \sqrt{r^2-\dfrac{yr}{h}}\)

Parameters:

Name Type Description Default
y Scalar

activation degree

required

Returns:

Type Description
Scalar

\(x=c\pm \sqrt{r^2-\dfrac{yr}{h}}\)

Bell

Bases: Term

Extended term that represents the generalized bell curve membership function.

Equation

\(\mu(x)=\dfrac{h}{1 + \left(\dfrac{|x-c|}{w}\right)^{2s}}\)

where

  • \(h\): height of the Term
  • \(c\): center of the Bell
  • \(w\): width of the Bell
  • \(s\): slope of the Bell

Attributes

center instance-attribute

center = center

slope instance-attribute

slope = slope

width instance-attribute

width = width

Functions

__init__

__init__(name: str = '', center: float = nan, width: float = nan, slope: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
center float

center of the Bell

nan
width float

width of the Bell

nan
slope float

slope of the Bell

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

center width slope [height].

required

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x)=\dfrac{h}{1 + \left(\dfrac{|x-c|}{w}\right)^{2s}}\)

parameters

parameters() -> str

Return the space-separated parameters of the term.

Returns:

Type Description
str

center width slope [height].

Binary

Bases: Term

Edge Term that represents the binary membership function.

Equation

\(\mu(x) = \begin{cases} h & \mbox{if } (d=\infty \wedge x \ge s) \vee (d=-\infty \wedge x \le s) \cr 0 & \mbox{otherwise} \end{cases}\)

where

  • \(h\): height of the Term
  • \(s\): start of the Binary
  • \(d\): direction of the Binary

Attributes

direction instance-attribute

direction = direction

start instance-attribute

start = start

Functions

__init__

__init__(name: str = '', start: float = nan, direction: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
start float

start of the Binary

nan
direction float

direction of the Binary (-inf, inf)

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

start direction [height].

required

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \begin{cases} h & \mbox{if } (d=\infty \wedge x \ge s) \vee (d=-\infty \wedge x \le s) \cr 0 & \mbox{otherwise} \end{cases}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

start direction [height].

Concave

Bases: Term

Edge Term that represents the concave membership function.

Equation

\(\mu(x) = \begin{cases} h \dfrac{e - i} {2e - i - x} & \mbox{if } i \leq e \wedge x < e \mbox{ (increasing concave)} \cr h \dfrac{i - e} {-2e + i + x} & \mbox{if } i > e \wedge x > e \mbox{ (decreasing concave)} \cr h & \mbox{otherwise} \cr \end{cases}\)

where

  • \(h\): height of the Term
  • \(i\): inflection of the Concave
  • \(e\): end of the Concave

Attributes

end instance-attribute

end = end

inflection instance-attribute

inflection = inflection

Functions

__init__

__init__(name: str = '', inflection: float = nan, end: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
inflection float

inflection of the Concave

nan
end float

end of the Concave

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

inflection end [height].

required

is_monotonic

is_monotonic() -> bool

Return True because the term is monotonic.

Returns:

Type Description
bool

True

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \begin{cases} h \dfrac{e - i} {2e - i - x} & \mbox{if } i \leq e \wedge x < e \mbox{ (increasing concave)} \cr h \dfrac{i - e} {-2e + i + x} & \mbox{if } i > e \wedge x > e \mbox{ (decreasing concave)} \cr h & \mbox{otherwise} \cr \end{cases}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

inflection end [height].

tsukamoto

tsukamoto(y: Scalar) -> Scalar

Compute the tsukamoto value of the monotonic term for activation degree \(y\).

Equation

\(y = h \dfrac{e - i} {2e - i - x}\)

\(x = h \dfrac{e-i}{y} + 2e -i\)

Parameters:

Name Type Description Default
y Scalar

activation degree

required

Returns:

Type Description
Scalar

\(x = h \dfrac{e-i}{y} + 2e -i\)

Constant

Bases: Term

Zero polynomial term \(k\) that represents a constant value.

Equation

\(\mu(x) = k\)

where

  • \(k\): value of the Constant

Attributes

value instance-attribute

value = value

Functions

__init__

__init__(name: str = '', value: float = nan) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
value float

value of the Constant

nan

__repr__

__repr__() -> str

Return the code to construct the term in Python.

Returns:

Type Description
str

code to construct the term in Python.

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

k

required

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

irrelevant

required

Returns:

Type Description
Scalar

\(\mu(x) = k\)

parameters

parameters() -> str

Return the space-separated parameters of the term.

Returns:

Type Description
str

k

Cosine

Bases: Term

Extended term that represents the cosine membership function.

Equation

\(\mu(x) = \begin{cases} \dfrac{h}{2} \left(1 + \cos\left(\dfrac{2.0}{w}\pi(x-c)\right)\right) & \mbox{if } c - \dfrac{w}{2} \le x \le c + \dfrac{w}{2} \cr 0 & \mbox{otherwise} \end{cases}\)

where

  • \(h\): height of the Term
  • \(c\): center of the Cosine
  • \(w\): width of the Cosine

Attributes

center instance-attribute

center = center

width instance-attribute

width = width

Functions

__init__

__init__(name: str = '', center: float = nan, width: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
center float

center of the Cosine

nan
width float

width of the Cosine

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

center width [height].

required

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \begin{cases} \dfrac{h}{2} \left(1 + \cos\left(\dfrac{2.0}{w}\pi(x-c)\right)\right) & \mbox{if } c - \dfrac{w}{2} \le x \le c + \dfrac{w}{2} \cr 0 & \mbox{otherwise} \end{cases}\)

parameters

parameters() -> str

Return the space-separated parameters of the term.

Returns:

Type Description
str

center width [height].

Discrete

Bases: Term

Basic term that represents a discrete membership function.

Equation

\(\mu(x) = h\dfrac{(y_\max - y_\min)}{(x_\max - x_\min)} (x - x_\min) + y_\min\)

where

  • \(h\): height of the Term
  • \(x_{\min}, x_{\max}\): lower and upper bounds of \(x\), respectively
  • \(y_{\min}, y_{\max}\): membership function values \(\mu(x_{\min})\) and \(\mu(x_{\max})\), respectively
related
Warning

The pairs of values in any Discrete term must be sorted in ascending order by the \(x\) coordinate because the membership function is computed using binary search to find the lower and upper bounds of \(x\).

Attributes

Floatable class-attribute instance-attribute

Floatable = Union[SupportsFloat, str]

values instance-attribute

values = values

Functions

__init__

__init__(name: str = '', values: ScalarArray | Sequence[Floatable] | None = None, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the term

''
values ScalarArray | Sequence[Floatable] | None

2D array of \((x,y)\) pairs

None
height float

height of the term.

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

x1 y1 ... xn yn [height].

required

create staticmethod

create(
    name: str,
    xy: str | Sequence[Floatable] | tuple[Sequence[Floatable], Sequence[Floatable]] | dict[Floatable, Floatable],
    height: float = 1.0,
) -> Discrete

Create a discrete term from the parameters.

Parameters:

Name Type Description Default
name str

name of the term

required
xy str | Sequence[Floatable] | tuple[Sequence[Floatable], Sequence[Floatable]] | dict[Floatable, Floatable]

coordinates

required
height float

height of the term

1.0

Returns:

Type Description
Discrete

Discrete term.

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

The function uses binary search to find the lower and upper bounds of \(x\) and then linearly interpolates the membership function value between the bounds.

Warning

The pairs of values in any Discrete term must be sorted in ascending order by the \(x\) coordinate because the membership function is computed using binary search to find the lower and upper bounds of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = h\dfrac{(y_\max - y_\min)}{(x_\max - x_\min)} (x - x_\min) + y_\min\)

parameters

parameters() -> str

Return the space-separated parameters of the term.

Returns:

Type Description
str

x1 y1 ... xn yn [height].

sort

sort() -> None

Sort in ascending order the pairs of values by the \(x\)-coordinate.

to_dict

to_dict() -> dict[float, float]

Return a dictionary of values in the form {x: y}.

Returns:

Type Description
dict[float, float]

dictionary of values in the form {x: y}.

to_list

to_list() -> list[float]

Return a list of values in the form [x1,y1, ..., xn, yn].

Returns:

Type Description
list[float]

list of values in the form [x1,y1, ..., xn, yn].

to_xy staticmethod

to_xy(x: Any, y: Any) -> ScalarArray

Create list of values from the parameters.

Parameters:

Name Type Description Default
x Any

\(x\)-coordinate(s) that can be converted into scalar(s)

required
y Any

\(y\)-coordinate(s) that can be converted into scalar(s)

required

Returns:

Type Description
ScalarArray

array of \(n\)-rows and \(2\)-columns \((n,2)\).

Raises:

Type Description
ValueError

when the shapes of \(x\) and \(y\) are different.

x

x() -> ScalarArray

Return \(x\) coordinates.

Returns:

Type Description
ScalarArray

\(x\) coordinates.

y

y() -> ScalarArray

Return \(y\) coordinates.

Returns:

Type Description
ScalarArray

\(y\) coordinates.

Function

Bases: Term

Polynomial term that represents a generic function.

Equation

\(f : x \mapsto f(x)\)

The function term is also used to convert the text of the antecedent of a rule from infix to postfix notation.

related

Attributes

engine instance-attribute

engine = engine

formula instance-attribute

formula = formula

root instance-attribute

root: Node | None = None

variables instance-attribute

variables: dict[str, Scalar] = copy() if variables else {}

Classes

Element

Representation of a single element in a formula: either a function or an operator.

If the Element represents a function, its parameter is the arity of the function (only unary or binary supported) If the Element represents an operator, its parameters are: arity, precedence, and associativity.

Attributes
arity instance-attribute
arity = arity
associativity instance-attribute
associativity = associativity
description instance-attribute
description = description
method instance-attribute
method = method
name instance-attribute
name = name
precedence instance-attribute
precedence = precedence
type instance-attribute
type = type if isinstance(type, Type) else Type[type]
Classes
Type

Bases: Enum

Type of function element.

Attributes
Function class-attribute instance-attribute
Function = auto()
Operator class-attribute instance-attribute
Operator = auto()
Functions
__repr__
__repr__() -> str

Return the code to construct the name of the element in Python.

Returns:

Type Description
str

code to construct the name of the element in Python.

Functions
__init__
__init__(
    name: str,
    description: str,
    type: Type | str,
    method: Callable[..., Scalar],
    arity: int = 0,
    precedence: int = 0,
    associativity: int = -1,
) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the element

required
description str

description of the element

required
type Type | str

type of the element

required
method Callable[..., Scalar]

reference to the function (only supports unary or binary)

required
arity int

number of operands required

0
precedence int

precedence of operators, where higher precedence comes first (see Order of operations)

0
associativity int

precedence of grouping operators in the absence of parentheses (see Operator associativity)

-1
__repr__
__repr__() -> str

Return the code to construct the element in Python.

Returns:

Type Description
str

code to construct the element in Python.

is_function
is_function() -> bool

Return whether the element is a fuzzylite.term.Function.Element.Type.Function.

Returns:

Type Description
bool
is_operator
is_operator() -> bool

Return whether the element is a fuzzylite.term.Function.Element.Type.Operator.

Returns:

Type Description
bool

Node

Basic binary tree structure.

A node can point to left and right nodes to build a binary tree.

A node can represent:

  • an element (Function or Operator),
  • an input or output variable by name,
  • a constant floating-point value
Attributes
constant instance-attribute
constant = constant
element instance-attribute
element = element
left instance-attribute
left = left
right instance-attribute
right = right
variable instance-attribute
variable = variable
Functions
__init__
__init__(
    element: Element | None = None,
    variable: str = "",
    constant: float = nan,
    left: Node | None = None,
    right: Node | None = None,
) -> None

Constructor.

Parameters:

Name Type Description Default
element Element | None

node refers to a function or an operator

None
variable str

node refers to a variable by name

''
constant float

node refers to an arbitrary floating-point value

nan
right Node | None

node has an expression tree on the right

None
left Node | None

node has an expression tree on the left.

None
__repr__
__repr__() -> str

Return the code to construct the node in Python.

Returns:

Type Description
str

code to construct the node in Python.

evaluate
evaluate(local_variables: dict[str, Scalar] | None = None) -> Scalar

Recursively evaluate the node and substitute the variables with the given values (if any).

Parameters:

Name Type Description Default
local_variables dict[str, Scalar] | None

map of substitutions of variable names for scalars

None

Returns:

Type Description
Scalar

scalar as the result of the evaluation.

Raises:

Type Description
ValueError

when function arity is not met with left and right nodes

ValueError

when the node represents a variable but the map does not contain its substitution value

infix
infix(node: Node | None = None) -> str

Return the infix notation of the node.

Parameters:

Name Type Description Default
node Node | None

node in the expression tree (defaults to self if None)

None

Returns:

Type Description
str

infix notation of the node.

postfix
postfix(node: Node | None = None) -> str

Return the postfix notation of the node.

Parameters:

Name Type Description Default
node Node | None

node in the expression tree (defaults to self if None)

None

Returns:

Type Description
str

postfix notation of the node.

prefix
prefix(node: Node | None = None) -> str

Return the prefix notation of the node.

Parameters:

Name Type Description Default
node Node | None

node in the expression tree (defaults to self if None)

None

Returns:

Type Description
str

prefix notation of the node.

value
value() -> str

Return the value of the node based on its contents.

The value of the node is the first of:

  1. operation or function name if there is an element
  2. variable name if it is not empty
  3. constant value.

Returns:

Type Description
str

value of the node based on its contents.

Functions

__init__

__init__(
    name: str = "",
    formula: str = "",
    engine: Engine | None = None,
    variables: dict[str, Scalar] | None = None,
    load: bool = False,
) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the term

''
formula str

formula defining the membership function

''
engine Engine | None

engine to which the Function can have access

None
variables dict[str, Scalar] | None

map of substitution variables

None
load bool

load the function on creation.

False

__repr__

__repr__() -> str

Return the code to construct the term in Python.

Returns:

Type Description
str

code to construct the term in Python.

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

formula.

required

create staticmethod

create(name: str, formula: str, engine: Engine | None = None) -> Function

Create and configure a function term.

Parameters:

Name Type Description Default
name str

name of the term

required
formula str

formula defining the membership function

required
engine Engine | None

engine to which the Function can have access

None

Returns:

Type Description
Function

configured function term

Raises:

Type Description
SyntaxError

when the formula has a syntax error

evaluate

evaluate(variables: dict[str, Scalar] | None = None) -> Scalar

Evaluate the function value using the map of variable substitutions (if any).

Parameters:

Name Type Description Default
variables dict[str, Scalar] | None

map containing substitutions of variable names for values

None

Returns:

Type Description
Scalar

function value using the map of variable substitutions (if any).

Raises:

Type Description
RuntimeError

when the function is not loaded

format_infix classmethod

format_infix(formula: str) -> str

Format the formula expressed in infix notation.

Parameters:

Name Type Description Default
formula str

formula expressed in infix notation.

required

Returns:

Type Description
str

formatted formula expressed in infix notation.

infix_to_postfix classmethod

infix_to_postfix(formula: str) -> str

Convert the formula to postfix notation.

Parameters:

Name Type Description Default
formula str

right-hand side of an equation expressed in infix notation

required

Returns:

Type Description
str

formula in postfix notation

Raises:

Type Description
SyntaxError

when the formula has syntax errors.

is_loaded

is_loaded() -> bool

Return whether the function is loaded.

Returns:

Type Description
bool

function is loaded.

load

load() -> None

Load the function using the formula expressed in infix notation.

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

The value of variable x will be added to the variables map, and so will the current values of the input variables and output variables if the engine has been set.

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(f(x)\)

Raises:

Type Description
ValueError

when an input or output variable is named x

ValueError

when the map of variables contain names of input or output variables

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

formula.

parse classmethod

parse(formula: str) -> Node

Create a node as a binary expression tree of the formula.

Parameters:

Name Type Description Default
formula str

right-hand side of an equation expressed in infix notation

required

Returns:

Type Description
Node

node as a binary expression tree of the formula

Raises:

Type Description
SyntaxError

when the formula has syntax errors.

unload

unload() -> None

Unload the function and reset the map of substitution variables.

update_reference

update_reference(engine: Engine | None) -> None

Update the reference to the engine (if any) and load the function if it is not loaded.

Parameters:

Name Type Description Default
engine Engine | None

engine to which the term belongs to.

required

Gaussian

Bases: Term

Extended term that represents the gaussian curve membership function.

Equation

\(\mu(x) = h \exp\left(-\dfrac{(x-\mu)^2}{2\sigma^2}\right)\)

where

  • \(h\): height of the Term
  • \(\mu\): mean of the Gaussian
  • \(\sigma\): standard deviation of the Gaussian

Attributes

mean instance-attribute

mean = mean

standard_deviation instance-attribute

standard_deviation = standard_deviation

Functions

__init__

__init__(name: str = '', mean: float = nan, standard_deviation: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
mean float

mean of the Gaussian

nan
standard_deviation float

standard deviation of the Gaussian

nan
height float

height of the Term.

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

mean standard_deviation [height].

required

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = h \exp\left(-\dfrac{(x-\mu)^2}{2\sigma^2}\right)\)

parameters

parameters() -> str

Return the space-separated parameters of the term.

Returns:

Type Description
str

mean standard_deviation [height].

GaussianProduct

Bases: Term

Extended term that represents the two-sided gaussian membership function.

Equation

\(a = \begin{cases} \mbox{Gaussian}^{\mu_a}_{\sigma_a}(x) & \mbox{if } x < \mu_a \cr 1.0 & \mbox{otherwise} \cr \end{cases}\)

\(b = \begin{cases} \mbox{Gaussian}^{\mu_b}_{\sigma_b}(x) & \mbox{if } x > \mu_b \cr 1.0 & \mbox{otherwise} \cr \end{cases}\)

\(\mu(x) = h (a \times b)\)

where

  • \(h\): height of the Term
  • \(\mu_a, \sigma_a\): mean and standard deviation of the first Gaussian
  • \(\mu_b, \sigma_b\): mean and standard deviation of the second Gaussian

Attributes

mean_a instance-attribute

mean_a = mean_a

mean_b instance-attribute

mean_b = mean_b

standard_deviation_a instance-attribute

standard_deviation_a = standard_deviation_a

standard_deviation_b instance-attribute

standard_deviation_b = standard_deviation_b

Functions

__init__

__init__(
    name: str = "",
    mean_a: float = nan,
    standard_deviation_a: float = nan,
    mean_b: float = nan,
    standard_deviation_b: float = nan,
    height: float = 1.0,
) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
mean_a float

mean of the first Gaussian

nan
standard_deviation_a float

standard deviation of the first Gaussian

nan
mean_b float

mean of the second Gaussian

nan
standard_deviation_b float

standard deviation of the second Gaussian

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

mean_a standard_deviation_a mean_b standard_deviation_b [height].

required

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = h (a \times b)\)

parameters

parameters() -> str

Return the space-separated parameters of the term.

Returns:

Type Description
str

mean_a standard_deviation_a mean_b standard_deviation_b [height].

Linear

Bases: Term

Linear polynomial term.

Equation

\(\mu(x)= \mathbf{c}\mathbf{v}+k = \sum_i c_iv_i + k\)

where

  • \(x\): irrelevant
  • \(\mathbf{v}\): vector of values from the input variables
  • \(\mathbf{c}\) vector of coefficients for the input variables
  • \(k\) is a constant

Attributes

coefficients instance-attribute

coefficients = list(coefficients or [])

engine instance-attribute

engine = engine

Functions

__init__

__init__(name: str = '', coefficients: Sequence[float] | None = None, engine: Engine | None = None) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the term

''
coefficients Sequence[float] | None

coefficients for the input variables (plus constant \(k\), optionally)

None
engine Engine | None

engine with the input variables

None

__repr__

__repr__() -> str

Return the code to construct the term in Python.

Returns:

Type Description
str

code to construct the term in Python.

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

coefficients c1 ... cn k.

required

membership

membership(x: Scalar) -> Scalar

Compute the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x)=\sum_i c_iv_i + k\)

Raises:

Type Description
ValueError

when the number of coefficients (+1) is different from the number of input variables

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

c1 ... cn k.

update_reference

update_reference(engine: Engine | None) -> None

Set the reference to the engine.

Parameters:

Name Type Description Default
engine Engine | None

engine with the input variables

required

PiShape

Bases: Term

Extended term that represents the Pi-shaped membership function.

Equation

\(\mu(x) = h \left(\mbox{SShape}_{a}^{b}(x) \times \mbox{ZShape}_{c}^{d}(x)\right)\)

where

  • \(h\): height of the Term
  • \(a, b\): bottom left and top left parameters of the PiShape
  • \(c, d\): top right and bottom right parameters of the PiShape
related

Attributes

bottom_left instance-attribute

bottom_left = bottom_left

bottom_right instance-attribute

bottom_right = bottom_right

top_left instance-attribute

top_left = top_left

top_right instance-attribute

top_right = top_right

Functions

__init__

__init__(
    name: str = "",
    bottom_left: float = nan,
    top_left: float = nan,
    top_right: float = nan,
    bottom_right: float = nan,
    height: float = 1.0,
) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
bottom_left float

bottom-left value of the PiShape

nan
top_left float

top-left value of the PiShape

nan
top_right float

top-right value of the PiShape

nan
bottom_right float

bottom-right value of the PiShape

nan
height float

height of the Term.

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

bottom_left top_left top_right bottom_right [height].

required

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = h \left(\mbox{SShape}_{a}^{b}(x) \times \mbox{ZShape}_{c}^{d}(x)\right)\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

bottom_left top_left top_right bottom_right [height].

Ramp

Bases: Term

Edge term that represents the ramp membership function.

Equation

\(\mu(x) = \begin{cases} h \dfrac{x - s} {e - s} & \mbox{if } s < x < e \cr h \dfrac{s - x} {s - e} & \mbox{if } e < x < s \cr h & \mbox{if } s < e \wedge x \ge e \cr h & \mbox{if } s > e \wedge x \le e \cr 0 & \mbox{otherwise} \end{cases}\)

where

  • \(h\): height of the Term
  • \(s\): start of the Ramp
  • \(e\): end of the Ramp

Attributes

end instance-attribute

end = end

start instance-attribute

start = start

Functions

__init__

__init__(name: str = '', start: float = nan, end: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
start float

start of the Ramp

nan
end float

end of the Ramp

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

start end [height].

required

is_monotonic

is_monotonic() -> bool

Return True because the term is monotonic.

Returns:

Type Description
bool

True

membership

membership(x: Scalar) -> Scalar

Compute the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \begin{cases} h \dfrac{x - s} {e - s} & \mbox{if } s < x < e \cr h \dfrac{s - x} {s - e} & \mbox{if } e < x < s \cr h & \mbox{if } s < e \wedge x \ge e \cr h & \mbox{if } s > e \wedge x \le e \cr 0 & \mbox{otherwise} \end{cases}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

start end [height].

tsukamoto

tsukamoto(y: Scalar) -> Scalar

Compute the tsukamoto value of the monotonic term for activation degree \(y\).

Equation

\(y = h \dfrac{x - s} {e - s}\)

\(x = s + (e-s) \dfrac{y}{h}\)

Parameters:

Name Type Description Default
y Scalar

activation degree

required

Returns:

Type Description
Scalar

\(x = s + (e-s) \dfrac{y}{h}\)

Rectangle

Bases: Term

Basic term that represents the rectangle membership function.

Equation

\(\mu(x) = \begin{cases} h & \mbox{if } s \le x \le e \cr 0 & \mbox{otherwise} \end{cases}\)

where

  • \(h\): height of the Term
  • \(s\): start of the Rectangle
  • \(e\): end of the Rectangle

Attributes

end instance-attribute

end = end

start instance-attribute

start = start

Functions

__init__

__init__(name: str = '', start: float = nan, end: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
start float

start of the Rectangle

nan
end float

end of the Rectangle

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

start end [height].

required

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \begin{cases} h & \mbox{if } s \le x \le e \cr 0 & \mbox{otherwise} \end{cases}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

start end [height].

SShape

Bases: Term

Edge Term that represents the S-shaped membership function.

Equation:

\(\mu(x) = \begin{cases} 0 & \mbox{if } x \leq s \cr 2h \left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x \leq \dfrac{s+e}{2}\cr h - 2h\left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} < x < e\cr h & \mbox{otherwise} \end{cases}\)

where

  • \(h\): height of the Term
  • \(s\): start of the SShape
  • \(e\): end of the SShape

Attributes

end instance-attribute

end = end

start instance-attribute

start = start

Functions

__init__

__init__(name: str = '', start: float = nan, end: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
start float

start of the SShape

nan
end float

end of the SShape

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

start end [height].

required

is_monotonic

is_monotonic() -> bool

Return True because the term is monotonic.

Returns:

Type Description
bool

True

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \begin{cases} 0 & \mbox{if } x \leq s \cr 2h \left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x \leq \dfrac{s+e}{2}\cr h - 2h\left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} < x < e\cr h & \mbox{otherwise} \end{cases}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

start end [height].

tsukamoto

tsukamoto(y: Scalar) -> Scalar

Compute the tsukamoto value of the monotonic term for activation degree \(y\).

Equation

\(y = \begin{cases} 0 & \mbox{if } x \leq s \cr 2h \left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x \leq \dfrac{s+e}{2}\cr h - 2h\left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} < x < e\cr h & \mbox{otherwise} \end{cases}\)

\(x = \begin{cases} s + (e-s) \sqrt{\dfrac{y}{2h}} & \mbox{if } y \le \dfrac{h}{2} \cr e - (e-s) \sqrt{\dfrac{h-y}{2h}} & \mbox{otherwise} \end{cases}\)

Parameters:

Name Type Description Default
y Scalar

activation degree

required

Returns:

Type Description
Scalar

\(x = \begin{cases} s + (e-s) \sqrt{\dfrac{y}{2h}} & \mbox{if } y \le \dfrac{h}{2} \cr e - (e-s) \sqrt{\dfrac{h-y}{2h}} & \mbox{otherwise} \end{cases}\)

SemiEllipse

Bases: Term

Basic term that represents the semi-ellipse membership function.

Equation

\(\mu(x) = h \dfrac{\sqrt{r^2- (x-c)^2}}{r}\)

where

  • \(h\): height of the Term
  • \(r\): radius of the SemiEllipse
  • \(c\): center of the SemiEllipse

Attributes

end instance-attribute

end = end

start instance-attribute

start = start

Functions

__init__

__init__(name: str = '', start: float = nan, end: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
start float

start of the SemiEllipse

nan
end float

end of the SemiEllipse

nan
height float

height of the Term.

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

start end [height]

required

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = h \dfrac{\sqrt{r^2- (x-c)^2}}{r}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

start end [height]

Sigmoid

Bases: Term

Edge Term that represents the sigmoid membership function.

Equation

\(\mu(x) = \dfrac{h}{1 + \exp(-s(x-i))}\)

where

  • \(h\): height of the Term
  • \(s\): slope of the Sigmoid
  • \(i\): inflection of the Sigmoid

Attributes

inflection instance-attribute

inflection = inflection

slope instance-attribute

slope = slope

Functions

__init__

__init__(name: str = '', inflection: float = nan, slope: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
inflection float

inflection of the Sigmoid

nan
slope float

slope of the Sigmoid

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

inflection slope [height].

required

is_monotonic

is_monotonic() -> bool

Return True because the term is monotonic.

Returns:

Type Description
bool

True

membership

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \dfrac{h}{1 + \exp(-s(x-i))}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

inflection slope [height].

tsukamoto

tsukamoto(y: Scalar) -> Scalar

Compute the tsukamoto value of the monotonic term for activation degree \(y\).

Equation

\(y=\dfrac{h}{1 + \exp(-s(x-i))}\)

\(x=i\dfrac{\log{\left(\dfrac{h}{y}-1\right)}}{-s}\)

Parameters:

Name Type Description Default
y Scalar

activation degree

required

Returns:

Type Description
Scalar

\(x=i\dfrac{\log{\left(\dfrac{h}{y}-1\right)}}{-s}\)

SigmoidDifference

Bases: Term

Extended Term that represents the difference between two sigmoid membership functions.

Equation

\(a = \mbox{Sigmoid}_\mbox{left}^\mbox{rise}(x)\)

\(b = \mbox{Sigmoid}_\mbox{right}^\mbox{fall}(x)\)

\(\mu(x) = h (a-b)\)

where

  • \(h\): height of the Term
  • \(\mbox{left}, \mbox{rise}\): inflection and slope of left Sigmoid
  • \(\mbox{right}, \mbox{fall}\): inflection and slope of right Sigmoid

Attributes

falling instance-attribute

falling = falling

left instance-attribute

left = left

right instance-attribute

right = right

rising instance-attribute

rising = rising

Functions

__init__

__init__(
    name: str = "",
    left: float = nan,
    rising: float = nan,
    falling: float = nan,
    right: float = nan,
    height: float = 1.0,
) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
left float

inflection of the left Sigmoid

nan
rising float

slope of the left Sigmoid

nan
falling float

slope of the right Sigmoid

nan
right float

inflection of the right Sigmoid

nan
height float

height of the Term.

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

left rising falling right [height].

required

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = h (a-b)\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

left rising falling right [height].

SigmoidProduct

Bases: Term

Extended Term that represents the product of two sigmoid membership functions.

Equation

\(a = \mbox{Sigmoid}_\mbox{left}^\mbox{rise}(x)\)

\(b = \mbox{Sigmoid}_\mbox{right}^\mbox{fall}(x)\)

\(\mu(x) = h (a \times b)\)

where

  • \(h\): height of the Term
  • \(\mbox{left}, \mbox{rise}\): inflection and slope of left Sigmoid
  • \(\mbox{right}, \mbox{fall}\): inflection and slope of right Sigmoid

Attributes

falling instance-attribute

falling = falling

left instance-attribute

left = left

right instance-attribute

right = right

rising instance-attribute

rising = rising

Functions

__init__

__init__(
    name: str = "",
    left: float = nan,
    rising: float = nan,
    falling: float = nan,
    right: float = nan,
    height: float = 1.0,
) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
left float

inflection of the left Sigmoid

nan
rising float

slope of the left Sigmoid

nan
falling float

slope of the right Sigmoid

nan
right float

inflection of the right Sigmoid

nan
height float

height of the Term.

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

left rising falling right [height].

required

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = h (a \times b)\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

left rising falling right [height].

Spike

Bases: Term

Extended Term that represents the spike membership function.

Equation

\(\mu(x)=h \exp\left(-\left|\dfrac{10}{w} (x - c)\right|\right)\)

where

  • \(h\): height of the Term
  • \(w\): width of the Spike
  • \(c\): center of the Spike

Attributes

center instance-attribute

center = center

width instance-attribute

width = width

Functions

__init__

__init__(name: str = '', center: float = nan, width: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
center float

center of the Spike

nan
width float

width of the Spike

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

center width [height].

required

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x)=h \exp\left(-\left|\dfrac{10}{w} (x - c)\right|\right)\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

center width [height].

Term

Bases: ABC

Abstract class for linguistic terms.

The linguistic terms in this library can be divided into four groups, namely basic, extended, edge, and function.

basic/function extended edge
fuzzylite.term.Discrete fuzzylite.term.Bell fuzzylite.term.Arc
fuzzylite.term.Rectangle fuzzylite.term.Cosine fuzzylite.term.Binary
fuzzylite.term.SemiEllipse fuzzylite.term.Gaussian fuzzylite.term.Concave
fuzzylite.term.Triangle fuzzylite.term.GaussianProduct fuzzylite.term.Ramp
fuzzylite.term.Trapezoid fuzzylite.term.PiShape fuzzylite.term.Sigmoid
fuzzylite.term.Constant fuzzylite.term.SigmoidDifference fuzzylite.term.SShape - fuzzylite.term.ZShape
fuzzylite.term.Linear fuzzylite.term.SigmoidProduct fuzzylite.term.SShape
fuzzylite.term.Function fuzzylite.term.Spike fuzzylite.term.ZShape
related

Attributes

height instance-attribute

height = height

name instance-attribute

name = name

Functions

__init__

__init__(name: str = '', height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the term

''
height float

height of the term.

1.0

__repr__

__repr__() -> str

Return the code to construct the term in Python.

Returns:

Type Description
str

code to construct the term in Python.

__str__

__str__() -> str

Return the code to construct the term in the FuzzyLite Language.

Returns:

Type Description
str

code to construct the term in the FuzzyLite Language.

_parameters

_parameters(*args: object) -> str

Concatenate the arguments and the height.

Parameters:

Name Type Description Default
*args object

arguments to configure the term

()

Returns:

Type Description
str

parameters concatenated and an optional height at the end.

_parse

_parse(required: int, parameters: str, *, height: bool = True) -> list[float]

Parse the required values from the parameters.

Parameters:

Name Type Description Default
required int

number of values to parse

required
parameters str

text containing the values

required
height bool

whether parameters contains an extra value for the height of the term

True

Returns:

Type Description
list[float]

list of floating-point values parsed from the parameters.

configure

configure(parameters: str) -> None

Configure the term with the parameters.

The parameters is a list of space-separated values, with an optional value at the end to set the height (defaults to 1.0 if absent)

Parameters:

Name Type Description Default
parameters str

space-separated parameter values to configure the term.

required

discretize

discretize(start: float, end: float, resolution: int = 10, midpoints: bool = True) -> Discrete

Discretize the term.

Parameters:

Name Type Description Default
start float

start of the range

required
end float

end of the range

required
resolution int

number of points to discretize

10
midpoints bool

use midpoints method or include start and end.

True
related

is_monotonic

is_monotonic() -> bool

Return whether the term is monotonic.

Returns:

Type Description
bool

False.

membership abstractmethod

membership(x: Scalar) -> Scalar

Compute the membership function value of \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

membership function value \(\mu(x)\).

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

list of space-separated parameters of the term.

tsukamoto

tsukamoto(y: Scalar) -> Scalar

Compute the tsukamoto value of the monotonic term for activation degree \(y\).

Equation

\(g(y) = \{ z \in\mathbb{R} : \mu(z) = y \}\)

Warning

Raises RuntimeError because the term does not support Tsukamoto

Parameters:

Name Type Description Default
y Scalar

activation degree

required

Raises:

Type Description
RuntimeError

because the term does not support Tsukamoto

update_reference

update_reference(engine: Engine | None) -> None

Update the reference (if any) to the engine the term belongs to.

Parameters:

Name Type Description Default
engine Engine | None

engine to which the term belongs to.

required

Trapezoid

Bases: Term

Basic Term that represents the trapezoid membership function.

Equation

\(\mu(x)= \begin{cases} 0 & \mbox{if } x < a \vee x > d\cr h \dfrac{x - a}{b - a} & \mbox{if } a \le x < b\cr h & \mbox{if } (b \le x \le c) \vee (a=-\infty \wedge x < b) \vee (d=\infty \wedge x > c) \cr h \dfrac{d - x}{d - c} & \mbox{if } c < x \le d\cr \text{NaN} & \mbox{otherwise} \end{cases}\)

where

  • \(h\): height of the Term
  • \(a\): bottom left vertex of the Trapezoid
  • \(b\): top left vertex of the Trapezoid
  • \(c\): top right vertex of the Trapezoid
  • \(d\): bottom right vertex of the trapezoid

Attributes

bottom_left instance-attribute

bottom_left = bottom_left

bottom_right instance-attribute

bottom_right = bottom_right

top_left instance-attribute

top_left = top_left

top_right instance-attribute

top_right = top_right

Functions

__init__

__init__(
    name: str = "",
    bottom_left: float = nan,
    top_left: float = nan,
    top_right: float = nan,
    bottom_right: float = nan,
    height: float = 1.0,
) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
bottom_left float

first vertex of the Trapezoid

nan
top_left float

second vertex of the Trapezoid

nan
top_right float

third vertex of the Trapezoid

nan
bottom_right float

fourth vertex of the Trapezoid

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

bottom_left top_left top_right bottom_right [height].

required

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x)= \begin{cases} 0 & \mbox{if } x < a \vee x > d\cr h \dfrac{x - a}{b - a} & \mbox{if } a \le x < b\cr h & \mbox{if } (b \le x \le c) \vee (a=-\infty \wedge x < b) \vee (d=\infty \wedge x > c) \cr h \dfrac{d - x}{d - c} & \mbox{if } c < x \le d\cr \text{NaN} & \mbox{otherwise} \end{cases}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

bottom_left top_left top_right bottom_right [height].

Triangle

Bases: Term

Basic Term that represents the triangle membership function.

Equation

\(\mu(x)= \begin{cases} 0 & \mbox{if } x < a \vee x > c \cr h & \mbox{if } (x = b) \vee (a=-\infty \wedge x < b) \vee (c=\infty \wedge x > b) \cr h \dfrac{x - a}{b - a} & \mbox{if } a \le x < b \cr h \dfrac{c - x}{c - b} & \mbox{if } b < x \le c \end{cases}\)

where

  • \(h\): height of the Term
  • \(a\): left vertex of the Triangle
  • \(b\): top vertex of the Triangle
  • \(c\): right vertex of the Triangle

Attributes

left instance-attribute

left = left

right instance-attribute

right = right

top instance-attribute

top = top

Functions

__init__

__init__(name: str = '', left: float = nan, top: float = nan, right: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
left float

first vertex of the Triangle

nan
top float

second vertex of the Triangle

nan
right float

third vertex of the Triangle

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

left top right [height].

required

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x)= \begin{cases} 0 & \mbox{if } x < a \vee x > c \cr h & \mbox{if } (x = b) \vee (a=-\infty \wedge x < b) \vee (c=\infty \wedge x > b) \cr h \dfrac{x - a}{b - a} & \mbox{if } a \le x < b \cr h \dfrac{c - x}{c - b} & \mbox{if } b < x \le c \end{cases}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

left top right [height].

ZShape

Bases: Term

Edge Term that represents the ZShape membership function.

Equation

\(\mu(x) = \begin{cases} 1 & \mbox{if } x \leq s \cr h - 2h\left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x < \dfrac{s+e}{2} \cr 2h \left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} \le x < e\cr 0 & \mbox{otherwise} \end{cases}\)

where

  • \(h\): height of the Term
  • \(s\): start of the ZShape
  • \(e\): end of the ZShape

Attributes

end instance-attribute

end = end

start instance-attribute

start = start

Functions

__init__

__init__(name: str = '', start: float = nan, end: float = nan, height: float = 1.0) -> None

Constructor.

Parameters:

Name Type Description Default
name str

name of the Term

''
start float

start of the ZShape

nan
end float

end of the ZShape

nan
height float

height of the Term

1.0

configure

configure(parameters: str) -> None

Configure the term with the parameters.

Parameters:

Name Type Description Default
parameters str

start end [height].

required

is_monotonic

is_monotonic() -> bool

Return True because the term is monotonic.

Returns:

Type Description
bool

True

membership

membership(x: Scalar) -> Scalar

Computes the membership function evaluated at \(x\).

Parameters:

Name Type Description Default
x Scalar

scalar

required

Returns:

Type Description
Scalar

\(\mu(x) = \begin{cases} 1 & \mbox{if } x \leq s \cr h - 2h\left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x < \dfrac{s+e}{2} \cr 2h \left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} \le x < e\cr 0 & \mbox{otherwise} \end{cases}\)

parameters

parameters() -> str

Return the parameters of the term.

Returns:

Type Description
str

start end [height].

tsukamoto

tsukamoto(y: Scalar) -> Scalar

Compute the tsukamoto value of the monotonic term for activation degree \(y\).

Equation

\(y = \begin{cases} 1 & \mbox{if } x \leq s \cr h - 2h\left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x < \dfrac{s+e}{2} \cr 2h \left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} \le x < e\cr 0 & \mbox{otherwise} \end{cases}\)

\(x = \begin{cases} e + (e-s) \sqrt{\dfrac{y}{2h}} & \mbox{if } y \le \dfrac{h}{2} \cr s + (e-s) \sqrt{\dfrac{h-y}{2h}} & \mbox{otherwise} \end{cases}\)

Parameters:

Name Type Description Default
y Scalar

activation degree

required

Returns:

Type Description
Scalar

\(x = \begin{cases} e + (e-s) \sqrt{\dfrac{y}{2h}} & \mbox{if } y \le \dfrac{h}{2} \cr s + (e-s) \sqrt{\dfrac{h-y}{2h}} & \mbox{otherwise} \end{cases}\)