ex_fuzzy.fuzzy_sets.FS#
- class ex_fuzzy.fuzzy_sets.FS(name, membership_parameters, domain)[source]#
Bases:
object
Base class for Type-1 fuzzy sets (Zadeh fuzzy sets).
This class implements the fundamental Type-1 fuzzy set with crisp membership functions. It serves as the base class for more specialized fuzzy set types like triangular, gaussian, and categorical fuzzy sets.
Example
>>> fs = FS("medium", [1, 2, 3, 4], [0, 5]) # Trapezoidal fuzzy set >>> membership = fs.membership(2.5) >>> print(membership) # Should be 1.0 (fully in the set)
Note
This class uses trapezoidal membership functions by default. For other shapes, use specialized subclasses like gaussianFS or triangularFS.
- __init__(name, membership_parameters, domain)[source]#
Initialize a Type-1 fuzzy set.
- Parameters:
name (str) – Linguistic name for the fuzzy set
membership_parameters (list[float]) – Four parameters [a, b, c, d] defining the trapezoidal membership function where: - a: left foot (membership starts rising from 0) - b: left shoulder (membership reaches 1.0) - c: right shoulder (membership starts falling from 1.0) - d: right foot (membership reaches 0)
domain (list[float]) – Two-element list [min, max] defining the universe of discourse for this fuzzy set
Example
>>> fs = FS("medium", [2, 3, 7, 8], [0, 10]) >>> # Creates a trapezoidal set: rises from 2-3, flat 3-7, falls 7-8
Methods
__init__
(name, membership_parameters, domain)Initialize a Type-1 fuzzy set.
membership
(x)Compute membership degrees for input values.
shape
()Returns the shape of the fuzzy set.
type
()Return the fuzzy set type identifier.
- __init__(name, membership_parameters, domain)[source]#
Initialize a Type-1 fuzzy set.
- Parameters:
name (str) – Linguistic name for the fuzzy set
membership_parameters (list[float]) – Four parameters [a, b, c, d] defining the trapezoidal membership function where: - a: left foot (membership starts rising from 0) - b: left shoulder (membership reaches 1.0) - c: right shoulder (membership starts falling from 1.0) - d: right foot (membership reaches 0)
domain (list[float]) – Two-element list [min, max] defining the universe of discourse for this fuzzy set
Example
>>> fs = FS("medium", [2, 3, 7, 8], [0, 10]) >>> # Creates a trapezoidal set: rises from 2-3, flat 3-7, falls 7-8
- membership(x)[source]#
Compute membership degrees for input values.
This method calculates the membership degree(s) for the given input value(s) using the trapezoidal membership function defined by this fuzzy set’s parameters.
- Parameters:
x (np.array) – Input value(s) for which to compute membership degrees. Can be a single value, list, or numpy array.
- Returns:
Membership degree(s) in the range [0, 1]. Shape matches input.
- Return type:
np.array
Example
>>> fs = FS("medium", [2, 3, 7, 8], [0, 10]) >>> print(fs.membership(5)) # 1.0 (in flat region) >>> print(fs.membership(2.5)) # 0.5 (on rising slope) >>> print(fs.membership([1, 5, 9])) # [0.0, 1.0, 0.0]
- type()[source]#
Return the fuzzy set type identifier.
- Returns:
The type identifier (FUZZY_SETS.t1 for Type-1 fuzzy sets)
- Return type:
- __call__(x)[source]#
Calling the Fuzzy set returns its membership.
- Parameters:
x (array) – input values in the fuzzy set referencial domain.
- Returns:
membership of the fuzzy set.
- Return type:
array