Skip to content

ltnjax.fuzzy_ops

Classes:

Name Description
AggregBoltzmann
AggregCMean

Cubic mean or root mean square aggregation operator. Intended for

AggregGMean
AggregHMean
AggregInverted

Inversion operator, that inverts conjunction operators to disjunction

AggregLogProd

Log-product aggregation operator.

AggregLogSumExp
AggregLukMax

Lukasiewicz fuzzy maximum operator.

AggregLukMin

Lukasiewicz fuzzy minimum aggregation operator. Intended for

AggregMax

Max fuzzy aggregation operator. Intended for disjunction.

AggregMean

(Weighted) Mean fuzzy aggregation operator.

AggregMellowmax
AggregMin

Min fuzzy aggregation operator. Intended for conjunction.

AggregPMean
AggregPMeanError

pMeanError fuzzy aggregation operator.

AggregProbSum

Probabilistic sum aggregation operator. Intended for disjunction as it

AggregProd

(Weighted) Product fuzzy aggregation operator.

AggregQMean

Quadratic mean or root mean square aggregation operator. Intended for

AggregSum

(Weighted) Sum aggregation operator.

AggregYager2

yager2 fuzzy aggregation operation. Intended for disjunction

AggregationOperator

Abstract class for aggregation operators.

AndLuk

Lukasiewicz fuzzy conjunction operator.

AndMin

Godel fuzzy conjunction operator (min operator).

AndProd

Goguen fuzzy conjunction operator (product operator).

BinaryConnectiveOperator

Abstract class for binary connective operators.

ConnectiveOperator

Abstract class for connective operators.

Equiv

Equivalence (\(\leftrightarrow\)) fuzzy operator.

Implies

Implies (\(\Rightarrow\)) fuzzy operator.

ImpliesGodel

Godel fuzzy implication operand.

ImpliesGoguen

Goguen fuzzy implication operator.

ImpliesKleeneDienes

Kleene Dienes fuzzy implication operator.

ImpliesLuk

Lukasiewicz fuzzy implication operator.

ImpliesReichenbach

Reichenbach fuzzy implication operator.

NotGodel

Godel fuzzy negation operator.

NotStandard

Standard fuzzy negation operator.

OrLuk

Lukasiewicz fuzzy disjunction operator.

OrMax

Godel fuzzy disjunction operator (max operator).

OrProbSum

Goguen fuzzy disjunction operator (probabilistic sum).

OrSmoothMaximumUnit
UnaryConnectiveOperator

Abstract class for unary connective operators.

Functions:

Name Description
not_ones

Smoothly transforms an array to avoid one-values.

not_zeros

Smoothly transforms an array to avoid zero-values.

sigmoid

Computes sigmoid.

tanh

Computes hyperbolic tangent (tanh).

Attributes:

Name Type Description
AggregSumLog
Axis
eps

Attributes

AggregSumLog module-attribute

AggregSumLog = AggregLogProd

eps module-attribute

eps = 0.0001

Classes

AggregBoltzmann

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregBoltzmann[AggregBoltzmann]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregBoltzmann
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregBoltzmann href "" "ltnjax.fuzzy_ops.AggregBoltzmann"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Boltzmann fuzzy aggregation operator. This is intended to be used as an disjunction operator as it approximates the maximum aggregation.

\(S_\alpha(x_1,...,x_n)= \sum_{i = 1}^n x_i * \exp(\alpha x_i) / \sum_{i = 1}^n exp(\alpha x_i)\)

Attributes:

Name Type Description
alpha

\(\alpha\) parameter for \(S_\alpha(x_1,...,x_n)\).

Notes: - \(S_\alpha \rightarrow \max\) as \(\alpha \rightarrow \infty\). - \(S_0\) is the arithmetic mean of its inputs. - \(S_\alpha \rightarrow \min\) as \(\alpha \rightarrow -\infty\). - With zero-only mask, the function will return nan as we divide by a sum, that will be \(0\).

Methods:

Name Description
__call__

It applies the Boltzmann aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregBoltzmann(AggregationOperator):
    r"""[Boltzmann fuzzy aggregation operator](https://en.wikipedia.org/wiki/Smooth_maximum).
    This is intended to be used as an disjunction operator as it approximates
    the maximum aggregation.

    $S_\alpha(x_1,...,x_n)= \sum_{i = 1}^n x_i * \exp(\alpha x_i) / \sum_{i = 1}^n exp(\alpha x_i)$

    Attributes:
        alpha: $\alpha$ parameter for
            $S_\alpha(x_1,...,x_n)$.

    Notes:
    - $S_\alpha \rightarrow \max$ as $\alpha \rightarrow \infty$.
    - $S_0$ is the arithmetic mean of its inputs.
    - $S_\alpha \rightarrow \min$ as $\alpha \rightarrow -\infty$.
    - With zero-only mask, the function will return <b>`nan`</b> as we divide
    by a sum, that will be $0$.
    """  # noqa: E501

    def __init__(self, alpha: float):
        r"""Constructor.

        Args:
            alpha: $\alpha$ parameter for
                $S_\alpha(x_1,...,x_n)$.
        """
        self.alpha = alpha

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the Boltzmann aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            Boltzmann aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        exp_expr = jnp.exp(jnp.multiply(self.alpha, xs))
        return jnp.divide(
            jnp.sum(
                jnp.multiply(xs, exp_expr),
                axis=axis,
                keepdims=keepdims,
                where=mask,
            ),
            jnp.sum(exp_expr, axis=axis, keepdims=keepdims, where=mask),
        )

Attributes

alpha instance-attribute
alpha = alpha

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the Boltzmann aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

Boltzmann aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the Boltzmann aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        Boltzmann aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    exp_expr = jnp.exp(jnp.multiply(self.alpha, xs))
    return jnp.divide(
        jnp.sum(
            jnp.multiply(xs, exp_expr),
            axis=axis,
            keepdims=keepdims,
            where=mask,
        ),
        jnp.sum(exp_expr, axis=axis, keepdims=keepdims, where=mask),
    )
__init__
__init__(alpha: float)

Constructor.

Parameters:

Name Type Description Default
alpha
float

\(\alpha\) parameter for \(S_\alpha(x_1,...,x_n)\).

required
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, alpha: float):
    r"""Constructor.

    Args:
        alpha: $\alpha$ parameter for
            $S_\alpha(x_1,...,x_n)$.
    """
    self.alpha = alpha

AggregCMean

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregCMean[AggregCMean]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregCMean
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregCMean href "" "ltnjax.fuzzy_ops.AggregCMean"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Cubic mean or root mean square aggregation operator. Intended for disjunction as it approximates the maximum operator.

Cubic mean: \(\left( \sum_{i = 1}^n x_i^3 / n \right)^{\frac{1}{3}}\)

Weighted cubic mean: \(\left( \frac{\sum_{i=1}^n w_i x_i^3}{\sum_{i=1}^n w_i} \right)^{1/3}\)

Methods:

Name Description
__call__

It applies the quadratic mean aggregation operator to the given

__init__

Constructor.

Attributes:

Name Type Description
stable
Source code in src/ltnjax/fuzzy_ops.py
class AggregCMean(AggregationOperator):
    r"""Cubic mean or root mean square aggregation operator. Intended for
    disjunction as it approximates the maximum operator.

    Cubic mean:
    $\left( \sum_{i = 1}^n x_i^3 / n \right)^{\frac{1}{3}}$

    Weighted cubic mean:
    $\left( \frac{\sum_{i=1}^n w_i x_i^3}{\sum_{i=1}^n w_i} \right)^{1/3}$
    """  # noqa: E501

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the quadratic mean aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            Cubic mean aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)
        # Preparing input
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_zeros(xs)

        if weights is None:
            return jnp.cbrt(
                jnp.mean(
                    jnp.pow(xs, 3), axis=axis, keepdims=keepdims, where=mask
                )
            )
        elif mask is None:
            return jnp.cbrt(
                jnp.average(
                    jnp.pow(xs, 3),
                    axis=axis,
                    weights=weights,
                    keepdims=keepdims,
                )
            )
        else:  # weights is not None and mask is not None:
            weights = jnp.asarray(weights)
            x_p = jnp.pow(xs, 3)  # may contain nan values if x_i == 0.

            # Suppress UserWarnings from fuzzy_ops.AggregSum().
            warnings.filterwarnings("ignore", category=UserWarning)
            Sum = AggregSum()

            upper = Sum(
                x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
            )
            if len(weights.shape) == 1:
                weights = jnp.broadcast_to(weights, xs.shape)
            lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
            return jnp.cbrt(jnp.divide(upper, lower))

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array

It applies the quadratic mean aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

Cubic mean aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the quadratic mean aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        Cubic mean aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)
    # Preparing input
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_zeros(xs)

    if weights is None:
        return jnp.cbrt(
            jnp.mean(
                jnp.pow(xs, 3), axis=axis, keepdims=keepdims, where=mask
            )
        )
    elif mask is None:
        return jnp.cbrt(
            jnp.average(
                jnp.pow(xs, 3),
                axis=axis,
                weights=weights,
                keepdims=keepdims,
            )
        )
    else:  # weights is not None and mask is not None:
        weights = jnp.asarray(weights)
        x_p = jnp.pow(xs, 3)  # may contain nan values if x_i == 0.

        # Suppress UserWarnings from fuzzy_ops.AggregSum().
        warnings.filterwarnings("ignore", category=UserWarning)
        Sum = AggregSum()

        upper = Sum(
            x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
        )
        if len(weights.shape) == 1:
            weights = jnp.broadcast_to(weights, xs.shape)
        lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
        return jnp.cbrt(jnp.divide(upper, lower))
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

AggregGMean

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregGMean[AggregGMean]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregGMean
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregGMean href "" "ltnjax.fuzzy_ops.AggregGMean"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Geometric Mean fuzzy aggregation operator. Intended for conjunction as it approximates the minimum aggregation operator.

Geometric mean: \((\prod_{i = 1}^n x_i)^{1/n} = \exp(\sum_{i = 1}^n \ln(x_i) / n)\)

Weighted geometric mean: \((\prod_{i = 1}^n x_i^{w_i})^{1/(\sum_{i=1}^n w_i)} = \exp(\sum_{i = 1}^n \ln(x_i) / n)\)

Attributes:

Name Type Description
stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Methods:

Name Description
__call__

It applies the geometric mean aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregGMean(AggregationOperator):
    r"""[Geometric Mean fuzzy aggregation operator](https://en.wikipedia.org/wiki/Geometric_mean).
    Intended for conjunction as it approximates the minimum aggregation
    operator.

    Geometric mean:
    $(\prod_{i = 1}^n x_i)^{1/n} = \exp(\sum_{i = 1}^n \ln(x_i) / n)$

    Weighted geometric mean:
    $(\prod_{i = 1}^n x_i^{w_i})^{1/(\sum_{i=1}^n w_i)} = \exp(\sum_{i = 1}^n \ln(x_i) / n)$

    Attributes:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """  # noqa: E501

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the geometric mean aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            Geometric mean aggregation applied to the expression.

        Note:
        -jax.numpy.log computes the <b>natural logarithm</b>.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)
        # preparing input
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_zeros(xs)

        if weights is None:
            return jnp.exp(
                jnp.mean(jnp.log(xs), axis=axis, keepdims=keepdims, where=mask)
            )
        elif mask is None:
            return jnp.exp(
                jnp.average(
                    jnp.log(xs), axis=axis, weights=weights, keepdims=keepdims
                )
            )
        else:  # weights is not None and mask is not None:
            weights = jnp.asarray(weights)
            x_p = jnp.log(xs)  # may contain nan values if x_i == 0.

            # Suppress UserWarnings from fuzzy_ops.AggregSum().
            warnings.filterwarnings("ignore", category=UserWarning)
            Sum = AggregSum()

            upper = Sum(
                x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
            )
            if len(weights.shape) == 1:
                weights = jnp.broadcast_to(weights, xs.shape)
            lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
            return jnp.exp(jnp.divide(upper, lower))

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array

It applies the geometric mean aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

Geometric mean aggregation applied to the expression.

Note: -jax.numpy.log computes the natural logarithm.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the geometric mean aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        Geometric mean aggregation applied to the expression.

    Note:
    -jax.numpy.log computes the <b>natural logarithm</b>.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)
    # preparing input
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_zeros(xs)

    if weights is None:
        return jnp.exp(
            jnp.mean(jnp.log(xs), axis=axis, keepdims=keepdims, where=mask)
        )
    elif mask is None:
        return jnp.exp(
            jnp.average(
                jnp.log(xs), axis=axis, weights=weights, keepdims=keepdims
            )
        )
    else:  # weights is not None and mask is not None:
        weights = jnp.asarray(weights)
        x_p = jnp.log(xs)  # may contain nan values if x_i == 0.

        # Suppress UserWarnings from fuzzy_ops.AggregSum().
        warnings.filterwarnings("ignore", category=UserWarning)
        Sum = AggregSum()

        upper = Sum(
            x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
        )
        if len(weights.shape) == 1:
            weights = jnp.broadcast_to(weights, xs.shape)
        lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
        return jnp.exp(jnp.divide(upper, lower))
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

AggregHMean

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregHMean[AggregHMean]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregHMean
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregHMean href "" "ltnjax.fuzzy_ops.AggregHMean"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Harmonic mean fuzzy aggregation operator.

The harmonic mean is the special case of the Power Mean with \(p=-1\).

