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.
- fs_type#
Type of fuzzy sets (t1 or t2)
- Type:
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:
- 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.
Computes the membership to each of the FS in the fuzzy variables.
domain
()Returns the domain of the fuzzy variable.
Returns the fuzzy type of the domain
Returns the name of the linguistic variables.
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:
- 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:
- 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:
- fuzzy_type()[source]#
Returns the fuzzy type of the domain
- Returns:
the type of the fuzzy set present in the fuzzy variable.
- Return type:
- 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:
- __str__()[source]#
Returns the name of the fuzzy variable, its type and its parameters.
- Returns:
string.
- Return type:
- __getitem__(item)[source]#
Returns the corresponding fs.
- Parameters:
item – int. Index of the FS.
- Returns:
FS. The corresponding FS.
- Return type: