Activation Functions

jlnn.core.activations.entropy_raw(val: Array) Array[source]

Calculates the normalized binary Shannon entropy over the interval [0, 1].

Acts as an exported framework utility for measuring local fuzzy uncertainty and systemic chaos. The output is normalized such that maximum entropy H(0.5) = 1.0, and deterministic edges H(0.0) = H(1.0) = 0.0.

Parameters:

val (jnp.ndarray) – Input logical tensor containing truth values nominally in [0, 1].

Returns:

Computed and normalized Shannon entropy values.

Return type:

jnp.ndarray

jlnn.core.activations.get_entropic_weight(val: Array) Array[source]

Computes the logical stability (entropic weight) of a state: 1.0 - H(val).

This function is exported for use across interval-valued physical implication operators (PFL) to dynamically adjust logical truth bounds based on local uncertainty.

Parameters:

val (jnp.ndarray) – Input logical truth value or individual interval bound.

Returns:

Logical stability weight in the closed range [0, 1].

Return type:

jnp.ndarray

jlnn.core.activations.gravitational_bend_activation(z: Array, gamma: float = 0.2, mode: str = 'sigmoid', slope: float = 1.0, offset: float = 0.5) Array[source]

PFL activation function that deforms the standard truth potential space [0, 1].

Simulates a gravitational well around the logical center (0.5) via local entropy, pulling highly unstable, uncertain states towards the center. Near the deterministic edges (0.0 and 1.0), this gravitational influence decays naturally, allowing the function to converge to standard saturation behavior.

Parameters:
  • z (jnp.ndarray) – Input logical potential (raw input features or linear combination).

  • gamma (float) – Bending strength coefficient, bounded within the interval [0, 1]. Defaults to 0.2.

  • mode (str) – Base compression strategy. Options are ‘sigmoid’ (smooth physical field) or ‘ramp’ (truncated linear mapping). Defaults to ‘sigmoid’.

  • slope (float) – Stringency parameter utilized exclusively when mode=’ramp’. Defaults to 1.0.

  • offset (float) – Midpoint shift parameter utilized exclusively when mode=’ramp’. Defaults to 0.5.

Returns:

Bounded truth value in [0, 1] after entropic space bending.

Return type:

jnp.ndarray

jlnn.core.activations.identity_activation(x: Array) Array[source]

Realizes the identity function truncated to the closed logical interval [0, 1].

This activation function is utilized within the JLNN framework primarily as a numerical safeguard in locations where inputs already semantically represent truth values (e.g., outputs from upstream predicates or logical gates).

It ensures that minor numerical inaccuracies or floating-point drifts arising from cumulative tensor operations do not leak outside the valid logical boundary. In the context of interval logic, it maintains axiomatic integrity by enforcing strict saturation at 0.0 (absolute falsehood) and 1.0 (absolute truth).

Parameters:

x (jnp.ndarray) – Input tensor of arbitrary shape containing truth values or raw logical potentials.

Returns:

A bounded tensor of the same shape as the input, where each

element v_i satisfies the axiomatic constraint 0.0 <= v_i <= 1.0.

Return type:

jnp.ndarray

jlnn.core.activations.lukasiewicz_and_activation(sum_val: Array, beta: Array) Array[source]

It implements the activation function for the weighted Łukasiewicz conjunction (AND).

This function transforms the weighted sum of the logical negations of the inputs into the resulting truth value. In LNN logic, the beta parameter plays the role of a sensitivity threshold: if the weighted sum of the ‘false’s’ on the inputs exceeds the beta value, the gate output linearly drops to zero.

Mathematical relationship: f(s, β) = max(0, 1 - (s / β)) where ‘s’ is the weighted sum (sum_val) and ‘β’ is the threshold (beta).

Features: - For s = 0 (all inputs are 1.0): Output is 1.0 (True). - For s >= β: Output is 0.0 (False). - It preserves a linear gradient in the region (0, β), which is crucial for learning weights.

Parameters:
  • sum_val (jnp.ndarray) – Weighted sum of the complements of the truth values ​​of the inputs. Typically calculated as sum(w * (1 - x)).

  • beta (jnp.ndarray) – Gate threshold (nnx.Param), determining the steepness and the breakpoint of the logic function.

Returns:

Resulting truth value in the interval [0, 1].

Return type:

jnp.ndarray

jlnn.core.activations.lukasiewicz_or_activation(sum_val: Array, beta: Array) Array[source]

It implements the activation function for the weighted Łukasiewicz disjunction (OR).

This function transforms the weighted sum of the truth values ​​of the inputs into the resulting truth of the output. In LNN semantics, the beta parameter determines the sensitivity of the gate: the lower the beta value, the fewer “confirmations” (the sum of the inputs) are needed to reach the full truth.

Mathematical relationship: f(s, β) = min(1, s / β) where ‘s’ is the weighted sum (sum_val) and ‘β’ is the threshold (beta).

