fuzzy_dl_owl2.fuzzydl.modifier.triangular_modifier

A fuzzy logic modifier that applies a triangular membership function to concepts based on three defining parameters.

Description

The software implements a specific type of fuzzy logic modifier characterized by a triangular membership function, which determines the degree to which a value belongs to a concept based on three distinct parameters: a left boundary, a peak, and a right boundary. By enforcing the constraint that the left boundary must be less than or equal to the peak, which in turn must be less than or equal to the right boundary, the implementation ensures a valid geometric shape where membership increases linearly from zero to one and then decreases back to zero. When applied to a base concept, the logic wraps the original entity into a specialized structure that incorporates these triangular characteristics, allowing for the dynamic calculation of membership degrees for any given input value. Furthermore, the design supports logical composition by overloading standard operators to perform conjunctions, disjunctions, and negations, effectively enabling the combination of multiple triangular modifiers into complex fuzzy expressions.

Classes

TriangularModifier

This class implements a fuzzy logic modifier that applies a triangular membership function to concepts, defining how strongly a specific value belongs to a modified concept. The function is characterized by three parameters: the left boundary a, the peak b, and the right boundary c, which must satisfy the ordering $a le b le c$. Membership degrees increase linearly from 0 at a to 1 at b, and then decrease linearly back to 0 at c. To utilize this modifier, instantiate it with a name and the three boundary values, and then apply it to a Concept instance via the modify method, which produces a TriangularlyModifiedConcept. The class also provides a get_membership_degree method for calculating the specific membership value of a given input.

Module Contents

UML Class Diagram for TriangularModifier

UML Class Diagram for TriangularModifier

class TriangularModifier(name: str, a: float, b: float, c: float)[source]

Bases: fuzzy_dl_owl2.fuzzydl.modifier.modifier.Modifier

Inheritance diagram of fuzzy_dl_owl2.fuzzydl.modifier.triangular_modifier.TriangularModifier
Parameters:
  • _a (Any) – The left endpoint of the triangular membership function, marking the lower bound where the membership degree begins to increase from zero.

  • _b (Any) – The x-coordinate of the peak of the triangular membership function, representing the point of maximum membership degree.

  • _c (Any) – The right endpoint of the triangular membership function, defining the upper bound where the membership degree reaches zero.

__and__(value: Self) Self[source]

Implements the bitwise AND operation (&) for the TriangularModifier class, enabling logical conjunction between the current instance and another of the same type. This method delegates the underlying logic to OperatorConcept.and_ and returns a new TriangularModifier instance representing the combined result, ensuring that the operation does not modify the original operands in place.

Parameters:

value (Self) – The right-hand operand for the AND operation, which must be an instance of the same class.

Returns:

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

Return type:

Self

__hash__() int[source]

Computes an integer hash value for the instance by hashing the string representation of the object. This implementation allows the object to be used as a key in dictionaries or as a member of sets, provided the string representation remains consistent throughout the object’s lifetime. The resulting hash is entirely dependent on the output of the __str__ method, meaning any changes to the string representation will alter the hash value.

Returns:

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

Return type:

int

__neg__() fuzzy_dl_owl2.fuzzydl.concept.concept.Concept[source]

Implements the unary negation operator, enabling the use of the minus sign to invert the logic of the triangular modifier. This method returns a new Concept instance representing the logical complement of the current modifier by delegating to OperatorConcept.not_. The operation is non-destructive, leaving the original modifier unchanged while generating a distinct conceptual entity that encapsulates the negation.

Returns:

A Concept representing the logical negation of the current instance.

Return type:

Concept

__or__(value: Self) Self[source]

Implements the bitwise OR operation using the pipe operator (|) to combine the current instance with another TriangularModifier. This method delegates the logic to OperatorConcept.or_, which calculates the union of the two modifiers based on the underlying concept definitions. It returns a new instance of TriangularModifier representing the combined result, ensuring that the original operands remain unmodified.

Parameters:

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

Returns:

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

Return type:

Self

clone() Self[source]

Creates and returns a new instance of the class that is a copy of the current object. This method instantiates a new object using the current values of the name, a, b, and c attributes, ensuring that the returned modifier has the same configuration as the original. The operation has no side effects on the existing instance.

Returns:

A new instance of the class with identical attributes to the current instance.

Return type:

Self

compute_name() str[source]

Generates a standardized string representation for the triangular modifier instance based on its defining parameters. The returned value follows the format ‘triangular-modifier(a, b, c)’, incorporating the current values of the instance’s attributes a, b, and c. This method does not modify the object’s state and is primarily useful for logging, debugging, or identifying specific modifier configurations.

Returns:

A string representing the name of the triangular modifier, formatted with the values of a, b, and c.

Return type:

str

get_membership_degree(x: float) float[source]

Calculates the degree of membership for a given input value x within a triangular fuzzy set defined by the parameters a, b, and c. The function returns 0.0 if the input lies outside the interval [a, c]. For values between a and the peak b, the membership increases linearly, while values between b and c result in a linear decrease. This method performs a pure calculation without modifying internal state or causing side effects.

Parameters:

x (float) – The input value for which to calculate the membership degree.

Returns:

The degree of membership of the input value x to the fuzzy set, ranging from 0.0 (no membership) to 1.0 (full membership).

Return type:

float

modify(concept: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept) fuzzy_dl_owl2.fuzzydl.concept.concept.Concept[source]

Applies the triangular modification logic encapsulated by this instance to the provided concept. This method does not mutate the original concept directly; instead, it creates and returns a new TriangularlyModifiedConcept wrapper that combines the original concept with the current modifier. This allows the modified concept to be evaluated or processed with the specific triangular characteristics defined by the modifier.

Parameters:

concept (Concept) – The concept to be modified.

Returns:

A new Concept instance that wraps the provided concept and applies a triangular modification using the current object.

Return type:

Concept

_a
_b
_c
property a: float

Updates the internal state of the object by setting the value of the private attribute _a to the provided floating-point number. This method serves as the setter for the ‘a’ property, allowing external modification of this specific parameter within the TriangularModifier context. Since the implementation performs a direct assignment, side effects are limited to the mutation of the instance’s internal state, though the validity of the new value relative to other constraints is not enforced within this specific method.

Parameters:

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

property b: float

Updates the internal configuration of the TriangularModifier by setting the value of the parameter b. This property setter accepts a floating-point number and assigns it directly to the private attribute _b. While this specific implementation performs no validation or triggers immediate side effects, modifying this value changes the state of the object, which will influence the behavior of any subsequent operations that rely on the b parameter.

Parameters:

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

property c: float

Sets the value of the parameter ‘c’ for the triangular modifier. This method acts as a property setter, assigning the provided floating-point value to the internal _c attribute. By updating this attribute, the method modifies the internal state of the instance, which may influence subsequent calculations or behaviors relying on this parameter.

Parameters:

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