Fuzzy Sets Functions

This is a the source file that contains the class of GT2 fuzzy set and its most direct applications, like computing the FM function, etc.

class ex_fuzzy.fuzzy_sets.FS(name: str, membership_parameters: list[float], domain: list[float])[source]

Bases: object

Class that defines the most basic fuzzy sets (also known as Type 1 fuzzy sets or Zadeh sets).

membership(x: array) array[source]

Computes the membership of a point or a vector.

Parameters:

x – input values in the fuzzy set referencial domain.

type() FUZZY_SETS[source]

Returns the corresponding fuzzy set type according to FUZZY_SETS enum.

Returns:

FUZZY_SETS enum.

class ex_fuzzy.fuzzy_sets.GT2(name: str, secondary_memberships: dict[float, FS], domain: list[float], significant_decimals: int, alpha_cuts: list[float] = [0.2, 0.4, 0.5, 0.7, 0.9, 1.0], unit_resolution: float = 0.2)[source]

Bases: FS

Class to define a gt2 fuzzy set.

alpha_reduction(x) array[source]

Computes the type reduction to reduce the alpha cuts to one value.

Parameters:

x – array with the values of the inputs.

Returns:

array with the memberships of the consequents for each sample.

membership(x: array) array[source]

Computes the alpha cut memberships of a point.

Parameters:

x – input values in the fuzzy set referencial domain.

Returns:

np array samples x alpha_cuts x 2

type() FUZZY_SETS[source]

Returns the corresponding fuzzy set type according to FUZZY_SETS enum.

Returns:

FUZZY_SETS enum.

class ex_fuzzy.fuzzy_sets.IVFS(name: str, secondMF_lower: list[float], secondMF_upper: list[float], domain: list[float], lower_height=1.0)[source]

Bases: FS

Class to define a iv fuzzy set.

membership(x: array) array[source]

Computes the iv-membership of a point or a vector.

Parameters:

x – input values in the fuzzy set referencial domain.

Returns:

iv-membership of the fuzzy set.

type() FUZZY_SETS[source]

Returns the corresponding fuzzy set type according to FUZZY_SETS enum: (t2)

class ex_fuzzy.fuzzy_sets.categoricalFS(name: str, category)[source]

Bases: FS

membership(x: array) array[source]

Computes the membership of a point or vector of elements.

Parameters:

x – input values in the referencial domain.

type() FUZZY_SETS[source]

Returns the corresponding fuzzy set type according to FUZZY_SETS enum.

class ex_fuzzy.fuzzy_sets.categoricalIVFS(name: str, category)[source]

Bases: IVFS

Class to define a iv fuzzy set with categorical membership.

membership(x: array) array[source]

Computes the membership of a point or vector of elements.

Parameters:

x – input values in the referencial domain.

type() FUZZY_SETS[source]

Returns the corresponding fuzzy set type according to FUZZY_SETS enum.

class ex_fuzzy.fuzzy_sets.fuzzyVariable(name: str, fuzzy_sets: list[FS], units: str = None)[source]

Bases: object

Class to implement a fuzzy Variable. Contains a series of fuzzy sets and computes the memberships to all of them.

append(fs: FS) None[source]

Appends a fuzzy set to the fuzzy variable.

Parameters:

fs – FS. Fuzzy set to append.

compute_memberships(x: array) list[source]

Computes the membership to each of the FS in the fuzzy variables.

Parameters:

x – numeric value or array. Computes the membership to each of the FS in the fuzzy variables.

Returns:

list of floats. Membership to each of the FS in the fuzzy variables.

domain() list[float][source]

Returns the domain of the fuzzy variable.

Returns:

list of floats.

fuzzy_type() FUZZY_SETS[source]

Returns the fuzzy type of the domain

Returns:

the type of the fuzzy set present in the fuzzy variable.

get_linguistic_variables() list[FS][source]

Returns the name of the linguistic variables.

Returns:

list of strings.

linguistic_variable_names() list[source]

Returns the name of the linguistic variables.

Returns:

list of strings.

class ex_fuzzy.fuzzy_sets.gaussianFS(name: str, membership_parameters: list[float], domain: list[float])[source]

Bases: FS

Class to define a gaussian fuzzy set.

membership(input: array) array[source]

Computes the gaussian membership of a point or a vector.

Parameters:

input – input values in the fuzzy set referencial domain.

Returns:

np array samples

type() FUZZY_SETS[source]

Returns the type of the fuzzy set. (t1)

class ex_fuzzy.fuzzy_sets.gaussianIVFS(name: str, secondMF_lower: list[float], secondMF_upper: list[float], domain: list[float], lower_height=1.0)[source]

Bases: IVFS

Class to define a iv fuzzy set with gaussian membership.

membership(input: array) array[source]

Computes the gaussian iv-membership of a point or a vector.

Parameters:

input – input values in the fuzzy set referencial domain.

Returns:

np array samples x 2

type() FUZZY_SETS[source]

Returns the type of the fuzzy set. (t1)

ex_fuzzy.fuzzy_sets.trapezoidal_membership(x: array, params: list[float], epsilon=0.0001) array[source]

Trapezoidal membership functions.

Parameters:
  • x – input values in the fuzzy set referencial domain.

  • params – four numbers that comprises the start and end of the trapezoid.

  • epsilon – small float number for numerical stability. Adjust accordingly only if there are NaN issues.