_fpt_operators

These are the co-norms etc.

This module contains a set of fuzzy logic operators designed for use with Zuffy, suitable for constructing Fuzzy Pattern Trees (FPT). Each operator performs a specific mathematical operation on NumPy arrays, representing fuzzy set memberships.

The functions can be organised thus:
  1. Basic Fuzzy Operators
    • _minimum (MINIMUM/and)

    • _maximum (MAXIMUM/or)

    • _complement (COMPLEMENT/not)

  2. Linguistic Hedges
    • _diluter (DILUTER)

    • _diluter_power (used by DILUTER3, DILUTER4)

    • _concentrator (CONCENTRATOR)

    • _concentrator_power (used by CONCENTRATOR3, CONCENTRATOR4)

    • _intensifier (INTENSIFIER)

    • _diffuser (DIFFUSER)

  3. Averaging Operators
    • _weighted_average (used by WA_P1 to WA_P9)

    • _ordered_weighted_average (used by OWA_P1 to OWA_P9)

  4. T-Norms and T-Conorms
    • _fuzzy_and (FUZZY_AND - specifically product t-norm)

    • _fuzzy_or (FUZZY_OR - specifically probabilistic sum t-conorm)

    • _lukasiewicz_t_norm (LUKASIEWICZ/AND)

    • _lukasiewicz_t_conorm (LUKASIEWICZ/OR)

    • _hamacher_t_norm (used by HAMACHER025, HAMACHER050)

    • _product_t_norm (PRODUCT)

  5. Conditional Operators
    • _if_gte (IFGTE)

    • _if_gte_else (IFGTE2)

    • _if_lt (IFLT)

    • _if_lt_else (IFLT2)

zuffy._fpt_operators._complement(x0: ndarray | float) ndarray | float[source]

Calculates the fuzzy complement (1.0 - x0).

Parameters

x0np.ndarray or float

The fuzzy set membership value or array.

Returns

np.ndarray or float

The result of the fuzzy complement operation.

zuffy._fpt_operators._concentrator(x0: ndarray | float) ndarray | float[source]

Applies a Concentrator operation (squaring) to fuzzy set memberships. Typically used to “sharpen” or narrow the meaning of a fuzzy set.

Parameters

x0np.ndarray or float

The input fuzzy set membership value or array.

Returns

np.ndarray or float

The result of the concentration (squaring) operation.

zuffy._fpt_operators._concentrator_power(x0: ndarray | float, power: int) ndarray | float[source]

Applies a generalized Concentrator operation (x0^power) to fuzzy set memberships.

Parameters

x0np.ndarray or float

The input fuzzy set membership value or array.

powerint

The integer power to raise x0 to (e.g., 3 for cubing, 4 for power of 4).

Returns

np.ndarray or float

The result of the concentration operation.

zuffy._fpt_operators._diffuser(x0: ndarray | float) ndarray | float[source]

Applies a Diffuser linguistic hedge (from “Expanding the definitions of linguistic hedges”). This operation decreases membership values above 0.5 and increases those below 0.5, making the set “less true” or “fuzzier”.

Parameters

x0np.ndarray or float

The input fuzzy set membership value or array.

Returns

np.ndarray or float

The result of the diffuser operation.

zuffy._fpt_operators._diluter(x0: ndarray | float) ndarray | float[source]

Applies a Diluter operation (square root) to fuzzy set memberships. Typically used to “fuzzify” or expand the meaning of a fuzzy set. Ensures non-negative output for non-negative input.

Parameters

x0np.ndarray or float

The input fuzzy set membership value or array.

Returns

np.ndarray or float

The result of the dilution (square root) operation.

zuffy._fpt_operators._diluter_power(x0: ndarray | float, power: float) ndarray | float[source]

Applies a generalized Diluter operation (x0^power) to fuzzy set memberships. Ensures non-negative output for non-negative input.

Parameters

x0np.ndarray or float

The input fuzzy set membership value or array.

powerfloat

The power to raise x0 to (e.g., 1/3 for cube root, 0.25 for fourth root).

Returns

np.ndarray or float

The result of the dilution operation.

zuffy._fpt_operators._fuzzy_and(a: ndarray | float, b: ndarray | float) ndarray | float[source]

Calculates the fuzzy AND using the product (a * b) t-norm.

Parameters

anp.ndarray or float

The first fuzzy set membership value or array.

bnp.ndarray or float

The second fuzzy set membership value or array.

Returns

np.ndarray or float

The result of the fuzzy AND operation.

zuffy._fpt_operators._fuzzy_or(a: ndarray | float, b: ndarray | float) ndarray | float[source]

Calculates the fuzzy OR using the probabilistic sum (a + b - a*b) t-conorm.

Parameters

anp.ndarray or float

The first fuzzy set membership value or array.

bnp.ndarray or float

The second fuzzy set membership value or array.

Returns

np.ndarray or float

The result of the fuzzy OR operation.

zuffy._fpt_operators._generate_owa_operator(param: float)[source]

Generates a gplearn-compatible OWA operator with a fixed weight.

zuffy._fpt_operators._generate_wa_operator(param: float)[source]

Generates a gplearn-compatible WA operator with a fixed weight.

zuffy._fpt_operators._hamacher_t_norm(x0: ndarray | float, x1: ndarray | float, lambda_param: float) ndarray | float[source]

Computes the Hamacher T-norm.

Parameters

x0np.ndarray or float

First value, should be in the range [0, 1].

x1np.ndarray or float

