Functional Logic Kernels¶
- jlnn.nn.functional.weighted_and(x: Array, weights: Array, beta: Array) Array[source]¶
Stateless weighted conjunction (AND) according to Łukasiewicz.
- Parameters:
x (jnp.ndarray) – Input interval tensor of the form (…, num_inputs, 2).
weights (jnp.ndarray) – Tensor weights for individual inputs.
beta (jnp.ndarray) – Gate sensitivity threshold.
- Returns:
The resulting truth interval [L, U].
- Return type:
jnp.ndarray
- jlnn.nn.functional.weighted_implication(int_a: Array, int_b: Array, weights: Array, beta: Array, method: str = 'lukasiewicz') Array[source]¶
Functional calculation of logical implication (A -> B).
It supports various semantics for modeling expert rules.
- Parameters:
int_a (jnp.ndarray) – Antecedent (presupposition).
int_b (jnp.ndarray) – Consequent (consequence).
weights (jnp.ndarray) – Weights for A and B.
beta (jnp.ndarray) – Gate Threshold.
method (str) – Method (‘lukasiewicz’, ‘kleene_dienes’, ‘reichenbach’).
- Returns:
The truth of the rule as an interval.
- Return type:
jnp.ndarray
- jlnn.nn.functional.weighted_nand(x: Array, weights: Array, beta: Array) Array[source]¶
Weighted NAND calculated as the negation of weighted AND.
- jlnn.nn.functional.weighted_nor(x: Array, weights: Array, beta: Array) Array[source]¶
Weighted NOR calculated as the negation of the weighted OR.
- jlnn.nn.functional.weighted_not(x: Array, weight: Array) Array[source]¶
Computes a weighted logical negation (NOT) with confidence scaling.
FIXED VERSION - Corrects the weighting semantics to preserve NOT logic.
The weight parameter controls how much the negation “pulls toward uncertainty”: - weight = 1.0: Pure logical NOT, [L, U] -> [1-U, 1-L] - weight < 1.0: Negation is “softened” by blending with the unknown state [0, 1] - weight > 1.0: Not recommended (would push values outside [0, 1])
- The weighting is applied by linear interpolation:
result = weight * NOT(x) + (1 - weight) * [0, 1]
This ensures that when weight = 1.0, we get pure logical negation. When weight = 0.0, we get complete uncertainty [0, 1].
- Parameters:
x (jnp.ndarray) – Input truth interval tensor of shape (…, 2).
weight (jnp.ndarray) – Scaling factor (0.0 to 1.0) representing the confidence or strength of the negation.
- Returns:
The weighted negated interval, clipped to [0, 1].
- Return type:
jnp.ndarray
Examples
>>> # Pure negation (weight = 1.0) >>> x = jnp.array([[0.0, 0.0]]) # False >>> weighted_not(x, jnp.array(1.0)) # Returns: [[1.0, 1.0]] (True) ✓
>>> x = jnp.array([[1.0, 1.0]]) # True >>> weighted_not(x, jnp.array(1.0)) # Returns: [[0.0, 0.0]] (False) ✓
>>> # Softened negation (weight = 0.5) >>> x = jnp.array([[0.0, 0.0]]) # False >>> weighted_not(x, jnp.array(0.5)) # Returns: [[0.5, 1.0]] (blend of True and Unknown)
- jlnn.nn.functional.weighted_or(x: Array, weights: Array, beta: Array) Array[source]¶
Stateless weighted disjunction (OR) according to Łukasiewicz.
- Parameters:
x (jnp.ndarray) – Input interval tensor of the form (…, num_inputs, 2).
weights (jnp.ndarray) – Tensor weights for individual inputs.
beta (jnp.ndarray) – Gate sensitivity threshold.
- Returns:
The resulting truth interval [L, U].
- Return type:
jnp.ndarray
This module provides a functional interface to all logical operations supported by the JLNN framework. Unlike the modules in Base Logical Elements, these functions do not maintain their own state and are designed to be called directly with parameters passed as tensors.
Key features¶
JAX-Native: All functions are fully compatible with JAX transformations such as
jit,vmapandgrad.Łukasiewicz semantics: The default implementation of gates (AND, OR, Implication) uses Łukasiewicz logic for working with truth intervals.
Flexibility: The module supports different types of implications (Kleene-Dienes, Reichenbach) for modeling expert systems.
Overview of Gates¶
Negation first applies a weight to the boundaries of the interval and then performs the inversion: \([1-U_w, 1-L_w]\).
Supports multiple methods for calculating the truth of the rule \(A \to B\). The lukasiewicz method is recommended for consistency with weights and the \(\beta\) threshold.
Advanced operations¶
Compound gates are implemented as negations of basic operators:
NAND: Implemented as
negate(weighted_and(...)).NOR: Implemented as
negate(weighted_or(...)).