Harmonic mean: \(n / (\sum_{i = 1}^n \frac{1}{x_i}\)

Weighted harmonic mean: \(\frac{\sum_{i=1}^n w_i}{\sum_{i=1}^n \frac{w_i}{x_i}}\) \(= \left( \frac{\sum_{i=1}^n w_i x_i^{-1}}{\sum_{i=1}^n w_i} \right)^{-1}\)

Attributes:

Name Type Description
stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - As we divide by \((\sum_{i = 1}^n \frac{1}{x_i})\), the values \(x_i\) must not be \(0\).

Methods:

Name Description
__call__

It applies the harmonic mean aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregHMean(AggregationOperator):
    r"""[Harmonic mean fuzzy aggregation operator](https://en.wikipedia.org/wiki/Harmonic_mean).

    The harmonic mean is the special case of the Power Mean with $p=-1$.

    Harmonic mean:
    $n / (\sum_{i = 1}^n \frac{1}{x_i}$

    Weighted harmonic mean:
    $\frac{\sum_{i=1}^n w_i}{\sum_{i=1}^n \frac{w_i}{x_i}}$
    $= \left( \frac{\sum_{i=1}^n w_i x_i^{-1}}{\sum_{i=1}^n w_i} \right)^{-1}$

    Attributes:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Notes:
    - As we divide by $(\sum_{i = 1}^n \frac{1}{x_i})$, the values
    $x_i$ <b>must not be $0$</b>.
    """  # noqa: E501

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the harmonic mean aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            harmonic mean aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)
        # Preparing input
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_zeros(xs)

        if weights is None:
            return jnp.reciprocal(
                jnp.mean(
                    jnp.reciprocal(xs),
                    axis=axis,
                    keepdims=keepdims,
                    where=mask,
                )
            )
        elif mask is None:
            return jnp.reciprocal(
                jnp.average(
                    jnp.reciprocal(xs),
                    axis=axis,
                    weights=weights,
                    keepdims=keepdims,
                )
            )
        else:  # weights is not None and mask is not None:
            weights = jnp.asarray(weights)
            x_p = jnp.reciprocal(xs)  # may contain nan values if x_i == 0.

            # Suppress UserWarnings from fuzzy_ops.AggregSum().
            warnings.filterwarnings("ignore", category=UserWarning)
            Sum = AggregSum()

            upper = Sum(
                x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
            )
            if len(weights.shape) == 1:
                weights = jnp.broadcast_to(weights, xs.shape)
            lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
            return jnp.reciprocal(jnp.divide(upper, lower))

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array

It applies the harmonic mean aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

harmonic mean aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the harmonic mean aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        harmonic mean aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)
    # Preparing input
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_zeros(xs)

    if weights is None:
        return jnp.reciprocal(
            jnp.mean(
                jnp.reciprocal(xs),
                axis=axis,
                keepdims=keepdims,
                where=mask,
            )
        )
    elif mask is None:
        return jnp.reciprocal(
            jnp.average(
                jnp.reciprocal(xs),
                axis=axis,
                weights=weights,
                keepdims=keepdims,
            )
        )
    else:  # weights is not None and mask is not None:
        weights = jnp.asarray(weights)
        x_p = jnp.reciprocal(xs)  # may contain nan values if x_i == 0.

        # Suppress UserWarnings from fuzzy_ops.AggregSum().
        warnings.filterwarnings("ignore", category=UserWarning)
        Sum = AggregSum()

        upper = Sum(
            x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
        )
        if len(weights.shape) == 1:
            weights = jnp.broadcast_to(weights, xs.shape)
        lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
        return jnp.reciprocal(jnp.divide(upper, lower))
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

AggregInverted

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregInverted[AggregInverted]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregInverted
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregInverted href "" "ltnjax.fuzzy_ops.AggregInverted"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Inversion operator, that inverts conjunction operators to disjunction operators and vise verca. The given aggreg_op is inverted.

For that, we make use of the fact \(\bigvee(x1,x2,x3) = \neg(\bigwedge(\neg(x1), \neg(x2), \neg(x3)))\)

For example we have Aggreg_Inverted(Aggreg_pMeanError(p=2))) == Aggreg_pMean(p=2))

Attributes:

Name Type Description
aggreg_op

The aggregation operator that is inverted.

Methods:

Name Description
__call__

It applies the inverted aggregation operator aggreg_op to the

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregInverted(AggregationOperator):
    r"""Inversion operator, that inverts conjunction operators to disjunction
    operators and vise verca. The given `aggreg_op` is inverted.

    For that, we make use of the fact
    $\bigvee(x1,x2,x3) = \neg(\bigwedge(\neg(x1), \neg(x2), \neg(x3)))$

    For example we have
    `Aggreg_Inverted(Aggreg_pMeanError(p=2))) == Aggreg_pMean(p=2))`

    Attributes:
        aggreg_op: The aggregation operator that is inverted.
    """  # noqa: E501

    def __init__(self, aggreg_op: AggregationOperator):
        """Constructor.

        Args:
            aggreg_op: The aggregation operator that is inverted.
        """
        self.aggreg_op = aggreg_op

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        **kwargs: Any,
    ) -> Array:
        """It applies the inverted aggregation operator `aggreg_op` to the
        given expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            kwargs: Further arguments to pass to `connective_op`.

        Returns:
            Inverted aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        return 1.0 - self.aggreg_op(
            1.0 - xs, axis=axis, keepdims=keepdims, mask=mask, **kwargs
        )

Attributes

aggreg_op instance-attribute
aggreg_op = aggreg_op

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    **kwargs: Any,
) -> Array

It applies the inverted aggregation operator aggreg_op to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
kwargs
Any

Further arguments to pass to connective_op.

{}

Returns:

Type Description
Array

Inverted aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    **kwargs: Any,
) -> Array:
    """It applies the inverted aggregation operator `aggreg_op` to the
    given expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        kwargs: Further arguments to pass to `connective_op`.

    Returns:
        Inverted aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    return 1.0 - self.aggreg_op(
        1.0 - xs, axis=axis, keepdims=keepdims, mask=mask, **kwargs
    )
__init__

Constructor.

Parameters:

Name Type Description Default
aggreg_op
AggregationOperator

The aggregation operator that is inverted.

required
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, aggreg_op: AggregationOperator):
    """Constructor.

    Args:
        aggreg_op: The aggregation operator that is inverted.
    """
    self.aggreg_op = aggreg_op

AggregLogProd

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregLogProd[AggregLogProd]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregLogProd
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregLogProd href "" "ltnjax.fuzzy_ops.AggregLogProd"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Log-product aggregation operator.

\(\sum_{i = 1}^n \log x_i\)

Attributes:

Name Type Description
stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - The values in xs should not be \(0\) as we take its logarithm.

Methods:

Name Description
__call__

It applies the LogProd aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregLogProd(AggregationOperator):
    r"""Log-product aggregation operator.

    $\sum_{i = 1}^n \log x_i$

    Attributes:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Notes:
    - The values in `xs` should <b>not be $0$</b> as we take its
    logarithm.
    """

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        warn(
            "`Aggreg_LogProd` outputs values out of the truth value range"
            "[0,1]. "
            "Its usage with other connectives could be compromised. "
            "Use it carefully.",
            UserWarning,
            stacklevel=1,
        )
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the LogProd aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            LogProd aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        if mask is not None:
            xs = jnp.where(xs, mask, 0.0)
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_zeros(xs)
        return jnp.sum(jnp.log(xs), axis=axis, keepdims=keepdims)

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array

It applies the LogProd aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

LogProd aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the LogProd aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        LogProd aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    if mask is not None:
        xs = jnp.where(xs, mask, 0.0)
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_zeros(xs)
    return jnp.sum(jnp.log(xs), axis=axis, keepdims=keepdims)
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    warn(
        "`Aggreg_LogProd` outputs values out of the truth value range"
        "[0,1]. "
        "Its usage with other connectives could be compromised. "
        "Use it carefully.",
        UserWarning,
        stacklevel=1,
    )
    self.stable = stable

AggregLogSumExp

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregLogSumExp[AggregLogSumExp]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregLogSumExp
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregLogSumExp href "" "ltnjax.fuzzy_ops.AggregLogSumExp"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

LogSumExp operator Intended for disjunction as it approximates the maximum aggregation.

\(LSE_\alpha(x_1,\dotsc,x_n) = (1/\alpha) \log \sum_{i = 1}^n \exp (\alpha x_i)\)

Attributes:

Name Type Description
alpha

\(\alpha\) parameter for \(LSE_\alpha(x_1,\dotsc,x_n)\).

Notes: - With zero-only mask, the function will return -np.infty as we take the logarithm of an empty sum, i.e. of \(0\).

Methods:

Name Description
__call__

It applies the LogSumExp aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregLogSumExp(AggregationOperator):
    r"""[LogSumExp operator](https://en.wikipedia.org/wiki/LogSumExp)
    Intended for disjunction as it approximates the maximum aggregation.

    $LSE_\alpha(x_1,\dotsc,x_n) = (1/\alpha) \log \sum_{i = 1}^n \exp (\alpha x_i)$

    Attributes:
        alpha: $\alpha$ parameter for
            $LSE_\alpha(x_1,\dotsc,x_n)$.

    Notes:
    - With zero-only mask, the function will return <b>`-np.infty`</b> as we
    take the logarithm of an empty sum, i.e. of $0$.
    """  # noqa: E501

    def __init__(self, alpha: float):
        r"""Constructor.

        Args:
            alpha: $\alpha$ parameter for
                $LSE_\alpha(x_1,...,x_n)$.
        """
        self.alpha = alpha

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the LogSumExp aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            LogSumExp aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        return jnp.multiply(
            jnp.divide(1, self.alpha),
            jnp.log(
                jnp.sum(
                    jnp.exp(jnp.multiply(self.alpha, xs)),
                    axis=axis,
                    keepdims=keepdims,
                    where=mask,
                )
            ),
        )

Attributes

alpha instance-attribute
alpha = alpha

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the LogSumExp aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

LogSumExp aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the LogSumExp aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        LogSumExp aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    return jnp.multiply(
        jnp.divide(1, self.alpha),
        jnp.log(
            jnp.sum(
                jnp.exp(jnp.multiply(self.alpha, xs)),
                axis=axis,
                keepdims=keepdims,
                where=mask,
            )
        ),
    )
__init__
__init__(alpha: float)

Constructor.

Parameters:

Name Type Description Default
alpha
float

\(\alpha\) parameter for \(LSE_\alpha(x_1,...,x_n)\).

required
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, alpha: float):
    r"""Constructor.

    Args:
        alpha: $\alpha$ parameter for
            $LSE_\alpha(x_1,...,x_n)$.
    """
    self.alpha = alpha

AggregLukMax

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregLukMax[AggregLukMax]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregLukMax
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregLukMax href "" "ltnjax.fuzzy_ops.AggregLukMax"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Lukasiewicz fuzzy maximum operator. This is intended to be used as an conjunction operator.

\(\max(\sum_{i = 1}^n x_i - n + 1, 0)\)

Notes: - Luk_Max has vanishing gradiens for \(\sum_{i = 1}^n x_i - n + 1 < 0\). If \(\sum_{i = 1}^n x_i - n + 1 = 0\), all gradients are \(0.5\).

Methods:

Name Description
__call__

It applies the Lukasiewicz fuzzy disjunction aggregation operator

Source code in src/ltnjax/fuzzy_ops.py
class AggregLukMax(AggregationOperator):
    r"""Lukasiewicz fuzzy maximum operator.
    This is intended to be used as an conjunction operator.

    $\max(\sum_{i = 1}^n x_i - n + 1, 0)$

    Notes:
    - Luk_Max has <b>vanishing gradiens</b> for
    $\sum_{i = 1}^n x_i - n + 1 < 0$.
    If $\sum_{i = 1}^n x_i - n + 1 = 0$, all gradients are $0.5$.
    """

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the Lukasiewicz fuzzy disjunction aggregation operator
        to the given expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            Lukasiewicz fuzzy disjunction aggregation applied to the
            expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        if mask is not None:
            n = jnp.sum(mask, axis=axis)
        else:
            n = jnp.asarray(jnp.size(xs, axis=axis))
        return jnp.maximum(
            jnp.sum(xs, axis=axis, keepdims=keepdims, where=mask) - n + 1, 0
        )

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the Lukasiewicz fuzzy disjunction aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

Lukasiewicz fuzzy disjunction aggregation applied to the

Array

expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the Lukasiewicz fuzzy disjunction aggregation operator
    to the given expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        Lukasiewicz fuzzy disjunction aggregation applied to the
        expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    if mask is not None:
        n = jnp.sum(mask, axis=axis)
    else:
        n = jnp.asarray(jnp.size(xs, axis=axis))
    return jnp.maximum(
        jnp.sum(xs, axis=axis, keepdims=keepdims, where=mask) - n + 1, 0
    )

AggregLukMin

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregLukMin[AggregLukMin]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregLukMin
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregLukMin href "" "ltnjax.fuzzy_ops.AggregLukMin"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Lukasiewicz fuzzy minimum aggregation operator. Intended for disjunction.

\(\min(\sum_{i = 1}^n x_i, 1)\)

Notes: - We have vanishing gradients for the case \(\sum_{i = 1}^n x_i > 1\). For the case that \(\sum_{i = 1}^n x_i = 1\), all gradients are \(0.5\).

Methods:

Name Description
__call__

It applies the Lukasiewicz fuzzy conjunction aggregation operator