Second value, should be in the range [0, 1].

lambda_paramfloat

Parameter lambda, should be >= 0.

Returns

np.ndarray or float

The Hamacher T-norm of x0 and x1.

Raises

ValueError

If lambda_param is negative.

zuffy._fpt_operators._if_gte(x1: ndarray | float, x2: ndarray | float) ndarray | float[source]

Returns x1 if x1 >= x2, otherwise returns x2.

Parameters

x1np.ndarray or float

The first operand.

x2np.ndarray or float

The second operand (threshold).

Returns

np.ndarray or float

The result based on the condition.

zuffy._fpt_operators._if_gte_else(x1: ndarray | float, x2: ndarray | float, x3: ndarray | float, x4: ndarray | float) ndarray | float[source]

Returns x3 if x1 >= x2, otherwise returns x4.

Parameters

x1np.ndarray or float

The comparison value.

x2np.ndarray or float

The threshold value.

x3np.ndarray or float

The value to return if the condition is true.

x4np.ndarray or float

The value to return if the condition is false.

Returns

np.ndarray or float

The result based on the condition.

zuffy._fpt_operators._if_lt(x1: ndarray | float, x2: ndarray | float) ndarray | float[source]

Returns x1 if x1 < x2, otherwise returns x2.

Parameters

x1np.ndarray or float

The first operand.

x2np.ndarray or float

The second operand (threshold).

Returns

np.ndarray or float

The result based on the condition.

zuffy._fpt_operators._if_lt_else(x1: ndarray | float, x2: ndarray | float, x3: ndarray | float, x4: ndarray | float) ndarray | float[source]

Returns x3 if x1 < x2, otherwise returns x4.

Parameters

x1np.ndarray or float

The comparison value.

x2np.ndarray or float

The threshold value.

x3np.ndarray or float

The value to return if the condition is true.

x4np.ndarray or float

The value to return if the condition is false.

Returns

np.ndarray or float

The result based on the condition.

zuffy._fpt_operators._intensifier(x0: ndarray | float) ndarray | float[source]

Applies an Intensifier linguistic hedge (from “Expanding the definitions of linguistic hedges”). This operation increases membership values above 0.5 and decreases those below 0.5, making the set “more true”.

Parameters

x0np.ndarray or float

The input fuzzy set membership value or array.

Returns

np.ndarray or float

The result of the intensifier operation.

zuffy._fpt_operators._lukasiewicz_t_conorm(x0: ndarray | float, x1: ndarray | float) ndarray | float[source]

Calculates the Łukasiewicz t-conorm: min(1, x0 + x1).

Parameters

x0np.ndarray or float

First value, typically in the range [0, 1].

x1np.ndarray or float

Second value, typically in the range [0, 1].

Returns

np.ndarray or float

The Łukasiewicz t-conorm of x0 and x1.

zuffy._fpt_operators._lukasiewicz_t_norm(x0: ndarray | float, x1: ndarray | float) ndarray | float[source]

Calculates the Łukasiewicz t-norm: max(0, x0 + x1 - 1.0).

Parameters

x0np.ndarray or float

First value, typically in the range [0, 1].

x1np.ndarray or float

Second value, typically in the range [0, 1].

Returns

np.ndarray or float

The Łukasiewicz t-norm of x0 and x1.

zuffy._fpt_operators._maximum(x0: ndarray | float, x1: ndarray | float) ndarray | float[source]

Performs the Maximum operation, equivalent to a boolean OR in fuzzy sets.

Parameters

x0np.ndarray or float

The first operand.

x1np.ndarray or float

The second operand.

Returns

np.ndarray or float

The element-wise maximum of x0 and x1.

zuffy._fpt_operators._minimum(x0: ndarray | float, x1: ndarray | float) ndarray | float[source]

Performs the Minimum operation, equivalent to a boolean AND in fuzzy sets.

Parameters

x0np.ndarray or float

The first operand.

x1np.ndarray or float

The second operand.

Returns

np.ndarray or float

The element-wise minimum of x0 and x1.

zuffy._fpt_operators._ordered_weighted_average(a: ndarray | float, b: ndarray | float, x: float) ndarray | float[source]

Calculates the Ordered Weighted Average (OWA): x*max(a, b) + (1-x)*min(a, b).

Parameters

anp.ndarray or float

The first operand.

bnp.ndarray or float

The second operand.

xfloat

The weight to apply to the maximum of ‘a’ and ‘b’, with (1-x) applied to the minimum. Should be in the range [0, 1].

Returns

np.ndarray or float

The result of the OWA operation.

zuffy._fpt_operators._product_t_norm(x0: ndarray | float, x1: ndarray | float) ndarray | float[source]

Computes the product t-norm (x0 * x1). This is the standard fuzzy AND.

Parameters

x0np.ndarray or float

The first operand.

x1np.ndarray or float

The second operand.

Returns

np.ndarray or float

The product of x0 and x1.

zuffy._fpt_operators._weighted_average(a: ndarray | float, b: ndarray | float, x: float) ndarray | float[source]

Calculates the Weighted Average: x*a + (1-x)*b.

Parameters

anp.ndarray or float

The first operand, typically a fuzzy set membership value or array.

bnp.ndarray or float

The second operand, typically a fuzzy set membership value or array.

xfloat

The weight to apply to ‘a’, with (1-x) applied to ‘b’. Should be in the range [0, 1] for typical fuzzy operations.

Returns

np.ndarray or float

The result of the weighted average operation.