Features: - For s = 0 (all inputs are 0.0): Output is 0.0 (False). - For s >= β: Output is 1.0 (True). - The linear increase between 0 and β enables efficient gradient learning of weights and thresholds.

We use jnp.clip instead of jnp.minimum to ensure strict adherence to the interval [0, 1] even with numerical inaccuracies (e.g. floating-point drift) during the training phase.

Parameters:
  • sum_val (jnp.ndarray) – Weighted sum of the truth values ​​of the inputs. Calculated as sum(w * x).

  • beta (jnp.ndarray) – Gate threshold (nnx.Param), determining the saturation point logical truths.

Returns:

Resulting truth value in the interval [0, 1].

Return type:

jnp.ndarray

jlnn.core.activations.ramp_sigmoid(x: Array, slope: float = 1.0, offset: float = 0.5) Array[source]

Implements a linear Ramp activation function (truncated linear mapping).

Within the JLNN framework, this function is primarily utilized in grounding layers (such as LearnedPredicate) to transform unconstrained real-valued input features into fuzzy truth values. It balances the computational benefits of linearity (interpretability and constant gradients) with the semantic benefits of strict boundary saturation.

Parameter Semantics:
  • offset: Specifies the shift on the X-axis where the truth value is exactly 0.5 (the logical midpoint / decision boundary).

  • slope: Controls the stringency of the predicate. A high slope yields a sharp transition between false and true, approximating a crisp step function.

Parameters:
  • x (jnp.ndarray) – Input tensor of raw real-valued measurements (e.g., physical telemetry).

  • slope (float) – Steepness coefficient of the linear segment. Controls transition width. Defaults to 1.0.

  • offset (float) – Horizontal translation factor on the X-axis. Sets the decision threshold. Defaults to 0.5.

Returns:

Grounded fuzzy truth value constrained to the interval [0, 1].

Return type:

jnp.ndarray

Activating a function within the JLNN (Logical Neural Networks) framework not only serves to introduce nonlinearity into the network, but also fulfills two key semantic tasks: ensuring strict preservation of logical integrity and mapping real inputs or hidden potentials into correct truth intervals \([0, 1]\).

Traditional parametric activation

These functions ensure saturation at the edges and linearity in the gradient region, which is essential for stable and interpretable learning of gate and predicate weights.

  • identity_activation: Serves as a numeric safety (clipping with jnp.clip) to keep values ​​within the bounds \([0, 1]\). Prevents overflows caused by cumulative rounding when operating on tensors.

  • ramp_sigmoid: A key function for LearnedPredicates. It allows the conversion of real physical quantities to fuzzy logical truth using the parameters slope (stringency) and offset (decision boundary).

\[f(x) = \text{clip}(\text{slope} \cdot (x - \text{offset}) + 0.5, 0, 1)\]

Activation for Łukasiewicz logic

They implement specific accumulation and nilpotent activations for weighted logic gates, where the parameter beta (\(\beta\)) represents the sensitivity threshold.

  • lukasiewicz_and_activation: Transforms the weighted sum of the complements (negations) of the inputs into the resulting truth value of the conjunction. If the sum of the “falsehoods” exceeds the value \(\beta\), the output drops to pure zero.

\[f(s, \beta) = \text{clip}\left(1.0 - \frac{s}{\beta}, 0, 1\right)\]
  • lukasiewicz_or_activation: Activation for disjunction. The lower the value of \(\beta\), the fewer “confirmations” (sum of the truth values ​​of the inputs) are needed to reach absolute truth.

\[f(s, \beta) = \text{clip} \left(\frac{s}{\beta}, 0, 1\right)\]

Physical fuzzy logic (PFL) and space curvature

Extension of the framework to include space-time curved relations (Space-Curved Physical Fuzzy Logic), which model local chaos and state stability using Shannon entropy.

  • entropy_raw: Computes the normalized binary Shannon entropy on the interval \([0, 1]\). It reaches a maximum at \(H(0.5) = 1.0\) (pure uncertainty) and falls to \(H(0.0) = H(1.0) = 0.0\) at deterministic edges.

\[H(v) = -v \log_2(v) - (1-v) \log_2(1-v)\]
  • get_entropic_weight: Determines the logical stability of the state as a complement of entropy: \(1.0 - H(v)\). Used to dynamically adjust the limits of physical implication operators.

  • gravitational_bend_activation: Complex PFL activation that warps the standard truth potential space. Simulates a gravitational well around the center of uncertainty (\(0.5\)) proportional to the local entropy and the strength of the gamma coefficient. It attracts unstable states to the center, while at the deterministic edges the influence of gravity naturally disappears.

It supports two compression modes (mode parameter):

  • sigmoid: Smooth, continuous simulation of a physical field.

  • ramp: Truncated lineární mapování s ostřejšími přechody za použití parametrů slope a offset.