Source code in src/ltnjax/fuzzy_ops.py
class AggregLukMin(AggregationOperator):
    r"""Lukasiewicz fuzzy minimum aggregation operator. Intended for
    disjunction.

    $\min(\sum_{i = 1}^n x_i, 1)$

    Notes:
    - We have <b>vanishing gradients</b> for the case
    $\sum_{i = 1}^n x_i > 1$.
    For the case that $\sum_{i = 1}^n x_i = 1$, all gradients are
    $0.5$.
    """

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the Lukasiewicz fuzzy conjunction aggregation operator
        to the given expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            Lukasiewicz fuzzy aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        return jnp.minimum(
            1.0, jnp.sum(xs, axis=axis, keepdims=keepdims, where=mask)
        )

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the Lukasiewicz fuzzy conjunction aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

Lukasiewicz fuzzy aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the Lukasiewicz fuzzy conjunction aggregation operator
    to the given expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        Lukasiewicz fuzzy aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    return jnp.minimum(
        1.0, jnp.sum(xs, axis=axis, keepdims=keepdims, where=mask)
    )

AggregMax

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregMax[AggregMax]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregMax
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregMax href "" "ltnjax.fuzzy_ops.AggregMax"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Max fuzzy aggregation operator. Intended for disjunction.

\(A_{T_{M}}(x_1, \dots, x_n) = \max(x_1, \dots, x_n)\)

Notes: - This aggregator has a single-passing gradient for the maximum value. If \(n\) values attain the maximum, they get the gradients \(\frac{1}{n}\).

Methods:

Name Description
__call__

It applies the max fuzzy aggregation operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class AggregMax(AggregationOperator):
    r"""Max fuzzy aggregation operator. Intended for disjunction.

    $A_{T_{M}}(x_1, \dots, x_n) = \max(x_1, \dots, x_n)$

    Notes:
    - This aggregator has a <b>single-passing gradient</b> for the maximum
    value. If $n$ values attain the maximum, they get the gradients
    $\frac{1}{n}$.
    """

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the max fuzzy aggregation operator to the given
        formula's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            Max fuzzy aggregation of the formula.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        return jnp.max(
            xs, axis=axis, keepdims=keepdims, where=mask, initial=0.0
        )

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the max fuzzy aggregation operator to the given formula's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

Max fuzzy aggregation of the formula.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the max fuzzy aggregation operator to the given
    formula's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        Max fuzzy aggregation of the formula.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    return jnp.max(
        xs, axis=axis, keepdims=keepdims, where=mask, initial=0.0
    )

AggregMean

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregMean[AggregMean]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregMean
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregMean href "" "ltnjax.fuzzy_ops.AggregMean"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

(Weighted) Mean fuzzy aggregation operator.

Arithmetic mean \(A_{M}(x_1, \dots, x_n) = \frac{1}{n} \sum_{i = 1}^n x_i\)

Weighted arithmetic mean \(A_{M}(x_1, \dots, x_n) = \frac{1}{\sum_{i = 1}^n w_i} \sum_{i = 1}^n w_i x_i\)

Methods:

Name Description
__call__

It applies the mean fuzzy aggregation operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class AggregMean(AggregationOperator):
    r"""(Weighted) Mean fuzzy aggregation operator.

    [Arithmetic mean](https://en.wikipedia.org/wiki/Arithmetic_mean)
    $A_{M}(x_1, \dots, x_n) = \frac{1}{n} \sum_{i = 1}^n x_i$

    [Weighted arithmetic mean](https://en.wikipedia.org/wiki/Weighted_arithmetic_mean)
    $A_{M}(x_1, \dots, x_n) = \frac{1}{\sum_{i = 1}^n w_i} \sum_{i = 1}^n w_i x_i$
    """  # noqa: E501

    def __call__(
        self,
        xs: ArrayLike,
        weights: ArrayLike | None = None,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the mean fuzzy aggregation operator to the given
        formula's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            weights: (default=None) The weights for the aggregation operator.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            Mean fuzzy aggregation of the formula.
        """
        # TODO rewrite the function in case the
        # [#30678](https://github.com/jax-ml/jax/issues/30678) gets fixed.
        # This complicated code is necessary, as jnp.average does not take a
        # where-parameter and jnp.mean does not take weights-parameter.
        if mask is not None and weights is not None:
            xs = jnp.multiply(xs, mask)
            weights = jnp.multiply(weights, mask)
            return jnp.average(
                xs, weights=weights, axis=axis, keepdims=keepdims
            )
        elif mask is None and weights is not None:
            return jnp.average(
                xs, weights=weights, axis=axis, keepdims=keepdims
            )
        else:  # (weights is None)
            return jnp.mean(xs, axis=axis, keepdims=keepdims, where=mask)

Methods:

__call__
__call__(
    xs: ArrayLike,
    weights: ArrayLike | None = None,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the mean fuzzy aggregation operator to the given formula's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
weights
ArrayLike | None

(default=None) The weights for the aggregation operator.

None
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

Mean fuzzy aggregation of the formula.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    weights: ArrayLike | None = None,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the mean fuzzy aggregation operator to the given
    formula's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        weights: (default=None) The weights for the aggregation operator.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        Mean fuzzy aggregation of the formula.
    """
    # TODO rewrite the function in case the
    # [#30678](https://github.com/jax-ml/jax/issues/30678) gets fixed.
    # This complicated code is necessary, as jnp.average does not take a
    # where-parameter and jnp.mean does not take weights-parameter.
    if mask is not None and weights is not None:
        xs = jnp.multiply(xs, mask)
        weights = jnp.multiply(weights, mask)
        return jnp.average(
            xs, weights=weights, axis=axis, keepdims=keepdims
        )
    elif mask is None and weights is not None:
        return jnp.average(
            xs, weights=weights, axis=axis, keepdims=keepdims
        )
    else:  # (weights is None)
        return jnp.mean(xs, axis=axis, keepdims=keepdims, where=mask)

AggregMellowmax

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregMellowmax[AggregMellowmax]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregMellowmax
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregMellowmax href "" "ltnjax.fuzzy_ops.AggregMellowmax"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Mellowmax fuzzy aggregation operator. This is intended to be used as an disjunction operator as it approximates the maximum aggregation.

\(mm_\alpha(x_1,...,x_n) = (1/\alpha) \log \frac{1}{n} \sum_{i = 1}^n \exp (\alpha x_i)\)

Attributes:

Name Type Description
alpha

\(\alpha\) parameter for \(mm_\alpha(x_1,...,x_n)\).

Notes: - The result is undefined if we set \(\alpha=0\). - \(mm_\alpha \rightarrow \max\) as \(\alpha \rightarrow \infty\). - \(mm_\alpha \rightarrow 0\) is the arithmetic mean of its inputs. - \(mm_\alpha \rightarrow \min\) as \(\alpha \rightarrow -\infty\). - With zero-only mask, the function will return nan as we divide by a \(n=0\).

Methods:

Name Description
__call__

It applies the Mellowmax aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregMellowmax(AggregationOperator):
    r"""[Mellowmax fuzzy aggregation operator](https://en.wikipedia.org/wiki/Smooth_maximum#Mellowmax).
    This is intended to be used as an disjunction operator as it approximates
    the maximum aggregation.

    $mm_\alpha(x_1,...,x_n) = (1/\alpha) \log \frac{1}{n} \sum_{i = 1}^n \exp (\alpha x_i)$

    Attributes:
        alpha: $\alpha$ parameter for
            $mm_\alpha(x_1,...,x_n)$.


    Notes:
    - The result is <b>undefined</b> if we set $\alpha=0$.
    - $mm_\alpha \rightarrow \max$ as $\alpha \rightarrow \infty$.
    - $mm_\alpha \rightarrow 0$ is the arithmetic mean of its inputs.
    - $mm_\alpha \rightarrow \min$ as $\alpha \rightarrow -\infty$.
    - With zero-only mask, the function will return <b>`nan`</b> as we divide
    by a $n=0$.
    """  # noqa: E501

    def __init__(self, alpha: float):
        r"""Constructor.

        Args:
            alpha: $\alpha$ parameter for
                $mm_\alpha(x_1,\dotsc,x_n)$.
        """
        self.alpha = alpha

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the Mellowmax aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            Mellowmax aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        if mask is not None:
            n = jnp.sum(mask, axis=axis)
        else:
            n = jnp.asarray(jnp.size(xs, axis=axis))
        return jnp.multiply(
            jnp.reciprocal(self.alpha),
            jnp.log(
                jnp.multiply(
                    jnp.reciprocal(n),
                    jnp.sum(
                        jnp.exp(jnp.multiply(self.alpha, xs)),
                        axis=axis,
                        keepdims=keepdims,
                        where=mask,
                    ),
                )
            ),
        )

Attributes

alpha instance-attribute
alpha = alpha

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the Mellowmax aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

Mellowmax aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the Mellowmax aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        Mellowmax aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    if mask is not None:
        n = jnp.sum(mask, axis=axis)
    else:
        n = jnp.asarray(jnp.size(xs, axis=axis))
    return jnp.multiply(
        jnp.reciprocal(self.alpha),
        jnp.log(
            jnp.multiply(
                jnp.reciprocal(n),
                jnp.sum(
                    jnp.exp(jnp.multiply(self.alpha, xs)),
                    axis=axis,
                    keepdims=keepdims,
                    where=mask,
                ),
            )
        ),
    )
__init__
__init__(alpha: float)

Constructor.

Parameters:

Name Type Description Default
alpha
float

\(\alpha\) parameter for \(mm_\alpha(x_1,\dotsc,x_n)\).

required
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, alpha: float):
    r"""Constructor.

    Args:
        alpha: $\alpha$ parameter for
            $mm_\alpha(x_1,\dotsc,x_n)$.
    """
    self.alpha = alpha

AggregMin

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregMin[AggregMin]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregMin
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregMin href "" "ltnjax.fuzzy_ops.AggregMin"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Min fuzzy aggregation operator. Intended for conjunction.

\(A_{T_{M}}(x_1, \dots, x_n) = \min(x_1, \dots, x_n)\)

Notes: - This aggregator has a single-passing gradient for the minimum value. If \(n\) values attain the minimum, they get the gradients \(\frac{1}{n}\).

Methods:

Name Description
__call__

It applies the min fuzzy aggregation operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class AggregMin(AggregationOperator):
    r"""Min fuzzy aggregation operator. Intended for conjunction.

    $A_{T_{M}}(x_1, \dots, x_n) = \min(x_1, \dots, x_n)$

    Notes:
    - This aggregator has a <b>single-passing gradient</b> for the minimum
    value. If $n$ values attain the minimum, they get the gradients
    $\frac{1}{n}$.
    """

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the min fuzzy aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            Min fuzzy aggregation of the formula.
        """
        return jnp.min(
            xs, axis=axis, keepdims=keepdims, where=mask, initial=1.0
        )

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the min fuzzy aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

Min fuzzy aggregation of the formula.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the min fuzzy aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        Min fuzzy aggregation of the formula.
    """
    return jnp.min(
        xs, axis=axis, keepdims=keepdims, where=mask, initial=1.0
    )

AggregPMean

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregPMean[AggregPMean]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregPMean
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregPMean href "" "ltnjax.fuzzy_ops.AggregPMean"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

(Weighted) power mean (pmean) / generalized mean aggregation operator see logictensornetwors.

Generalized mean with \(p \neq 0\): \(\left( 1/n * \sum_{i = 1}^n u_i^p \right)^{1/p}\)

Generalized mean with \(p = 0\): \(\left( \prod_{i=1}^n x_i \right)^{\frac{1}{n}}\)

Weighted generalized mean with \(p \neq 0\): \(\left( \frac{\sum_{i=1}^n w_i x_i^p}{\sum_{i=1}^n w_i} \right)^{1/p}\)

Weighted generalized mean with \(p = 0\): \(\left( \prod_{i=1}^n x_i^{w_i} \right)^{\frac{1}{\sum_{i=1}^n w_i}}\)

pMean can be understood as a smooth-maximum that depends on the hyper-parameter \(p\):, - \(p \rightarrow -\infty\): the operator tends to \(\min\), - \(p = -1\): harmonic mean, - \(p = 0\): geometric mean, - \(p = 1\): mean, - \(p = 2\): quadratic mean, - \(p = 3\): cubic mean, - \(p \rightarrow +\infty\): the operator tends to \(\max\).

Attributes:

Name Type Description
p

(default=2) Value of the parameter p.

stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - pMean has exploding gradients for \(a_1= \dotsc =a_n=0\). - If not all values are \(0\), these who has get a vanishing gradient.

Methods:

Name Description
__call__

