ex_fuzzy.fuzzy_sets.fuzzyVariable#

class ex_fuzzy.fuzzy_sets.fuzzyVariable(name, fuzzy_sets, units=None)[source]#

Bases: object

Fuzzy Variable Container and Management Class.

This class represents a fuzzy variable composed of multiple fuzzy sets (linguistic variables). It provides methods to compute memberships across all fuzzy sets and manage the linguistic terms of the variable.

linguistic_variables#

List of fuzzy sets that define the variable

Type:

list

name#

Name of the fuzzy variable

Type:

str

units#

Units of measurement (optional, for display purposes)

Type:

str

fs_type#

Type of fuzzy sets (t1 or t2)

Type:

FUZZY_SETS

Example

>>> # Create fuzzy sets for temperature
>>> low_temp = gaussianFS([15, 5], "Low", 100)
>>> medium_temp = gaussianFS([25, 5], "Medium", 100)
>>> high_temp = gaussianFS([35, 5], "High", 100)
>>>
>>> # Create fuzzy variable
>>> temp_var = fuzzyVariable("Temperature", [low_temp, medium_temp, high_temp], "°C")
>>> memberships = temp_var.membership([20, 25, 30])
>>> print(memberships.shape)  # (3, 3) - 3 inputs, 3 fuzzy sets

Note

All fuzzy sets in the variable must be of the same type (t1 or t2).

__init__(name, fuzzy_sets, units=None)[source]#

Creates a fuzzy variable with the specified fuzzy sets.

Parameters:
  • name (str) – Name of the fuzzy variable

  • fuzzy_sets (list[FS]) – List of fuzzy sets that comprise the linguistic variables

  • units (str, optional) – Units of the fuzzy variable for display purposes

Raises:

ValueError – If fuzzy_sets is empty or contains mixed types

Example

>>> fs1 = gaussianFS([0, 1], "Low", 10)
>>> fs2 = gaussianFS([5, 1], "High", 10)
>>> var = fuzzyVariable("Speed", [fs1, fs2], "m/s")

Methods

__init__(name, fuzzy_sets[, units])

Creates a fuzzy variable with the specified fuzzy sets.

append(fs)

Appends a fuzzy set to the fuzzy variable.

compute_memberships(x)

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

domain()

Returns the domain of the fuzzy variable.

fuzzy_type()

Returns the fuzzy type of the domain

get_linguistic_variables()

Returns the name of the linguistic variables.

linguistic_variable_names()

Returns the name of the linguistic variables.

validate(X[, verbose])

Validates the fuzzy variable.

__init__(name, fuzzy_sets, units=None)[source]#

Creates a fuzzy variable with the specified fuzzy sets.

Parameters:
  • name (str) – Name of the fuzzy variable

  • fuzzy_sets (list[FS]) – List of fuzzy sets that comprise the linguistic variables

  • units (str, optional) – Units of the fuzzy variable for display purposes

Raises:

ValueError – If fuzzy_sets is empty or contains mixed types

Example

>>> fs1 = gaussianFS([0, 1], "Low", 10)
>>> fs2 = gaussianFS([5, 1], "High", 10)
>>> var = fuzzyVariable("Speed", [fs1, fs2], "m/s")
append(fs)[source]#

Appends a fuzzy set to the fuzzy variable.

Parameters:

fs (FS) – FS. Fuzzy set to append.

linguistic_variable_names()[source]#

Returns the name of the linguistic variables.

Returns:

list of strings.

Return type:

list

get_linguistic_variables()[source]#

Returns the name of the linguistic variables.

Returns:

list of strings.

Return type:

list[FS]

compute_memberships(x)[source]#

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

Parameters:

x (array) – 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.

Return type:

list

domain()[source]#

Returns the domain of the fuzzy variable.

Returns:

list of floats.

Return type:

list[float]

fuzzy_type()[source]#

Returns the fuzzy type of the domain

Returns:

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

Return type:

FUZZY_SETS

validate(X, verbose=False)[source]#

Validates the fuzzy variable. Checks that all the fuzzy sets have the same type and domain.

Parameters:

X – np.array. Input data to validate the fuzzy variable.

Returns:

bool. True if the fuzzy variable is valid, False otherwise.

Return type:

bool

__str__()[source]#

Returns the name of the fuzzy variable, its type and its parameters.

Returns:

string.

Return type:

str

__getitem__(item)[source]#

Returns the corresponding fs.

Parameters:

item – int. Index of the FS.

Returns:

FS. The corresponding FS.

Return type:

FS

__setitem__(item, elem)[source]#

Sets the corresponding fs.

Parameters:
  • item (int) – int. Index of the FS.

  • elem (FS) – FS. The FS to set.

__iter__()[source]#

Returns the corresponding fs.

Parameters:

item – int. Index of the FS.

Returns:

FS. The corresponding FS.

Return type:

Generator[FS, None, None]

__len__()[source]#

Returns the number of linguistic variables.

Returns:

int. Number of linguistic variables.

Return type:

int

__call__(x)[source]#

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

Parameters:

x (array) – numeric value or array.

Returns:

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

Return type:

list