fuzzy_dl_owl2.fuzzydl.concept.concrete.linear_concrete_concept
A fuzzy concept implementation that models a piecewise linear membership function operating on a normalized domain between zero and one.
Description
The implementation extends the base fuzzy concrete concept to represent a specific type of membership function characterized by a piecewise linear shape. It relies on a normalized domain ranging from zero to one, where the shape of the function is determined by a specific “knee” point defined by parameters a and b, creating a linear ramp from the origin to this point and a second ramp to the maximum value. While the constructor accepts interval bounds, the core membership calculation logic strictly utilizes the normalized input and the internal coefficients to determine the degree of truth through linear interpolation. Validation logic ensures that the definition parameters adhere to mathematical constraints, specifically requiring that the lower bound does not exceed the threshold and that the membership degree at the threshold remains within valid limits. Beyond calculating membership degrees, the design integrates with broader fuzzy logic operations by delegating tasks like negation, conjunction, and disjunction to an external operator handler to support complex logical expressions.
Classes
This class models a fuzzy concept characterized by a piecewise linear membership function operating on a normalized domain from 0 to 1. The function is defined by a specific "knee" point determined by parameters a and b, creating a linear ramp from (0, 0) to (a, b) and a second linear ramp from (a, b) to (1, 1). While the constructor accepts parameters k1 and k2 to denote the definition interval, the membership calculation logic strictly relies on the normalized input value and the a and b parameters. To use this class, instantiate it with a name and the required float parameters, ensuring that k1 is less than or equal to a and b does not exceed 1.0 to avoid validation errors. Once instantiated, the membership degree of a specific value can be retrieved using the get_membership_degree method, and the object supports standard fuzzy logic operations such as negation, conjunction, and disjunction. |
Module Contents
UML Class Diagram for LinearConcreteConcept
- class LinearConcreteConcept(name: str, k1: float, k2: float, a: float, b: float)[source]
Bases:
fuzzy_dl_owl2.fuzzydl.concept.concrete.fuzzy_concrete_concept.FuzzyConcreteConcept
This class models a fuzzy concept characterized by a piecewise linear membership function operating on a normalized domain from 0 to 1. The function is defined by a specific “knee” point determined by parameters a and b, creating a linear ramp from (0, 0) to (a, b) and a second linear ramp from (a, b) to (1, 1). While the constructor accepts parameters k1 and k2 to denote the definition interval, the membership calculation logic strictly relies on the normalized input value and the a and b parameters. To use this class, instantiate it with a name and the required float parameters, ensuring that k1 is less than or equal to a and b does not exceed 1.0 to avoid validation errors. Once instantiated, the membership degree of a specific value can be retrieved using the get_membership_degree method, and the object supports standard fuzzy logic operations such as negation, conjunction, and disjunction.
- Parameters:
k1 (float) – Lower bound of the interval for 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 interval for which the concept is satisfied, acting as a threshold in the piecewise linear membership function.
_b (float) – The membership degree at the threshold a, defining the slope of the linear membership function. Must be less than or equal to 1.0.
- __and__(value: Self) Self[source]
Computes the logical conjunction or intersection of the current concept with another instance of the same type. This method enables the use of the bitwise AND operator (&) to combine concepts, delegating the specific logic to the OperatorConcept.and_ method. The operation returns a new instance representing the result, leaving the original operands unchanged.
- Parameters:
value (Self) – The right-hand operand for the AND operation, which must be an instance of the same type.
- Returns:
The result of the AND operation between this instance and the provided value.
- Return type:
Self
- __hash__() int[source]
Computes the hash value for the instance based on its string representation, enabling the object to be used as a key in dictionaries or as a member of sets. The implementation delegates to the built-in hash function applied to the result of str(self), meaning the hash value is intrinsically linked to the object’s string output. Consequently, if the object is mutable and its string representation changes during its lifetime, the hash value will also change, which violates the standard contract for hashable objects and can lead to errors if the instance is used as a dictionary key after modification. Furthermore, the efficiency of this operation depends on the computational cost of generating the string representation.
- Returns:
An integer hash value computed 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, allowing the concept to be inverted using the - prefix. This method delegates the logic to OperatorConcept.not_ to compute the logical complement of the current instance. The operation returns a new FuzzyConcreteConcept representing the negation, rather than modifying the original object.
- Returns:
A new FuzzyConcreteConcept representing the logical negation of the current concept.
- Return type:
- __or__(value: Self) Self[source]
Performs a logical OR operation between the current concept and another concept of the same type. This method enables the use of the pipe operator (|) to combine concepts, delegating the underlying logic to the OperatorConcept.or_ method. It returns a new instance 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 operation.
- Returns:
Returns a new instance representing the logical OR of this object and the provided value.
- Return type:
Self
- clone() Self[source]
Creates and returns a new instance of the class that is a distinct copy of the current object. This method initializes the new instance using the values of the name, k1, k2, a, and b attributes from the original object. The operation does not modify the state of the existing instance, ensuring that the original and the clone are independent objects with identical initial 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 descriptive name for the linear concept instance by interpolating its key parameters into a standardized string format. The method retrieves the values of k1, k2, a, and b from the instance state and returns them formatted as “linear(k1, k2, a, b)”. This function is purely deterministic and has no side effects, relying solely on the current state of the object’s attributes.
- Returns:
A string representation of the linear function formatted with the current parameters.
- Return type:
str
- get_membership_degree(value: float) float[source]
Calculates the degree of membership for a given input value based on a piecewise linear function defined by the concept’s parameters. The input is treated as a normalized value, where any input less than or equal to zero results in a membership of 0.0, and any input greater than or equal to one results in a membership of 1.0. Between zero and the internal threshold self.a, the membership increases linearly from 0.0 to self.b. For values between self.a and 1.0, the membership increases linearly from self.b to 1.0. This method does not modify the state of the object.
- Parameters:
value (float) – The input value to evaluate against the membership function. Values less than or equal to 0 return 0, and values greater than or equal to 1 return 1.
- Returns:
The calculated degree of membership for the input value, bounded between 0.0 and 1.0.
- Return type:
float
- _a: float
- _b: float
- property a: float
Sets the value of the coefficient ‘a’ for the linear concept. This method accepts a value, converts it to a float, and assigns it to the internal attribute _a. It ensures type consistency by forcing the storage format to be a float, which may raise a ValueError or TypeError if the input is not a valid number. Modifying this property updates the internal state of the object, which may influence subsequent calculations or behaviors relying on this coefficient.
- Parameters:
value (float) – The new value to assign to the internal attribute, converted to a float.
- property b: float
Updates the internal state of the instance by assigning a new value to the underlying attribute. The input is coerced to a floating-point number before storage to ensure type consistency, regardless of whether the original input was an integer or a numeric string. This setter modifies the private attribute _b and will propagate standard exceptions if the provided value cannot be converted to a float.
- Parameters:
value (float) – The new value for the ‘b’ 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.