It applies the pMean aggregation operator to the given formula's

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregPMean(AggregationOperator):
    r"""[(Weighted) power mean (pmean) / generalized mean aggregation operator](https://en.wikipedia.org/wiki/Generalized_mean)
    see [logictensornetwors](https://github.com/logictensornetworks/logictensornetworks/blob/master/tutorials/2-grounding_connectives.ipynb).

    Generalized mean with $p \neq 0$:
    $\left( 1/n * \sum_{i = 1}^n u_i^p \right)^{1/p}$

    Generalized mean with $p = 0$:
    $\left( \prod_{i=1}^n x_i \right)^{\frac{1}{n}}$

    Weighted generalized mean with $p \neq 0$:
    $\left( \frac{\sum_{i=1}^n w_i x_i^p}{\sum_{i=1}^n w_i} \right)^{1/p}$

    Weighted generalized mean with $p = 0$:
    $\left( \prod_{i=1}^n x_i^{w_i} \right)^{\frac{1}{\sum_{i=1}^n w_i}}$

    `pMean` can be understood as a smooth-maximum that depends on the
    hyper-parameter $p$:,
    - $p \rightarrow -\infty$: the operator tends to $\min$,
    - $p = -1$: harmonic mean,
    - $p = 0$: geometric mean,
    - $p = 1$: mean,
    - $p = 2$: quadratic mean,
    - $p = 3$: cubic mean,
    - $p \rightarrow +\infty$: the operator tends to $\max$.

    Attributes:
        p: (default=2) Value of the parameter p.
        stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

    Notes:
    - pMean has <b>exploding gradients</b> for $a_1= \dotsc =a_n=0$.
    - If not all values are $0$, these who has get a <b>vanishing gradient</b>.
    """  # noqa: E501

    def __init__(self, p: int = 2, stable: bool = True):
        """Constructor.

        Args:
            p: (default=2) Value of the parameter p.
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.p = p
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        p: int | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the `pMean` aggregation operator to the given formula's
        grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            p: (default=2) Value of the parameter p.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            `pMean` fuzzy aggregation of the formula.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)
        # TODO rewrite if jax.numpy.mean gets a weights-parameter or
        # if jax.numpy.average gets a where-parameter.

        # Preparing input
        p = self.p if p is None else p
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_zeros(xs)

        # For specific p-values, call other aggregators.
        if p == -1:
            return AggregHMean()(
                xs,
                axis=axis,
                weights=weights,
                keepdims=keepdims,
                mask=mask,
                stable=stable,
            )
        if p == 0:
            return AggregGMean()(
                xs,
                axis=axis,
                weights=weights,
                keepdims=keepdims,
                mask=mask,
                stable=stable,
            )
        if p == 1:
            return AggregMean()(
                xs, axis=axis, weights=weights, keepdims=keepdims, mask=mask
            )
        if p == 2:
            return AggregQMean()(
                xs,
                axis=axis,
                weights=weights,
                keepdims=keepdims,
                mask=mask,
                stable=stable,
            )
        if p == 3:
            return AggregCMean()(
                xs,
                axis=axis,
                weights=weights,
                keepdims=keepdims,
                mask=mask,
                stable=stable,
            )

        if weights is None:
            return jnp.pow(
                jnp.mean(
                    jnp.pow(xs, p), axis=axis, keepdims=keepdims, where=mask
                ),
                1 / p,
            )
        elif mask is None:
            return jnp.pow(
                jnp.average(
                    jnp.pow(xs, p),
                    axis=axis,
                    weights=weights,
                    keepdims=keepdims,
                ),
                1 / p,
            )
        else:  # weights is not None and mask is not None:
            weights = jnp.asarray(weights)
            x_p = jnp.pow(xs, p)  # may contain nan values if x_i == 0.

            # Suppress UserWarnings from fuzzy_ops.AggregSum().
            warnings.filterwarnings("ignore", category=UserWarning)
            Sum = AggregSum()

            upper = Sum(
                x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
            )
            if len(weights.shape) == 1:
                weights = jnp.broadcast_to(weights, xs.shape)
            lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
            return jnp.pow(jnp.divide(upper, lower), 1 / p)

Attributes

p instance-attribute
p = p
stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    p: int | None = None,
    stable: bool | None = None,
) -> Array

It applies the pMean aggregation operator to the given formula's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
p
int | None

(default=2) Value of the parameter p.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

pMean fuzzy aggregation of the formula.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    p: int | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the `pMean` aggregation operator to the given formula's
    grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        p: (default=2) Value of the parameter p.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        `pMean` fuzzy aggregation of the formula.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)
    # TODO rewrite if jax.numpy.mean gets a weights-parameter or
    # if jax.numpy.average gets a where-parameter.

    # Preparing input
    p = self.p if p is None else p
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_zeros(xs)

    # For specific p-values, call other aggregators.
    if p == -1:
        return AggregHMean()(
            xs,
            axis=axis,
            weights=weights,
            keepdims=keepdims,
            mask=mask,
            stable=stable,
        )
    if p == 0:
        return AggregGMean()(
            xs,
            axis=axis,
            weights=weights,
            keepdims=keepdims,
            mask=mask,
            stable=stable,
        )
    if p == 1:
        return AggregMean()(
            xs, axis=axis, weights=weights, keepdims=keepdims, mask=mask
        )
    if p == 2:
        return AggregQMean()(
            xs,
            axis=axis,
            weights=weights,
            keepdims=keepdims,
            mask=mask,
            stable=stable,
        )
    if p == 3:
        return AggregCMean()(
            xs,
            axis=axis,
            weights=weights,
            keepdims=keepdims,
            mask=mask,
            stable=stable,
        )

    if weights is None:
        return jnp.pow(
            jnp.mean(
                jnp.pow(xs, p), axis=axis, keepdims=keepdims, where=mask
            ),
            1 / p,
        )
    elif mask is None:
        return jnp.pow(
            jnp.average(
                jnp.pow(xs, p),
                axis=axis,
                weights=weights,
                keepdims=keepdims,
            ),
            1 / p,
        )
    else:  # weights is not None and mask is not None:
        weights = jnp.asarray(weights)
        x_p = jnp.pow(xs, p)  # may contain nan values if x_i == 0.

        # Suppress UserWarnings from fuzzy_ops.AggregSum().
        warnings.filterwarnings("ignore", category=UserWarning)
        Sum = AggregSum()

        upper = Sum(
            x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
        )
        if len(weights.shape) == 1:
            weights = jnp.broadcast_to(weights, xs.shape)
        lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
        return jnp.pow(jnp.divide(upper, lower), 1 / p)
__init__
__init__(p: int = 2, stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
p
int

(default=2) Value of the parameter p.

2
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, p: int = 2, stable: bool = True):
    """Constructor.

    Args:
        p: (default=2) Value of the parameter p.
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.p = p
    self.stable = stable

AggregPMeanError

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregPMeanError[AggregPMeanError]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregPMeanError
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregPMeanError href "" "ltnjax.fuzzy_ops.AggregPMeanError"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

pMeanError fuzzy aggregation operator.

\(A_{pME}(x_1, \dots, x_n) = 1 - (\frac{1}{n} \sum_{i = 1}^n (1 - x_i)^p)^{\frac{1}{p}}\)

Attributes:

Name Type Description
p

(default=2) Value of the parameter p.

stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - pMeanError has exploding gradients for \(a_1= \dotsc =a_n=1\). - If not all values are \(1\), these who has get a vanishing gradient.

Methods:

Name Description
__call__

It applies the pMeanError aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregPMeanError(AggregationOperator):
    r"""`pMeanError` fuzzy aggregation operator.

    $A_{pME}(x_1, \dots, x_n) = 1 - (\frac{1}{n} \sum_{i = 1}^n (1 - x_i)^p)^{\frac{1}{p}}$

    Attributes:
        p: (default=2) Value of the parameter p.
        stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

    Notes:
    - pMeanError has <b>exploding gradients</b> for $a_1= \dotsc =a_n=1$.
    - If not all values are $1$, these who has get a <b>vanishing gradient</b>.
    """  # noqa: E501

    def __init__(self, p: int = 2, stable: bool = True):
        """Constructor.

        Args:
            p: (default=2) Value of the parameter p.
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.p = p
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        p: int | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the `pMeanError` aggregation operator to the given
        formula's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            p: (default=2) Value of the parameter p.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            `pMeanError` fuzzy aggregation of the formula.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)
        # Preparing input
        p = self.p if p is None else p
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_ones(xs)

        return 1.0 - AggregPMean()(
            1.0 - xs,
            axis=axis,
            weights=weights,
            keepdims=keepdims,
            mask=mask,
            p=p,
            stable=stable,
        )

Attributes

p instance-attribute
p = p
stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    p: int | None = None,
    stable: bool | None = None,
) -> Array

It applies the pMeanError aggregation operator to the given formula's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
p
int | None

(default=2) Value of the parameter p.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

pMeanError fuzzy aggregation of the formula.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    p: int | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the `pMeanError` aggregation operator to the given
    formula's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        p: (default=2) Value of the parameter p.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        `pMeanError` fuzzy aggregation of the formula.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)
    # Preparing input
    p = self.p if p is None else p
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_ones(xs)

    return 1.0 - AggregPMean()(
        1.0 - xs,
        axis=axis,
        weights=weights,
        keepdims=keepdims,
        mask=mask,
        p=p,
        stable=stable,
    )
__init__
__init__(p: int = 2, stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
p
int

(default=2) Value of the parameter p.

2
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, p: int = 2, stable: bool = True):
    """Constructor.

    Args:
        p: (default=2) Value of the parameter p.
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.p = p
    self.stable = stable

AggregProbSum

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregProbSum[AggregProbSum]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregProbSum
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregProbSum href "" "ltnjax.fuzzy_ops.AggregProbSum"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Probabilistic sum aggregation operator. Intended for disjunction as it is the inverse of AggregProd.

\(1-\prod_{i = 1}^n (1-x_i)\)

Attributes:

Name Type Description
stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - ProbSum has vanishing gradients for the case that at least two values \(a_i\) are \(1.\). For the case that exactly one \(a_i\) equals \(1.\), we have a single-passing gradient for this value.

Methods:

Name Description
__call__

It applies the ProbSum fuzzy aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregProbSum(AggregationOperator):
    r"""Probabilistic sum aggregation operator. Intended for disjunction as it
    is the inverse of [AggregProd][ltnjax.fuzzy_ops.AggregProd].

    $1-\prod_{i = 1}^n (1-x_i)$

    Attributes:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Notes:
    - ProbSum has <b>vanishing gradients</b> for the case that at least two
    values $a_i$ are $1.$.
    For the case that exactly one $a_i$ equals $1.$, we have a
    <b>single-passing gradient</b> for this value.
    """

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the ProbSum fuzzy aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            ProbSum fuzzy aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        # Prepare input
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_ones(xs)

        return 1.0 - AggregProd()(
            1.0 - xs,
            axis=axis,
            weights=weights,
            keepdims=keepdims,
            mask=mask,
            stable=stable,
        )

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array

It applies the ProbSum fuzzy aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

ProbSum fuzzy aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the ProbSum fuzzy aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        ProbSum fuzzy aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    # Prepare input
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_ones(xs)

    return 1.0 - AggregProd()(
        1.0 - xs,
        axis=axis,
        weights=weights,
        keepdims=keepdims,
        mask=mask,
        stable=stable,
    )
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

AggregProd

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregProd[AggregProd]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregProd
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregProd href "" "ltnjax.fuzzy_ops.AggregProd"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

(Weighted) Product fuzzy aggregation operator. Intended for conjunction.

Product: \(\prod_{i = 1}^n x_i\)

Weighted Product: \(\prod_{i = 1}^n x_i^{w_i}\) \(= \exp( \sum_{i = 1}^n w_i \ln x_i )\)

Attributes:

Name Type Description
stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - prod has vanishing gradients if at least two values of \(a_i\) are \(0\). If exactly one value is \(0\), we have a single-passing gradient for that value.

Methods:

Name Description
__call__

It applies the prod fuzzy aggregation operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregProd(AggregationOperator):
    r"""(Weighted) Product fuzzy aggregation operator.
    Intended for conjunction.

    Product:
    $\prod_{i = 1}^n x_i$

    Weighted Product:
    $\prod_{i = 1}^n x_i^{w_i}$
    $= \exp( \sum_{i = 1}^n w_i \ln x_i )$

    Attributes:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Notes:
    - prod has <b>vanishing gradients</b> if at least two values of $a_i$
    are $0$.
    If exactly one value is $0$, we have a <b>single-passing gradient</b>
    for that value.
    """

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the prod fuzzy aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            Prod fuzzy aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        # Prepare input
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_zeros(xs)

        # Suppress UserWarnings from fuzzy_ops.AggregSum().
        warnings.filterwarnings("ignore", category=UserWarning)
        Sum = AggregSum()

        return jnp.exp(
            Sum(
                xs=jnp.log(xs),
                axis=axis,
                weights=weights,
                keepdims=keepdims,
                mask=mask,
            )
        )

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array

It applies the prod fuzzy aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

Prod fuzzy aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the prod fuzzy aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        Prod fuzzy aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    # Prepare input
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_zeros(xs)

    # Suppress UserWarnings from fuzzy_ops.AggregSum().
    warnings.filterwarnings("ignore", category=UserWarning)
    Sum = AggregSum()

    return jnp.exp(
        Sum(
            xs=jnp.log(xs),
            axis=axis,
            weights=weights,
            keepdims=keepdims,
            mask=mask,
        )
    )
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

AggregQMean

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregQMean[AggregQMean]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregQMean
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregQMean href "" "ltnjax.fuzzy_ops.AggregQMean"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Quadratic mean or root mean square aggregation operator. Intended for disjunction as it approximates the maximum operator.

Quadratic mean: \(\sqrt{\sum_{i = 1}^n x_i^2 / n}\)

Weighted quadratic mean: \(\sqrt{ \frac{\sum_{i=1}^n w_i x_i^2}{\sum_{i=1}^n w_i} }\)

Methods:

Name Description
__call__

It applies the quadratic mean aggregation operator to the given

__init__

Constructor.

Attributes:

Name Type Description
stable
Source code in src/ltnjax/fuzzy_ops.py
class AggregQMean(AggregationOperator):
    r"""Quadratic mean or root mean square aggregation operator. Intended for
    disjunction as it approximates the maximum operator.

    Quadratic mean:
    $\sqrt{\sum_{i = 1}^n x_i^2 / n}$

    Weighted quadratic mean:
    $\sqrt{ \frac{\sum_{i=1}^n w_i x_i^2}{\sum_{i=1}^n w_i} }$
    """

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
        stable: bool | None = None,
    ) -> Array:
        """It applies the quadratic mean aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            Quadratic mean aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)
        # Preparing input
        stable = self.stable if stable is None else stable
        if stable:
            xs = not_zeros(xs)

        if weights is None:
            return jnp.sqrt(
                jnp.mean(
                    jnp.square(xs), axis=axis, keepdims=keepdims, where=mask
                )
            )
        elif mask is None:
            return jnp.sqrt(
                jnp.average(
                    jnp.square(xs),
                    axis=axis,
                    weights=weights,
                    keepdims=keepdims,
                )
            )
        else:  # weights is not None and mask is not None:
            weights = jnp.asarray(weights)
            x_p = jnp.square(xs)  # may contain nan values if x_i == 0.

            # Suppress UserWarnings from fuzzy_ops.AggregSum().
            warnings.filterwarnings("ignore", category=UserWarning)
            Sum = AggregSum()

            upper = Sum(
                x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
            )
            if len(weights.shape) == 1:
                weights = jnp.broadcast_to(weights, xs.shape)
            lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
            return jnp.sqrt(jnp.divide(upper, lower))

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array

It applies the quadratic mean aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

Quadratic mean aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
    stable: bool | None = None,
) -> Array:
    """It applies the quadratic mean aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        Quadratic mean aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)
    # Preparing input
    stable = self.stable if stable is None else stable
    if stable:
        xs = not_zeros(xs)

    if weights is None:
        return jnp.sqrt(
            jnp.mean(
                jnp.square(xs), axis=axis, keepdims=keepdims, where=mask
            )
        )
    elif mask is None:
        return jnp.sqrt(
            jnp.average(
                jnp.square(xs),
                axis=axis,
                weights=weights,
                keepdims=keepdims,
            )
        )
    else:  # weights is not None and mask is not None:
        weights = jnp.asarray(weights)
        x_p = jnp.square(xs)  # may contain nan values if x_i == 0.

        # Suppress UserWarnings from fuzzy_ops.AggregSum().
        warnings.filterwarnings("ignore", category=UserWarning)
        Sum = AggregSum()

        upper = Sum(
            x_p, axis=axis, weights=weights, keepdims=keepdims, mask=mask
        )
        if len(weights.shape) == 1:
            weights = jnp.broadcast_to(weights, xs.shape)
        lower = jnp.sum(weights, axis=axis, keepdims=keepdims, where=mask)
        return jnp.sqrt(jnp.divide(upper, lower))
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

AggregSum

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregSum[AggregSum]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregSum
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregSum href "" "ltnjax.fuzzy_ops.AggregSum"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

(Weighted) Sum aggregation operator.

\(\sum_{i = 1}^n w_i x_n\)

Methods:

Name Description
__call__

It applies the (weighted) sum operator to the given expression's

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AggregSum(AggregationOperator):
    r"""(Weighted) Sum aggregation operator.

    $\sum_{i = 1}^n w_i x_n$
    """

    def __init__(self):
        """Constructor."""
        warn(
            "`Aggreg_Sum` outputs values out of the truth value range [0,1]. "
            "Its usage with other connectives could be compromised. "
            "Use it carefully.",
            UserWarning,
            stacklevel=1,
        )

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        weights: ArrayLike | None = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the (weighted) sum operator to the given expression's
        grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            weights: (default=None) The weights for the aggregation operator.
                If `axis=None`, weights must have the same shape as `xs`.
                If there is a shape defined, it must be an `int` or `list[int]`
                containing exactly one `int` that must be the same as
                `xs.shape[axis]`.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            (Weighted) sum aggregator applied to the expression.

        Raises:
            ValueError: If `weights` are given but not compatible with `xs`.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        # axis can be int or list[int]
        if isinstance(axis, Sequence):
            axis = axis[0]

        # TODO Rewrite if jax.numpy get a weights-parameter.
        if weights is None:
            return jnp.sum(xs, axis=axis, keepdims=keepdims, where=mask)
        weights = jnp.asarray(weights)
        if mask is not None:
            xs = jnp.multiply(xs, mask)

        # Element-wise variant
        if xs.shape == weights.shape and axis is None:
            out = jnp.dot(xs.flatten(), weights.flatten())
            return (
                out if not keepdims else jnp.reshape(out, (1,) * jnp.ndim(xs))
            )

        # Aggregate along `axis` with 0-dim weights.

        if len(weights.shape) == 1 and axis is not None:
            out = jnp.tensordot(xs, weights, axes=[[axis], [0]])
            return out if not keepdims else jnp.expand_dims(out, axis)
        # None of the above cases.
        raise ValueError(
            "weights must either be None, or the same shape "
            "as `xs` or an 1D-array with length "
            "`xs.shape[axis]`."
        )

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the (weighted) sum operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
weights
ArrayLike | None

(default=None) The weights for the aggregation operator. If axis=None, weights must have the same shape as xs. If there is a shape defined, it must be an int or list[int] containing exactly one int that must be the same as xs.shape[axis].

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

(Weighted) sum aggregator applied to the expression.

Raises:

Type Description
ValueError

If weights are given but not compatible with xs.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    weights: ArrayLike | None = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the (weighted) sum operator to the given expression's
    grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        weights: (default=None) The weights for the aggregation operator.
            If `axis=None`, weights must have the same shape as `xs`.
            If there is a shape defined, it must be an `int` or `list[int]`
            containing exactly one `int` that must be the same as
            `xs.shape[axis]`.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        (Weighted) sum aggregator applied to the expression.

    Raises:
        ValueError: If `weights` are given but not compatible with `xs`.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    # axis can be int or list[int]
    if isinstance(axis, Sequence):
        axis = axis[0]

    # TODO Rewrite if jax.numpy get a weights-parameter.
    if weights is None:
        return jnp.sum(xs, axis=axis, keepdims=keepdims, where=mask)
    weights = jnp.asarray(weights)
    if mask is not None:
        xs = jnp.multiply(xs, mask)

    # Element-wise variant
    if xs.shape == weights.shape and axis is None:
        out = jnp.dot(xs.flatten(), weights.flatten())
        return (
            out if not keepdims else jnp.reshape(out, (1,) * jnp.ndim(xs))
        )

    # Aggregate along `axis` with 0-dim weights.

    if len(weights.shape) == 1 and axis is not None:
        out = jnp.tensordot(xs, weights, axes=[[axis], [0]])
        return out if not keepdims else jnp.expand_dims(out, axis)
    # None of the above cases.
    raise ValueError(
        "weights must either be None, or the same shape "
        "as `xs` or an 1D-array with length "
        "`xs.shape[axis]`."
    )
__init__
__init__()

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
def __init__(self):
    """Constructor."""
    warn(
        "`Aggreg_Sum` outputs values out of the truth value range [0,1]. "
        "Its usage with other connectives could be compromised. "
        "Use it carefully.",
        UserWarning,
        stacklevel=1,
    )

AggregYager2

Bases: AggregationOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregYager2[AggregYager2]
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.AggregationOperator --> ltnjax.fuzzy_ops.AggregYager2
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                



              click ltnjax.fuzzy_ops.AggregYager2 href "" "ltnjax.fuzzy_ops.AggregYager2"
              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

yager2 fuzzy aggregation operation. Intended for disjunction aggregation operator as it approximates :class.Aggreg_Luk_Min.

\(\min(1, \sqrt(\sum_{i = 1}^n x_i^2))\)

Notes: - We have vanishing gradients for the case \(\sqrt(\sum_{i = 1}^n x_i^2) > 1\). For the case that \(\sqrt(\sum_{i = 1}^n x_i^2) = 1\), all gradients are \(0.5\).

Methods:

Name Description
__call__

It applies the Yager2 fuzzy aggregation operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class AggregYager2(AggregationOperator):
    r"""yager2 fuzzy aggregation operation. Intended for disjunction
    aggregation operator as it approximates :class.`Aggreg_Luk_Min`.

    $\min(1, \sqrt(\sum_{i = 1}^n x_i^2))$

    Notes:
    - We have <b>vanishing gradients</b> for the case
    $\sqrt(\sum_{i = 1}^n x_i^2) > 1$.
    For the case that $\sqrt(\sum_{i = 1}^n x_i^2) = 1$, all gradients
    are $0.5$.
    """

    def __call__(
        self,
        xs: ArrayLike,
        axis: Axis = None,
        keepdims: bool = False,
        mask: ArrayLike | None = None,
    ) -> Array:
        """It applies the Yager2 fuzzy aggregation operator to the given
        expression's grounding on the selected dimensions.

        Args:
            xs: Grounding of expression on which the aggregation has to be
                performed.
            axis: (default=None) Axis along which the aggregation to be
                computed. If None, the aggregation is computed along all the
                axes.
            keepdims: (default=False) Flag indicating whether the output has to
                keep the same dimensions as the input after the aggregation.
            mask: (default=None) Boolean mask for excluding values of 'xs'
                from the aggregation. It is internally used for guarded
                quantification. The mask must have the same shape of 'xs'.
                `False` means exclusion, `True` means inclusion.

        Returns:
            Yager2 fuzzy aggregation applied to the expression.
        """
        # ArrayLike to Array
        xs = jnp.asarray(xs)

        return jnp.minimum(
            1.0,
            jnp.sqrt(
                jnp.sum(
                    jnp.square(xs), axis=axis, keepdims=keepdims, where=mask
                )
            ),
        )

Methods:

__call__
__call__(
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array

It applies the Yager2 fuzzy aggregation operator to the given expression's grounding on the selected dimensions.

Parameters:

Name Type Description Default
xs
ArrayLike

Grounding of expression on which the aggregation has to be performed.

required
axis
Axis

(default=None) Axis along which the aggregation to be computed. If None, the aggregation is computed along all the axes.

None
keepdims
bool

(default=False) Flag indicating whether the output has to keep the same dimensions as the input after the aggregation.

False
mask
ArrayLike | None

(default=None) Boolean mask for excluding values of 'xs' from the aggregation. It is internally used for guarded quantification. The mask must have the same shape of 'xs'. False means exclusion, True means inclusion.

None

Returns:

Type Description
Array

Yager2 fuzzy aggregation applied to the expression.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self,
    xs: ArrayLike,
    axis: Axis = None,
    keepdims: bool = False,
    mask: ArrayLike | None = None,
) -> Array:
    """It applies the Yager2 fuzzy aggregation operator to the given
    expression's grounding on the selected dimensions.

    Args:
        xs: Grounding of expression on which the aggregation has to be
            performed.
        axis: (default=None) Axis along which the aggregation to be
            computed. If None, the aggregation is computed along all the
            axes.
        keepdims: (default=False) Flag indicating whether the output has to
            keep the same dimensions as the input after the aggregation.
        mask: (default=None) Boolean mask for excluding values of 'xs'
            from the aggregation. It is internally used for guarded
            quantification. The mask must have the same shape of 'xs'.
            `False` means exclusion, `True` means inclusion.

    Returns:
        Yager2 fuzzy aggregation applied to the expression.
    """
    # ArrayLike to Array
    xs = jnp.asarray(xs)

    return jnp.minimum(
        1.0,
        jnp.sqrt(
            jnp.sum(
                jnp.square(xs), axis=axis, keepdims=keepdims, where=mask
            )
        ),
    )

AggregationOperator

