fuzzy_dl_owl2.fuzzydl.concept.concrete.trapezoidal_concrete_concept

Implements a trapezoidal membership function for fuzzy logic concepts, defining degrees of membership based on specific geometric parameters.

Description

The software models a fuzzy logic concept using a trapezoidal membership function, where the degree of truth for a given value is determined by its position relative to four defining parameters. It enforces strict geometric constraints during initialization to ensure the shape parameters are ordered correctly and that the definition domain fully encompasses the support interval. Membership calculations return zero for values outside the support range, one for values within the core plateau, and linearly interpolated values for the rising and falling edges. Logical operations such as conjunction, disjunction, and negation are supported through operator overloading, which delegates the computation to a separate operator utility to maintain consistency across the fuzzy logic framework. The implementation also includes mechanisms for object cloning and hashing based on the specific configuration of the trapezoid, facilitating use in collections and data structures.

Classes

TrapezoidalConcreteConcept

This class represents a trapezoidal concrete concept within a fuzzy logic framework, defining a membership function that follows a trapezoidal shape. It is defined by a universe of discourse interval [k1, k2] and four shape parameters a, b, c, and d, which establish the support [a, d] and the core [b, c] of the concept. The membership degree is 0 for values less than or equal to a or greater than or equal to d, equals 1 for values between b and c, and transitions linearly for values in the intervals (a, b) and (c, d). To use this class, instantiate it with a descriptive name and the required float parameters, ensuring that the shape parameters adhere to the strict ordering a <= b <= c <= d and that the definition interval fully encompasses the support interval (k1 <= a and k2 >= d). The class provides functionality to calculate membership degrees, clone instances, and supports logical operations such as AND, OR, and NOT via operator overloading.

Module Contents

UML Class Diagram for TrapezoidalConcreteConcept

UML Class Diagram for TrapezoidalConcreteConcept

class TrapezoidalConcreteConcept(name: str, k1: float, k2: float, a: float, b: float, c: float, d: float)[source]

Bases: fuzzy_dl_owl2.fuzzydl.concept.concrete.fuzzy_concrete_concept.FuzzyConcreteConcept

Inheritance diagram of fuzzy_dl_owl2.fuzzydl.concept.concrete.trapezoidal_concrete_concept.TrapezoidalConcreteConcept

This class represents a trapezoidal concrete concept within a fuzzy logic framework, defining a membership function that follows a trapezoidal shape. It is defined by a universe of discourse interval [k1, k2] and four shape parameters a, b, c, and d, which establish the support [a, d] and the core [b, c] of the concept. The membership degree is 0 for values less than or equal to a or greater than or equal to d, equals 1 for values between b and c, and transitions linearly for values in the intervals (a, b) and (c, d). To use this class, instantiate it with a descriptive name and the required float parameters, ensuring that the shape parameters adhere to the strict ordering a <= b <= c <= d and that the definition interval fully encompasses the support interval (k1 <= a and k2 >= d). The class provides functionality to calculate membership degrees, clone instances, and supports logical operations such as AND, OR, and NOT via operator overloading.

Parameters:
  • name (str) – Identifier for the concept, used for identification and debugging purposes.

  • k1 (float) – The lower bound of the interval [k1, k2] defining the domain over which the concept is defined.

  • k2 (float) – The upper bound of the interval for which the concept is defined.

  • _a (float) – The lower bound of the support interval, marking the point where the membership degree begins to increase from zero.

  • _b (float) – The lower bound of the plateau region where the membership degree is 1.

  • _c (float) – The upper bound of the plateau where the membership degree is 1.

  • _d (float) – The upper bound of the interval for which the concept is satisfied, representing the point where the membership degree drops to zero.

__and__(value: Self) Self[source]

Performs a logical conjunction (AND) operation between the current instance and another instance of the same type, typically invoked via the & operator. The method delegates the core logic to the OperatorConcept.and_ function, returning a new instance that represents the result while leaving the original operands unchanged.

Parameters:

value (Self) – The right-hand operand to perform the AND operation with.

Returns:

The result of the AND operation between this instance and the provided value.

Return type:

Self

__hash__() int[source]

Computes the integer hash value for the instance, enabling its use as a key in dictionary lookups or membership in sets. The implementation derives the hash from the string representation of the object, meaning that two instances with identical string outputs will produce the same hash code. Because the hash is based on the string representation, the efficiency of this method is directly tied to the performance of the __str__ method, and any mutation that alters the string output will result in a different hash value.

Returns:

An integer hash value derived from the string representation of the object.

Return type:

int

__neg__() fuzzy_dl_owl2.fuzzydl.concept.concrete.fuzzy_concrete_concept.FuzzyConcreteConcept[source]

