fuzzy_dl_owl2.fuzzydl.modifier.linear_modifier

A fuzzy logic modifier that applies a configurable piecewise linear transformation to the membership degrees of concepts.

Description

Software designed to adjust the intensity of fuzzy concepts by mapping input membership values through a piecewise linear function. The transformation is governed by a single coefficient that determines the slope and intercept of the function, allowing for precise control over how membership degrees are scaled. By deriving internal parameters from this coefficient, the implementation ensures that the resulting values remain strictly bounded between 0 and 1, effectively clamping inputs that fall outside the valid range. Integration with the broader fuzzy logic framework is achieved through the ability to wrap existing concepts into modified forms and support standard logical operators such as negation, conjunction, and disjunction.

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]

Computes the integer hash value for the LinearModifier 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 the hashing logic to the result of str(self), ensuring that two instances with identical string representations produce the same hash. However, because the hash is derived from the string form, any changes to the object’s state that alter its string representation will result in a different hash value, which violates the immutability requirement for objects used in hashed collections and may lead to lookup errors.

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 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

Sets the value of the ‘a’ coefficient for the linear modifier. This method updates the object’s internal state by assigning the provided floating-point value to the private attribute _a. It allows the linear parameter to be modified dynamically after the object has been initialized.

Parameters:

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

property b: float

Sets the internal coefficient ‘b’ for the linear modifier to the specified floating-point value. This method updates the object’s state by assigning the input directly to the private attribute _b. Since no validation logic is present in the implementation, any float value is accepted, potentially including edge cases like infinity or NaN.

Parameters:

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

property c: float

Updates the value of the ‘c’ property, which likely represents a constant term or coefficient in the linear modification logic. This setter assigns the provided floating-point value to the internal _c attribute, thereby modifying the object’s state. Since the implementation performs a direct assignment without explicit type enforcement, passing incompatible types may result in unexpected behavior during subsequent calculations that rely on this value.

Parameters:

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