Bases: ConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.AggregationOperator[AggregationOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.AggregationOperator
                


              click ltnjax.fuzzy_ops.AggregationOperator href "" "ltnjax.fuzzy_ops.AggregationOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Abstract class for aggregation operators.

Raises:

Type Description
NotImplementedError

Raised when call is not implemented in the sub-class.

Methods:

Name Description
__call__

Implements the behavior of the aggregation operator.

Source code in src/ltnjax/fuzzy_ops.py
class AggregationOperator(ConnectiveOperator):
    """Abstract class for aggregation operators.

    Raises:
        NotImplementedError: Raised when
            [__call__][ltnjax.fuzzy_ops.AggregationOperator.__call__]
            is not implemented in the sub-class.
    """

    @abstractmethod
    def __call__(self, *args: Any, **kwargs: Any):
        """Implements the behavior of the aggregation operator.

        Args:
            args: Arguments.
            kwargs: Keyword arguments.

        Raises:
            NotImplementedError: Always.
        """
        raise NotImplementedError()

Methods:

__call__ abstractmethod
__call__(*args: Any, **kwargs: Any)

Implements the behavior of the aggregation operator.

Parameters:

Name Type Description Default
args
Any

Arguments.

()
kwargs
Any

Keyword arguments.

{}

Raises:

Type Description
NotImplementedError

Always.

Source code in src/ltnjax/fuzzy_ops.py
@abstractmethod
def __call__(self, *args: Any, **kwargs: Any):
    """Implements the behavior of the aggregation operator.

    Args:
        args: Arguments.
        kwargs: Keyword arguments.

    Raises:
        NotImplementedError: Always.
    """
    raise NotImplementedError()

AndLuk

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.AndLuk[AndLuk]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.AndLuk
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.AndLuk href "" "ltnjax.fuzzy_ops.AndLuk"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Lukasiewicz fuzzy conjunction operator.

\(\land_{Lukasiewicz}(x, y) = \max(x + y - 1, 0)\)

Notes: - And_Luk has vanishing gradients if \(x+y < 1.\). If \(x+y = 1\), both gradients are \(0.5\).

Methods:

Name Description
__call__

It applies the Lukasiewicz fuzzy conjunction operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class AndLuk(BinaryConnectiveOperator):
    r"""Lukasiewicz fuzzy conjunction operator.

    $\land_{Lukasiewicz}(x, y) = \max(x + y - 1, 0)$

    Notes:
    - And_Luk has vanishing gradients if $x+y < 1.$.
    If $x+y = 1$, both gradients are $0.5$.
    """

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the Lukasiewicz fuzzy conjunction operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The Lukasiewicz fuzzy conjunction of the two operands.
        """
        return jnp.maximum(x + y - 1.0, 0.0)

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the Lukasiewicz fuzzy conjunction operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The Lukasiewicz fuzzy conjunction of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the Lukasiewicz fuzzy conjunction operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The Lukasiewicz fuzzy conjunction of the two operands.
    """
    return jnp.maximum(x + y - 1.0, 0.0)

AndMin

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.AndMin[AndMin]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.AndMin
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.AndMin href "" "ltnjax.fuzzy_ops.AndMin"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Godel fuzzy conjunction operator (min operator).

\(\land_{Godel}(x, y) := \min(x,y)\)

Notes: - \(\min\) has a single-passing gradient if the values \(x\) and \(y\) are not equal, i.e. the smaller one has \(1\) and the other one is \(0\). If both values are equal, both gradients equal \(0.5\).

Methods:

Name Description
__call__

It applies the Godel fuzzy conjunction operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class AndMin(BinaryConnectiveOperator):
    r"""Godel fuzzy conjunction operator (min operator).

    $\land_{Godel}(x, y) := \min(x,y)$

    Notes:
    - $\min$ has a <b>single-passing gradient</b> if the values
    $x$ and $y$ are not equal, i.e. the smaller one has $1$
    and the other one is $0$. If both values are equal, both gradients
    equal $0.5$.
    """

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the Godel fuzzy conjunction operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The Godel fuzzy conjunction of the two operands.
        """
        return jnp.minimum(x, y)

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the Godel fuzzy conjunction operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The Godel fuzzy conjunction of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the Godel fuzzy conjunction operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The Godel fuzzy conjunction of the two operands.
    """
    return jnp.minimum(x, y)

AndProd

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.AndProd[AndProd]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.AndProd
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.AndProd href "" "ltnjax.fuzzy_ops.AndProd"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Goguen fuzzy conjunction operator (product operator).

\(\land_{Goguen}(x, y) = xy\)

Attributes:

Name Type Description
stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - product t-norm has vanishing gradients for \(x=y=0\).

Methods:

Name Description
__call__

It applies the Goguen fuzzy conjunction operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class AndProd(BinaryConnectiveOperator):
    r"""Goguen fuzzy conjunction operator (product operator).

    $\land_{Goguen}(x, y) = xy$

    Attributes:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Notes:
    - product t-norm has <b>vanishing gradients</b> for $x=y=0$.
    """

    def __init__(self, stable: bool = True):
        """
        Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self, x: ArrayLike, y: ArrayLike, stable: bool | None = None
    ) -> Array:
        """It applies the Goguen fuzzy conjunction operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            The Goguen fuzzy conjunction of the two operands.
        """
        stable = self.stable if stable is None else stable
        if stable:
            x, y = not_zeros(x), not_zeros(y)
        return jnp.multiply(x, y)

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike, stable: bool | None = None) -> Array

It applies the Goguen fuzzy conjunction operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

The Goguen fuzzy conjunction of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self, x: ArrayLike, y: ArrayLike, stable: bool | None = None
) -> Array:
    """It applies the Goguen fuzzy conjunction operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        The Goguen fuzzy conjunction of the two operands.
    """
    stable = self.stable if stable is None else stable
    if stable:
        x, y = not_zeros(x), not_zeros(y)
    return jnp.multiply(x, y)
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """
    Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

BinaryConnectiveOperator

Bases: ConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                


              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Abstract class for binary connective operators.

Raises:

Type Description
NotImplementedError

Raised when call is not implemented in the sub-class.

Methods:

Name Description
__call__

Implements the behavior of the connective binary operator.

Source code in src/ltnjax/fuzzy_ops.py
class BinaryConnectiveOperator(ConnectiveOperator):
    """Abstract class for binary connective operators.

    Raises:
        NotImplementedError: Raised when
            [__call__][ltnjax.fuzzy_ops.BinaryConnectiveOperator.__call__] is
            not implemented in the sub-class.
    """

    @abstractmethod
    def __call__(self, *args: Any, **kwargs: Any):
        """Implements the behavior of the connective binary operator.

        Args:
            args: Arguments.
            kwargs: Keyword arguments.

        Raises:
            NotImplementedError: Always.
        """
        raise NotImplementedError()

Methods:

__call__ abstractmethod
__call__(*args: Any, **kwargs: Any)

Implements the behavior of the connective binary operator.

Parameters:

Name Type Description Default
args
Any

Arguments.

()
kwargs
Any

Keyword arguments.

{}

Raises:

Type Description
NotImplementedError

Always.

Source code in src/ltnjax/fuzzy_ops.py
@abstractmethod
def __call__(self, *args: Any, **kwargs: Any):
    """Implements the behavior of the connective binary operator.

    Args:
        args: Arguments.
        kwargs: Keyword arguments.

    Raises:
        NotImplementedError: Always.
    """
    raise NotImplementedError()

ConnectiveOperator

Bases: ABC


              flowchart TD
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

              

              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Abstract class for connective operators.

Raises:

Type Description
NotImplementedError

Raised when call is not implemented in the sub-class.

Methods:

Name Description
__call__

Implements the behavior of the connective operator.

Source code in src/ltnjax/fuzzy_ops.py
class ConnectiveOperator(ABC):
    """Abstract class for connective operators.

    Raises:
        NotImplementedError: Raised when
            [__call__][ltnjax.fuzzy_ops.ConnectiveOperator.__call__]
            is not implemented in the sub-class.
    """

    @abstractmethod
    def __call__(self, *args: Any, **kwargs: Any):
        """Implements the behavior of the connective operator.

        Args:
            args: Arguments.
            kwargs: Keyword arguments.

        Raises:
            NotImplementedError: Always.
        """
        raise NotImplementedError()

Methods:

__call__ abstractmethod
__call__(*args: Any, **kwargs: Any)

Implements the behavior of the connective operator.

Parameters:

Name Type Description Default
args
Any

Arguments.

()
kwargs
Any

Keyword arguments.

{}

Raises:

Type Description
NotImplementedError

Always.

Source code in src/ltnjax/fuzzy_ops.py
@abstractmethod
def __call__(self, *args: Any, **kwargs: Any):
    """Implements the behavior of the connective operator.

    Args:
        args: Arguments.
        kwargs: Keyword arguments.

    Raises:
        NotImplementedError: Always.
    """
    raise NotImplementedError()

Equiv

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.Equiv[Equiv]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.Equiv
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.Equiv href "" "ltnjax.fuzzy_ops.Equiv"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Equivalence (\(\leftrightarrow\)) fuzzy operator.

\(x \leftrightarrow y \equiv x \rightarrow y \land y \rightarrow x\)

Attributes:

Name Type Description
and_op

Fuzzy operator for the conjunction.

implies_op

Fuzzy operator for the implication.

Notes: - the equivalence operator (\(\leftrightarrow\)) is implemented as an operator which computes: \(x \rightarrow y \land y \rightarrow x\); - the and_op parameter defines the operator for \(\land\); - the implies_op parameter defines the operator for \(\rightarrow\).

Methods:

Name Description
__call__

It applies the fuzzy equivalence operator to the given operands.

__init__

This constructor has to be used to set the operator for the

Source code in src/ltnjax/fuzzy_ops.py
class Equiv(BinaryConnectiveOperator):
    r"""Equivalence ($\leftrightarrow$) fuzzy operator.

    $x \leftrightarrow y \equiv x \rightarrow y \land y \rightarrow x$

    Attributes:
        and_op: Fuzzy operator for the conjunction.
        implies_op: Fuzzy operator for the implication.

    Notes:
    - the equivalence operator ($\leftrightarrow$) is implemented as an
    operator which computes: $x \rightarrow y \land y \rightarrow x$;
    - the `and_op` parameter defines the operator for $\land$;
    - the `implies_op` parameter defines the operator for $\rightarrow$.
    """  # noqa: E501

    def __init__(
        self,
        and_op: BinaryConnectiveOperator,
        implies_op: BinaryConnectiveOperator,
    ):
        """This constructor has to be used to set the operator for the
        conjunction and for the implication of the equivalence operator.

        Args:
            and_op: Fuzzy operator for the conjunction.
            implies_op: Fuzzy operator for the implication.
        """
        self.and_op = and_op
        self.implies_op = implies_op

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the fuzzy equivalence operator to the given operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The fuzzy equivalence of the two operands.
        """
        return self.and_op(self.implies_op(x, y), self.implies_op(y, x))

Attributes

and_op instance-attribute
and_op = and_op
implies_op instance-attribute
implies_op = implies_op

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the fuzzy equivalence operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The fuzzy equivalence of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the fuzzy equivalence operator to the given operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The fuzzy equivalence of the two operands.
    """
    return self.and_op(self.implies_op(x, y), self.implies_op(y, x))
__init__

This constructor has to be used to set the operator for the conjunction and for the implication of the equivalence operator.

Parameters:

Name Type Description Default
and_op
BinaryConnectiveOperator

Fuzzy operator for the conjunction.

required
implies_op
BinaryConnectiveOperator

Fuzzy operator for the implication.

required
Source code in src/ltnjax/fuzzy_ops.py
def __init__(
    self,
    and_op: BinaryConnectiveOperator,
    implies_op: BinaryConnectiveOperator,
):
    """This constructor has to be used to set the operator for the
    conjunction and for the implication of the equivalence operator.

    Args:
        and_op: Fuzzy operator for the conjunction.
        implies_op: Fuzzy operator for the implication.
    """
    self.and_op = and_op
    self.implies_op = implies_op

Implies

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.Implies[Implies]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.Implies
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.Implies href "" "ltnjax.fuzzy_ops.Implies"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Implies (\(\Rightarrow\)) fuzzy operator.

An Implies operator that uses given negation and disjunction operators. This uses \(p \Rightarrow q \equiv \not p \lor q\).

Attributes:

Name Type Description
not_op

Fuzzy negation operator to use for the negation operator. or_op: Fuzzy disjunction operator to use for the disjunction operator.

Methods:

Name Description
__call__

It applies the fuzzy implies operator to the given operands.

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class Implies(BinaryConnectiveOperator):
    r"""Implies ($\Rightarrow$) fuzzy operator.

    An Implies operator that uses given negation and disjunction operators.
    This uses $p \Rightarrow q \equiv \not p \lor q$.

    Attributes:
        not_op: Fuzzy negation operator to use for the negation operator.
            or_op: Fuzzy disjunction operator to use for the disjunction
                operator.
    """

    def __init__(
        self, not_op: UnaryConnectiveOperator, or_op: BinaryConnectiveOperator
    ):
        """Constructor.

        Args:
            not_op: Fuzzy negation operator to use for the negation operator.
            or_op: Fuzzy disjunction operator to use for the disjunction
                operator.
        """
        self.not_op = not_op
        self.or_op = or_op

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the fuzzy implies operator to the given operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The fuzzy implies of the two operands.
        """
        return self.or_op(self.not_op(x), y)

Attributes

not_op instance-attribute
not_op = not_op
or_op instance-attribute
or_op = or_op

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the fuzzy implies operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The fuzzy implies of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the fuzzy implies operator to the given operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The fuzzy implies of the two operands.
    """
    return self.or_op(self.not_op(x), y)
__init__

Constructor.

Parameters:

Name Type Description Default
not_op
UnaryConnectiveOperator

Fuzzy negation operator to use for the negation operator.

required
or_op
BinaryConnectiveOperator

Fuzzy disjunction operator to use for the disjunction operator.

required
Source code in src/ltnjax/fuzzy_ops.py
def __init__(
    self, not_op: UnaryConnectiveOperator, or_op: BinaryConnectiveOperator
):
    """Constructor.

    Args:
        not_op: Fuzzy negation operator to use for the negation operator.
        or_op: Fuzzy disjunction operator to use for the disjunction
            operator.
    """
    self.not_op = not_op
    self.or_op = or_op

ImpliesGodel

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.ImpliesGodel[ImpliesGodel]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.ImpliesGodel
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.ImpliesGodel href "" "ltnjax.fuzzy_ops.ImpliesGodel"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Godel fuzzy implication operand.

\(\rightarrow_{Godel}(x, y) = \left\{\begin{array}{ c l }1 & \quad \textrm{if } x \le y \\ y & \quad \textrm{otherwise} \end{array} \right.\)

Notes: - Implies_Godel has vanishing gradients if \(x<=y\). Otherwise, it passes a single gradient for \(y\) if \(x>y\).

Methods:

Name Description
__call__

It applies the Godel fuzzy implication operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class ImpliesGodel(BinaryConnectiveOperator):
    r"""Godel fuzzy implication operand.

    $\rightarrow_{Godel}(x, y) = \left\{\begin{array}{ c l }1 & \quad \textrm{if } x \le y \\ y & \quad \textrm{otherwise} \end{array} \right.$

    Notes:
    - Implies_Godel has <b>vanishing gradients</b> if $x<=y$.
    Otherwise, it <b>passes a single gradient</b> for $y$ if $x>y$.
    """  # noqa: E501

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the Godel fuzzy implication operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The Godel fuzzy implication of the two operands.
        """
        return jnp.where(jnp.less_equal(x, y), jnp.ones_like(x), y)

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the Godel fuzzy implication operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The Godel fuzzy implication of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the Godel fuzzy implication operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The Godel fuzzy implication of the two operands.
    """
    return jnp.where(jnp.less_equal(x, y), jnp.ones_like(x), y)

ImpliesGoguen

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.ImpliesGoguen[ImpliesGoguen]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.ImpliesGoguen
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.ImpliesGoguen href "" "ltnjax.fuzzy_ops.ImpliesGoguen"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Goguen fuzzy implication operator.

\(\rightarrow_{Goguen}(x, y) = \left\{\begin{array}{ c l }1 & \quad \textrm{if } x \le y \\ \frac{y}{x} & \quad \textrm{otherwise} \end{array} \right.\)

Parameters:

Name Type Description Default

stable

bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True

Notes: - This expression is only defined if \(x != 0\). - This expression has vanishing gradients if \(x <= y\). This can be prevented by using its stable version.

Methods:

Name Description
__call__

It applies the Goguen fuzzy implication operator to the given

__init__

Constructor.

Attributes:

Name Type Description
stable
Source code in src/ltnjax/fuzzy_ops.py
class ImpliesGoguen(BinaryConnectiveOperator):
    r"""Goguen fuzzy implication operator.

    $\rightarrow_{Goguen}(x, y) = \left\{\begin{array}{ c l }1 & \quad \textrm{if } x \le y \\ \frac{y}{x} & \quad \textrm{otherwise} \end{array} \right.$

    Parameters:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Notes:
    - This expression is <b>only defined</b> if $x != 0$.
    - This expression has <b>vanishing gradients</b> if $x <= y$.
    This can be prevented by using its [stable](../../stable.md) version.
    """  # noqa: E501

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self, x: ArrayLike, y: ArrayLike, stable: bool | None = None
    ) -> Array:
        """It applies the Goguen fuzzy implication operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            The Goguen fuzzy implication of the two operands.
        """
        stable = self.stable if stable is None else stable
        if stable:
            x = not_zeros(x)
        return jnp.where(
            jnp.less_equal(x, y), jnp.ones_like(x), jnp.divide(y, x)
        )

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike, stable: bool | None = None) -> Array

It applies the Goguen fuzzy implication operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

The Goguen fuzzy implication of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self, x: ArrayLike, y: ArrayLike, stable: bool | None = None
) -> Array:
    """It applies the Goguen fuzzy implication operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        The Goguen fuzzy implication of the two operands.
    """
    stable = self.stable if stable is None else stable
    if stable:
        x = not_zeros(x)
    return jnp.where(
        jnp.less_equal(x, y), jnp.ones_like(x), jnp.divide(y, x)
    )
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