Implements the unary negation operator for the trapezoidal fuzzy concept, returning a new concept that represents the logical complement of the current instance. This operation delegates the calculation to the not_ method of the OperatorConcept class, effectively inverting the membership function. The method does not modify the original object but instead produces a new FuzzyConcreteConcept instance reflecting the negated state.

Returns:

Returns the logical negation of the current concept.

Return type:

FuzzyConcreteConcept

__or__(value: Self) Self[source]

Implements the bitwise OR operation for the concept, allowing the use of the pipe operator (|) to combine two instances. This method delegates the logic to the OperatorConcept.or_ method, which computes the logical disjunction between the current object and the provided value. It returns a new instance of the same type representing the result of the operation, leaving the original operands unchanged.

Parameters:

value (Self) – The right-hand operand to combine with the current instance using the OR operator.

Returns:

The result of the OR operation between the current instance and the provided value.

Return type:

Self

clone() Self[source]

Creates and returns a new instance that is an independent copy of the current object. The method instantiates a new object using the current values of the name, k1, k2, a, b, c, and d attributes. This operation has no side effects on the original instance, ensuring that modifications to the returned copy do not affect the source data.

Returns:

A new instance of the class initialized with the same attribute values as the current object.

Return type:

Self

compute_name() str[source]

Constructs a human-readable string identifier that encapsulates the specific parameters of the trapezoidal concept. The output is formatted as a function-like string containing the values of the six defining attributes—k1, k2, a, b, c, and d—enclosed in parentheses. This method relies on the existence of these instance attributes and will raise an error if any are undefined.

Returns:

A string representation of the trapezoidal configuration with the current parameter values.

Return type:

str

get_membership_degree(x: float) float[source]

Computes the degree of membership for a given input value within a trapezoidal fuzzy set defined by the instance’s boundary parameters. The function returns 0.0 if the input lies outside the range defined by the lower and upper bounds, and returns 1.0 if the input falls within the central plateau. For values located on the rising or falling edges of the trapezoid, the method performs linear interpolation to return a fractional membership value between 0.0 and 1.0. This calculation is stateless and does not modify the object’s attributes.

Parameters:

x (float) – The input value to evaluate against the membership function.

Returns:

The degree of membership of the input value x, ranging from 0.0 to 1.0.

Return type:

float

_a: float
_b: float
_c: float
_d: float
property a: float

Sets the value of the property ‘a’, representing a specific geometric dimension of the trapezoidal concrete concept. The method accepts a numeric input, casts it to a float, and stores the result in the private attribute _a. This type conversion ensures that the internal state maintains floating-point precision for subsequent calculations, even if an integer or compatible numeric type is provided.

Parameters:

value (float) – The value to assign to the attribute, converted to a float.

property b: float

Sets the dimension represented by ‘b’ for the trapezoidal concrete concept, typically corresponding to a width or base length. The method accepts a value, explicitly converts it to a float, and assigns it to the internal attribute _b. This ensures the underlying data type remains consistent, though providing a value that cannot be converted to a float will raise an error.

Parameters:

value (float) – The new value to assign to the b attribute.

property c: float

Assigns the specified value to the property ‘c’, which corresponds to a geometric dimension of the trapezoidal concrete concept. The input is explicitly cast to a float to maintain numerical precision and stored in the private attribute _c. This setter modifies the object’s state and may raise a TypeError or ValueError if the provided value cannot be converted to a float.

Parameters:

value (float) – The new value to assign to the property, converted to a float.

property d: float

Sets the depth dimension of the trapezoidal concrete concept. This method serves as the setter for the d property, converting the provided value to a float and storing it in the private _d attribute. While this ensures the internal state is always a float, passing a non-numeric value will result in a ValueError or TypeError during the conversion process.

Parameters:

value (float) – The numeric value to assign to the attribute, converted to a float.

k1: float

Sets the value of the k1 attribute for the instance, converting the input to a float to ensure type consistency. This method updates the private _k1 variable, effectively modifying the internal state of the FuzzyConcreteConcept object. Any subsequent operations relying on this parameter will reflect the new value.

Parameters:

value (float) – The new value for the k1 attribute.

k2: float

Sets the upper bound parameter k2 for the fuzzy concrete concept. This method enforces a constraint ensuring that the new value is greater than or equal to the existing k1 parameter; if k1 is larger than the provided value, a ValueError is raised. Upon successful validation, the input is converted to a float and stored in the internal state.

Parameters:

value (float) – The value to assign to the k2 parameter, which must be greater than or equal to k1.

Raises:

ValueError – Raised if the provided value is less than k1, as k2 must be greater than or equal to k1.

name: str

Updates the name of the Concept instance to the specified string value. This setter modifies the object’s internal state by assigning the provided value to the private _name attribute, effectively replacing any previously stored name.

Parameters:

value (str) – The new name to assign to the object.