fuzzy_dl_owl2.fuzzydl.modifier.linear_modifier

Implements a fuzzy logic modifier that transforms concept membership degrees using a configurable piecewise linear function.

Description

The software defines a mechanism for altering the membership degrees of fuzzy concepts through a piecewise linear transformation, controlled by a single shape coefficient. Upon initialization, the coefficient is used to derive two internal weights that define the inflection point and slope of the transformation, ensuring the output remains normalized within the zero-to-one range. When applied to a concept, the logic generates a specialized wrapper object that encapsulates both the original concept and the transformation rules, allowing the modified membership to be calculated dynamically based on input values. To support complex logical reasoning, the implementation includes operator overloading for conjunction, disjunction, and negation, delegating these operations to a central factory for concept construction while maintaining immutability of the original modifier.

Classes

LinearModifier

This class implements a modifier that applies a piecewise linear transformation to the membership degrees of concepts, governed by a configurable parameter 'c'. The value of 'c' determines the inflection point of the linear function, allowing for precise control over the intensity of the modification. To use this class, instantiate it with a name and the desired 'c' value, then apply it to a Concept object using the modify method to produce a LinearlyModifiedConcept. The logic ensures that membership degrees are clamped between 0 and 1, and the class supports logical operations such as negation, conjunction, and disjunction.

Module Contents

UML Class Diagram for LinearModifier

UML Class Diagram for LinearModifier

class LinearModifier(name: str, c: float)[source]

Bases: fuzzy_dl_owl2.fuzzydl.modifier.modifier.Modifier

Inheritance diagram of fuzzy_dl_owl2.fuzzydl.modifier.linear_modifier.LinearModifier

This class implements a modifier that applies a piecewise linear transformation to the membership degrees of concepts, governed by a configurable parameter ‘c’. The value of ‘c’ determines the inflection point of the linear function, allowing for precise control over the intensity of the modification. To use this class, instantiate it with a name and the desired ‘c’ value, then apply it to a Concept object using the modify method to produce a LinearlyModifiedConcept. The logic ensures that membership degrees are clamped between 0 and 1, and the class supports logical operations such as negation, conjunction, and disjunction.

Parameters:
  • _c (float) – The parameter determining the slope and intercept of the linear membership function.

  • _a (float) – The threshold value on the input domain that separates the two linear segments of the membership function.

  • _b (float) – The y-coordinate of the intermediate point $(a, b)$ in the piecewise linear membership function.

__and__(value: Self) Self[source]

Implements the bitwise AND operation (&) for the LinearModifier class, enabling the combination of the current instance with another instance of the same type. This method delegates the specific logic for the conjunction to OperatorConcept.and_, which determines how the two modifiers interact. The operation returns a new LinearModifier instance representing the result, ensuring that the original operands are not modified.

Parameters:

value (Self) – The right-hand operand for the AND operation.

Returns:

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

Return type:

Self

__hash__() int[source]

Return a hash value for this object, computed from its string representation. This approach ensures that the hash value reflects the structural identity of the object without relying on cached values or additional methods. The hash is derived from the output of the __str__ method, which provides a consistent and unique representation of the concept’s structure. This implementation does not utilize any internal caching mechanism and directly computes the hash each time it is called.

Returns:

An integer hash value representing the structural identity of this object.

Return type:

int

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

Implements the unary negation operator for the LinearModifier instance, returning a new Concept that represents the logical negation of the current modifier. This operation delegates the creation of the negated concept to the OperatorConcept.not_ factory method, ensuring that the resulting object encapsulates the inverse logic without modifying the original instance.

Returns:

A Concept representing the logical negation of the current instance.

Return type:

Concept

__or__(value: Self) Self[source]

Implements the bitwise OR operation for the LinearModifier class, allowing instances to be combined using the pipe operator (|). This method takes another LinearModifier instance and delegates the combination logic to OperatorConcept.or_, returning a new instance that represents the result of the operation. The original instances remain unmodified, ensuring that the operation is side-effect-free.

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 the current instance and the provided value.

Return type:

Self

clone() Self[source]

Creates and returns a new instance of LinearModifier that is a copy of the current object. The clone is initialized with the same name and c attributes as the original, resulting in an independent object that can be modified without affecting the source.

Returns:

A new instance of the class that is a copy of the current object.

Return type:

Self

compute_name() str[source]

Generates a string identifier for the linear modifier based on its coefficient attribute. The returned string follows the specific format “linear-modifier(c)”, where ‘c’ is replaced by the string representation of the instance’s ‘c’ attribute. This method performs no state modification and assumes the ‘c’ attribute is defined and convertible to a string.

Returns:

A string representing the name of the linear modifier, formatted as ‘linear-modifier({c})’.

Return type:

str

get_membership_degree(value: float) float[source]

Calculates the degree of membership for a given input value using a piecewise linear function defined by the instance attributes a and b. The function maps the input range [0, 1] to an output range [0, 1], clamping any values outside this interval to the nearest boundary. Specifically, for inputs between 0 and a, the result is linearly interpolated from 0 to b, whereas inputs between a and 1 are interpolated from b to 1. This method does not modify the state of the object.

Parameters:

value (float) – The crisp input value for which to calculate the membership degree. Values outside the range [0, 1] are clamped to the nearest boundary.

Returns:

A float representing the degree of membership for the input value, ranging from 0.0 to 1.0.

Return type:

float

modify(
concept: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept,
) fuzzy_dl_owl2.fuzzydl.concept.modified.linearly_modified_concept.LinearlyModifiedConcept[source]

Applies the linear modification logic encapsulated by this instance to a provided concept. This method constructs and returns a new LinearlyModifiedConcept object that wraps the original concept alongside the current modifier, effectively binding the two without mutating the original concept.

Parameters:

concept (Concept) – The Concept instance to be modified.

Returns:

A LinearlyModifiedConcept representing the input concept modified by the current object.

Return type:

LinearlyModifiedConcept

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

Returns the first derived weight of the linear modifier, computed at construction as c / (c + 1). Together with b it forms the pair of weights (summing to 1) that define the piecewise-linear membership transformation. The value is read from the private _a attribute without modifying the instance.

Returns:

The derived weight a of the modifier.

Return type:

float

property b: float

Returns the second derived weight of the linear modifier, computed at construction as 1 / (c + 1). Together with a it forms the pair of weights (summing to 1) that define the piecewise-linear membership transformation. The value is read from the private _b attribute without modifying the instance.

Returns:

The derived weight b of the modifier.

Return type:

float

property c: float

Returns the shape coefficient c of the linear modifier, the single parameter from which the derived weights a and b are computed and which controls the intensity of the modification. The value is read from the private _c attribute without modifying the instance.

Returns:

The shape coefficient c of the modifier.

Return type:

float