ImpliesKleeneDienes

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.ImpliesKleeneDienes[ImpliesKleeneDienes]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.ImpliesKleeneDienes
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.ImpliesKleeneDienes href "" "ltnjax.fuzzy_ops.ImpliesKleeneDienes"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Kleene Dienes fuzzy implication operator.

\(\rightarrow_{KleeneDienes}(x, y) = \max(1 - x, y)\)

Notes: - Implies_KleeneDienes has a single-passing gradient for either \(x\) if \(1.-x>y\), or for \(y\) if \(1.-x<y\). If \(1.-x=y\), both gradients are \(0.5\).

Methods:

Name Description
__call__

It applies the Kleene Dienes fuzzy implication operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class ImpliesKleeneDienes(BinaryConnectiveOperator):
    r"""Kleene Dienes fuzzy implication operator.

    $\rightarrow_{KleeneDienes}(x, y) = \max(1 - x, y)$

    Notes:
    - Implies_KleeneDienes has a <b>single-passing gradient</b> for either
    $x$ if $1.-x>y$, or for $y$ if $1.-x<y$.
    If $1.-x=y$, both gradients are $0.5$.
    """

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the Kleene Dienes fuzzy implication operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The Kleene Dienes fuzzy implication of the two operands.
        """
        return jnp.maximum(1.0 - x, y)

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the Kleene Dienes fuzzy implication operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The Kleene Dienes fuzzy implication of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the Kleene Dienes fuzzy implication operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The Kleene Dienes fuzzy implication of the two operands.
    """
    return jnp.maximum(1.0 - x, y)

ImpliesLuk

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.ImpliesLuk[ImpliesLuk]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.ImpliesLuk
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.ImpliesLuk href "" "ltnjax.fuzzy_ops.ImpliesLuk"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Lukasiewicz fuzzy implication operator.

\(\rightarrow_{Lukasiewicz}(x, y) = \min(1 - x + y, 1)\)

Notes: - Implies_Luk has vanishing gradients for \(-x+y>0\). For \(-x+y=0\), both gradients are \(0.5\).

Methods:

Name Description
__call__

It applies the Lukasiewicz fuzzy implication operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class ImpliesLuk(BinaryConnectiveOperator):
    r"""Lukasiewicz fuzzy implication operator.

    $\rightarrow_{Lukasiewicz}(x, y) = \min(1 - x + y, 1)$

    Notes:
    - Implies_Luk has <b>vanishing gradients</b> for $-x+y>0$.
    For $-x+y=0$, both gradients are $0.5$.
    """

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the Lukasiewicz fuzzy implication operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The Lukasiewicz fuzzy implication of the two operands.
        """
        return jnp.minimum(1.0 - x + y, 1.0)

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the Lukasiewicz fuzzy implication operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The Lukasiewicz fuzzy implication of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the Lukasiewicz fuzzy implication operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The Lukasiewicz fuzzy implication of the two operands.
    """
    return jnp.minimum(1.0 - x + y, 1.0)

ImpliesReichenbach

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.ImpliesReichenbach[ImpliesReichenbach]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.ImpliesReichenbach
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.ImpliesReichenbach href "" "ltnjax.fuzzy_ops.ImpliesReichenbach"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Reichenbach fuzzy implication operator.

\(\rightarrow_{Reichenbach}(x, y) = 1 - x + xy\)

Attributes:

Name Type Description
stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - The Reichenbach implication has vanishing gradients for \(x=0, y=1\). This can be prevented by using its stable version. - This implies operator is implemented using \(u \implies v \Leftrightarrow \neq p \lor q\) using NotStandard and OrProbSum.

Methods:

Name Description
__call__

It applies the Reichenbach fuzzy implication operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class ImpliesReichenbach(BinaryConnectiveOperator):
    r"""Reichenbach fuzzy implication operator.

    $\rightarrow_{Reichenbach}(x, y) = 1 - x + xy$

    Attributes:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Notes:
    - The Reichenbach implication has <b>vanishing gradients</b> for
    $x=0, y=1$.
    This can be prevented by using its [stable](../../stable.md) version.
    - This implies operator is implemented using
    $u \implies v \Leftrightarrow \neq p \lor q$ using
    [NotStandard][ltnjax.fuzzy_ops.NotStandard] and
    [OrProbSum][ltnjax.fuzzy_ops.OrProbSum].
    """

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self, x: ArrayLike, y: ArrayLike, stable: bool | None = None
    ) -> Array:
        """It applies the Reichenbach fuzzy implication operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            The Reichenbach fuzzy implication of the two operands.
        """
        stable = self.stable if stable is None else stable
        if stable:
            x, y = not_zeros(x), not_ones(y)
        return jnp.add(jnp.subtract(1.0, x), jnp.multiply(x, y))

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike, stable: bool | None = None) -> Array

It applies the Reichenbach fuzzy implication operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

The Reichenbach fuzzy implication of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self, x: ArrayLike, y: ArrayLike, stable: bool | None = None
) -> Array:
    """It applies the Reichenbach fuzzy implication operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        The Reichenbach fuzzy implication of the two operands.
    """
    stable = self.stable if stable is None else stable
    if stable:
        x, y = not_zeros(x), not_ones(y)
    return jnp.add(jnp.subtract(1.0, x), jnp.multiply(x, y))
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

NotGodel

Bases: UnaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.NotGodel[NotGodel]
              ltnjax.fuzzy_ops.UnaryConnectiveOperator[UnaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.UnaryConnectiveOperator --> ltnjax.fuzzy_ops.NotGodel
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.UnaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.NotGodel href "" "ltnjax.fuzzy_ops.NotGodel"
              click ltnjax.fuzzy_ops.UnaryConnectiveOperator href "" "ltnjax.fuzzy_ops.UnaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Godel fuzzy negation operator.

\(x == 0\)

Notes: - This is not recommended for machine learning as the gradient will always be \(0\).

Methods:

Name Description
__call__

It applies the Godel fuzzy negation operator to the given operand.

Source code in src/ltnjax/fuzzy_ops.py
class NotGodel(UnaryConnectiveOperator):
    """Godel fuzzy negation operator.

    $x == 0$

    Notes:
    - This is not recommended for machine learning as the gradient will always
    be $0$.
    """

    def __call__(self, x: ArrayLike) -> Array:
        """It applies the Godel fuzzy negation operator to the given operand.

        Args:
            x: Operand on which the operator has to be applied.

        Returns:
            The Godel fuzzy negation of the given operand.
        """
        return jnp.astype(jnp.equal(x, 0), jnp.float32)

Methods:

__call__
__call__(x: ArrayLike) -> Array

It applies the Godel fuzzy negation operator to the given operand.

Parameters:

Name Type Description Default
x
ArrayLike

Operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The Godel fuzzy negation of the given operand.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike) -> Array:
    """It applies the Godel fuzzy negation operator to the given operand.

    Args:
        x: Operand on which the operator has to be applied.

    Returns:
        The Godel fuzzy negation of the given operand.
    """
    return jnp.astype(jnp.equal(x, 0), jnp.float32)

NotStandard

Bases: UnaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.NotStandard[NotStandard]
              ltnjax.fuzzy_ops.UnaryConnectiveOperator[UnaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.UnaryConnectiveOperator --> ltnjax.fuzzy_ops.NotStandard
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.UnaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.NotStandard href "" "ltnjax.fuzzy_ops.NotStandard"
              click ltnjax.fuzzy_ops.UnaryConnectiveOperator href "" "ltnjax.fuzzy_ops.UnaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Standard fuzzy negation operator.

\(1-x\)

Methods:

Name Description
__call__

It applies the standard fuzzy negation operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class NotStandard(UnaryConnectiveOperator):
    """Standard fuzzy negation operator.

    $1-x$
    """

    def __call__(self, x: ArrayLike) -> Array:
        """It applies the standard fuzzy negation operator to the given
        operand.

        Args:
            x: Operand on which the operator has to be applied.

        Returns:
            The standard fuzzy negation of the given operand.
        """
        return jnp.subtract(1.0, x)

Methods:

__call__
__call__(x: ArrayLike) -> Array

It applies the standard fuzzy negation operator to the given operand.

Parameters:

Name Type Description Default
x
ArrayLike

Operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The standard fuzzy negation of the given operand.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike) -> Array:
    """It applies the standard fuzzy negation operator to the given
    operand.

    Args:
        x: Operand on which the operator has to be applied.

    Returns:
        The standard fuzzy negation of the given operand.
    """
    return jnp.subtract(1.0, x)

OrLuk

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.OrLuk[OrLuk]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.OrLuk
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.OrLuk href "" "ltnjax.fuzzy_ops.OrLuk"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Lukasiewicz fuzzy disjunction operator.

\(\lor_{Lukasiewicz}(x, y) = \min(x + y, 1)\)

Notes: - Or_Luk has vanishing gradients for \(x+y>1\). If \(x+y=1\), both gradients will be \(0.5\).

Methods:

Name Description
__call__

It applies the Lukasiewicz fuzzy disjunction operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class OrLuk(BinaryConnectiveOperator):
    r"""Lukasiewicz fuzzy disjunction operator.

    $\lor_{Lukasiewicz}(x, y) = \min(x + y, 1)$

    Notes:
    - Or_Luk has <b>vanishing gradients</b> for $x+y>1$.
    If $x+y=1$, both gradients will be $0.5$.
    """

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the Lukasiewicz fuzzy disjunction operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The Lukasiewicz fuzzy disjunction of the two operands.
        """
        return jnp.minimum(x + y, 1.0)

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the Lukasiewicz fuzzy disjunction operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The Lukasiewicz fuzzy disjunction of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the Lukasiewicz fuzzy disjunction operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The Lukasiewicz fuzzy disjunction of the two operands.
    """
    return jnp.minimum(x + y, 1.0)

OrMax

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.OrMax[OrMax]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.OrMax
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.OrMax href "" "ltnjax.fuzzy_ops.OrMax"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Godel fuzzy disjunction operator (max operator).

\(\lor_{Godel}(x, y) = \max(x, y)\)

Notes: - \(\max\) has a single-passing gradient if the values \(x\) and \(y\) are not equal, i.e. the larger one has \(1\) and the other one is \(0\). If both values are equal, both gradients equal \(0.5\).

Methods:

Name Description
__call__

It applies the Godel fuzzy disjunction operator to the given

Source code in src/ltnjax/fuzzy_ops.py
class OrMax(BinaryConnectiveOperator):
    r"""Godel fuzzy disjunction operator (max operator).

    $\lor_{Godel}(x, y) = \max(x, y)$

    Notes:
    - $\max$ has a <b>single-passing gradient</b> if the values
    $x$ and $y$ are not equal,
    i.e. the larger one has $1$ and the other one is $0$.
    If both values are equal, both gradients equal $0.5$.
    """

    def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
        """It applies the Godel fuzzy disjunction operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.

        Returns:
            The Godel fuzzy disjunction of the two operands.
        """
        return jnp.maximum(x, y)

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike) -> Array

It applies the Godel fuzzy disjunction operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required

Returns:

Type Description
Array

The Godel fuzzy disjunction of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(self, x: ArrayLike, y: ArrayLike) -> Array:
    """It applies the Godel fuzzy disjunction operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.

    Returns:
        The Godel fuzzy disjunction of the two operands.
    """
    return jnp.maximum(x, y)

OrProbSum

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.OrProbSum[OrProbSum]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.OrProbSum
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.OrProbSum href "" "ltnjax.fuzzy_ops.OrProbSum"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Goguen fuzzy disjunction operator (probabilistic sum).

\(\lor_{Goguen}(x, y) = x + y - xy\)

Attributes:

Name Type Description
stable

(default=True) Flag indicating whether to use the stable version of the operator or not.

Notes: - The product t-conorm has vanishing gradients for \(x=y=1\). - This or operator is implemented using De Morgans's law \(u \lor v \Leftrightarrow \neq u \land \neq v\) and the implementations NotStandard and AndProd.

Methods:

Name Description
__call__

It applies the Goguen fuzzy disjunction operator to the given

__init__

Constructor.

Source code in src/ltnjax/fuzzy_ops.py
class OrProbSum(BinaryConnectiveOperator):
    r"""Goguen fuzzy disjunction operator (probabilistic sum).

    $\lor_{Goguen}(x, y) = x + y - xy$

    Attributes:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Notes:
    - The product t-conorm has <b>vanishing gradients</b> for $x=y=1$.
    - This or operator is implemented using De Morgans's law
    $u \lor v \Leftrightarrow \neq u \land \neq v$ and the
    implementations [NotStandard][ltnjax.fuzzy_ops.NotStandard] and
    [AndProd][ltnjax.fuzzy_ops.AndProd].
    """

    def __init__(self, stable: bool = True):
        """Constructor.

        Args:
            stable: (default=True) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.
        """
        self.stable = stable

    def __call__(
        self, x: ArrayLike, y: ArrayLike, stable: bool | None = None
    ) -> Array:
        """It applies the Goguen fuzzy disjunction operator to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.
            stable: (default=None) Flag indicating whether to use the
                [stable](../../stable.md) version of the operator or not.

        Returns:
            The Goguen fuzzy disjunction of the two operands.
        """
        stable = self.stable if stable is None else stable
        if stable:
            x, y = not_ones(x), not_ones(y)
        return jnp.subtract(jnp.add(x, y), jnp.multiply(x, y))

Attributes

stable instance-attribute
stable = stable

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike, stable: bool | None = None) -> Array

It applies the Goguen fuzzy disjunction operator to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required
stable
bool | None

(default=None) Flag indicating whether to use the stable version of the operator or not.

None

Returns:

Type Description
Array

The Goguen fuzzy disjunction of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self, x: ArrayLike, y: ArrayLike, stable: bool | None = None
) -> Array:
    """It applies the Goguen fuzzy disjunction operator to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.
        stable: (default=None) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.

    Returns:
        The Goguen fuzzy disjunction of the two operands.
    """
    stable = self.stable if stable is None else stable
    if stable:
        x, y = not_ones(x), not_ones(y)
    return jnp.subtract(jnp.add(x, y), jnp.multiply(x, y))
__init__
__init__(stable: bool = True)

Constructor.

Parameters:

Name Type Description Default
stable
bool

(default=True) Flag indicating whether to use the stable version of the operator or not.

True
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, stable: bool = True):
    """Constructor.

    Args:
        stable: (default=True) Flag indicating whether to use the
            [stable](../../stable.md) version of the operator or not.
    """
    self.stable = stable

OrSmoothMaximumUnit

Bases: BinaryConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.OrSmoothMaximumUnit[OrSmoothMaximumUnit]
              ltnjax.fuzzy_ops.BinaryConnectiveOperator[BinaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.BinaryConnectiveOperator --> ltnjax.fuzzy_ops.OrSmoothMaximumUnit
                                ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.BinaryConnectiveOperator
                



              click ltnjax.fuzzy_ops.OrSmoothMaximumUnit href "" "ltnjax.fuzzy_ops.OrSmoothMaximumUnit"
              click ltnjax.fuzzy_ops.BinaryConnectiveOperator href "" "ltnjax.fuzzy_ops.BinaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Smooth maximum unit fuzzy disjunction operator, that approximates the maximum.

\(\max_\epsilon(a,b) = (a+b+|a-b|_\epsilon) / 2\), where we approximate \(|a-b|\) by \(\sqrt((a-b)^2 + \epsilon)\).

Attributes:

Name Type Description
epsilon

A parameter for \(|a-b|_\epsilon\) that approximates \(|a-b|\).

Methods:

Name Description
__call__

It applies the smooth maximum unit fuzzy disjunction to the given

__init__

This constructor has to be used to set the epsilon parameter.

Source code in src/ltnjax/fuzzy_ops.py
class OrSmoothMaximumUnit(BinaryConnectiveOperator):
    r"""[Smooth maximum unit](https://en.wikipedia.org/wiki/Smooth_maximum)
    fuzzy disjunction operator, that approximates the maximum.

    $\max_\epsilon(a,b) = (a+b+|a-b|_\epsilon) / 2$, where we
    approximate $|a-b|$ by $\sqrt((a-b)^2 + \epsilon)$.

    Attributes:
        epsilon: A parameter for $|a-b|_\epsilon$ that
            approximates $|a-b|$.
    """

    def __init__(self, epsilon: float = 1e-4):
        r"""This constructor has to be used to set the epsilon parameter.

        Args:
            epsilon: A parameter for $|a-b|_\epsilon$ that
                approximates $|a-b|$.
        """
        self.epsilon = epsilon

    def __call__(
        self, x: ArrayLike, y: ArrayLike, epsilon: float | None = None
    ) -> Array:
        r"""It applies the smooth maximum unit fuzzy disjunction to the given
        operands.

        Args:
            x: First operand on which the operator has to be applied.
            y: Second operand on which the operator has to be applied.
            epsilon: (default=None) Parameter for $|a-b|_\epsilon$ that
                approximates $|a-b|$.

        Returns:
            The smooth maximum unit fuzzy disjunction of the two operands.
        """
        epsilon = self.epsilon if epsilon is None else epsilon
        abs = jnp.sqrt(jnp.square(jnp.subtract(x, y)) + self.epsilon)
        return jnp.divide(x + y + abs, 2)

Attributes

epsilon instance-attribute
epsilon = epsilon

Methods:

__call__
__call__(x: ArrayLike, y: ArrayLike, epsilon: float | None = None) -> Array

It applies the smooth maximum unit fuzzy disjunction to the given operands.

Parameters:

Name Type Description Default
x
ArrayLike

First operand on which the operator has to be applied.

required
y
ArrayLike

Second operand on which the operator has to be applied.

required
epsilon
float | None

(default=None) Parameter for \(|a-b|_\epsilon\) that approximates \(|a-b|\).

None

Returns:

Type Description
Array

The smooth maximum unit fuzzy disjunction of the two operands.

Source code in src/ltnjax/fuzzy_ops.py
def __call__(
    self, x: ArrayLike, y: ArrayLike, epsilon: float | None = None
) -> Array:
    r"""It applies the smooth maximum unit fuzzy disjunction to the given
    operands.

    Args:
        x: First operand on which the operator has to be applied.
        y: Second operand on which the operator has to be applied.
        epsilon: (default=None) Parameter for $|a-b|_\epsilon$ that
            approximates $|a-b|$.

    Returns:
        The smooth maximum unit fuzzy disjunction of the two operands.
    """
    epsilon = self.epsilon if epsilon is None else epsilon
    abs = jnp.sqrt(jnp.square(jnp.subtract(x, y)) + self.epsilon)
    return jnp.divide(x + y + abs, 2)
__init__
__init__(epsilon: float = 0.0001)

This constructor has to be used to set the epsilon parameter.

Parameters:

Name Type Description Default
epsilon
float

A parameter for \(|a-b|_\epsilon\) that approximates \(|a-b|\).

0.0001
Source code in src/ltnjax/fuzzy_ops.py
def __init__(self, epsilon: float = 1e-4):
    r"""This constructor has to be used to set the epsilon parameter.

    Args:
        epsilon: A parameter for $|a-b|_\epsilon$ that
            approximates $|a-b|$.
    """
    self.epsilon = epsilon

UnaryConnectiveOperator

Bases: ConnectiveOperator


              flowchart TD
              ltnjax.fuzzy_ops.UnaryConnectiveOperator[UnaryConnectiveOperator]
              ltnjax.fuzzy_ops.ConnectiveOperator[ConnectiveOperator]

                              ltnjax.fuzzy_ops.ConnectiveOperator --> ltnjax.fuzzy_ops.UnaryConnectiveOperator
                


              click ltnjax.fuzzy_ops.UnaryConnectiveOperator href "" "ltnjax.fuzzy_ops.UnaryConnectiveOperator"
              click ltnjax.fuzzy_ops.ConnectiveOperator href "" "ltnjax.fuzzy_ops.ConnectiveOperator"
            

Abstract class for unary connective operators.

Raises:

Type Description
NotImplementedError

Raised when call is not implemented in the sub-class.

Methods:

Name Description
__call__

Implements the behavior of the unary connective operator.

Source code in src/ltnjax/fuzzy_ops.py
class UnaryConnectiveOperator(ConnectiveOperator):
    """Abstract class for unary connective operators.

    Raises:
        NotImplementedError: Raised when
            [__call__][ltnjax.fuzzy_ops.UnaryConnectiveOperator.__call__] is
            not implemented in the sub-class.
    """

    @abstractmethod
    def __call__(self, *args: Any, **kwargs: Any):
        """Implements the behavior of the unary connective operator.

        Args:
            args: Arguments.
            kwargs: Keyword arguments.

        Raises:
            NotImplementedError: Always.
        """
        raise NotImplementedError()

Methods:

__call__ abstractmethod
__call__(*args: Any, **kwargs: Any)

Implements the behavior of the unary connective operator.

Parameters:

Name Type Description Default
args
Any

Arguments.

()
kwargs
Any

Keyword arguments.

{}

Raises:

Type Description
NotImplementedError

Always.

Source code in src/ltnjax/fuzzy_ops.py
@abstractmethod
def __call__(self, *args: Any, **kwargs: Any):
    """Implements the behavior of the unary connective operator.

    Args:
        args: Arguments.
        kwargs: Keyword arguments.

    Raises:
        NotImplementedError: Always.
    """
    raise NotImplementedError()

Functions:

not_ones

not_ones(x: ArrayLike) -> Array

Smoothly transforms an array to avoid one-values.

Function that has to be used when we need to assure that the truth value in input to a fuzzy operator is never equal to one, in such a way to avoid gradient problems. It maps the interval \([0, 1]\) in the interval \([0, 1[\), where the \(1\) is excluded.

Parameters:

Name Type Description Default

x

ArrayLike

Array of truth-values.

required

Returns:

Type Description
Array

The input truth values changed in such a way to prevent gradient

Array

problems (1 is changed with a small number near 1).

Source code in src/ltnjax/fuzzy_ops.py
def not_ones(x: ArrayLike) -> Array:
    """Smoothly transforms an array to avoid one-values.

    Function that has to be used when we need to assure that the truth value
    in input to a fuzzy operator is never equal to one, in such a way to avoid
    gradient problems. It maps the interval $[0, 1]$ in the interval
    $[0, 1[$, where the $1$ is excluded.

    Args:
        x: Array of truth-values.

    Returns:
        The input truth values changed in such a way to prevent gradient
        problems (1 is changed with a small number near 1).
    """
    return jnp.multiply((1 - eps), x)

not_zeros

not_zeros(x: ArrayLike) -> Array

Smoothly transforms an array to avoid zero-values.

Function that has to be used when we need to assure that the truth value in input to a fuzzy operator is never equal to zero, in such a way to avoid gradient problems. It maps the interval \([0, 1]\) in the interval \(]0, 1]\), where the \(0\) is excluded.

Parameters:

Name Type Description Default

x

ArrayLike

Array of truth-values.

required

Returns:

Type Description
Array

The input truth values changed in such a way to prevent gradient

Array

problems (0 is changed with a small number near 0).

Source code in src/ltnjax/fuzzy_ops.py
def not_zeros(x: ArrayLike) -> Array:
    """Smoothly transforms an array to avoid zero-values.

    Function that has to be used when we need to assure that the truth value
    in input to a fuzzy operator is never equal to zero, in such a way to
    avoid gradient problems. It maps the interval $[0, 1]$ in the
    interval $]0, 1]$, where the $0$ is excluded.

    Args:
        x: Array of truth-values.

    Returns:
        The input truth values changed in such a way to prevent gradient
        problems (0 is changed with a small number near 0).
    """
    return jnp.multiply((1 - eps), x + eps)

sigmoid

sigmoid(x: ArrayLike) -> Array

Computes sigmoid.

Parameters:

Name Type Description Default

x

ArrayLike

Array.

required

Returns:

Type Description
Array

sigmoid(x).

Source code in src/ltnjax/fuzzy_ops.py
def sigmoid(x: ArrayLike) -> Array:
    """Computes sigmoid.

    Args:
        x: Array.

    Returns:
        `sigmoid(x)`.
    """
    return 1 / (1 + jnp.exp(jnp.negative(x)))

tanh

tanh(x: ArrayLike) -> Array

Computes hyperbolic tangent (tanh).

Parameters:

Name Type Description Default

x

ArrayLike

Array.

required

Returns:

Type Description
Array

tanh(x).

Source code in src/ltnjax/fuzzy_ops.py
def tanh(x: ArrayLike) -> Array:
    """Computes hyperbolic tangent (tanh).

    Args:
        x: Array.

    Returns:
        `tanh(x)`.
    """
    return (jnp.tanh(x) + 1) / 2