Skip to main content

omnibias.keras.fastpath.eulerian

0.0.2a1AlphaPython >=3.10Apache-2.0

Keras 3 operator layers and activation paths implemented with keras.ops for TensorFlow, JAX, or Torch.

import omnibias.keras.fastpath.eulerian
Module contract & mathematical conventions

Closed-form derivatives of sigmoid (and softplus) via the Eulerian / sigmoid-polynomial recursion, evaluated with keras.ops.

Let s = sigmoid(z). Then s' = s (1 - s) (a Riccati identity) and every higher derivative is a polynomial in s:

sigma^(n)(z) = P_n(s), P_0(s) = s, P_{n+1}(s) = s (1 - s) * P_n'(s).

The coefficients come from the canonical, backend-agnostic omnibias.core.polynomials so this Keras backend stays algebraically corresponding to the torch and JAX backends. Only the Horner evaluation is backend-specific (it touches the tensor).

Numerical scope: shared coefficients and formulas do not establish universal floating-point identity across backends, devices, compiler transforms, or reduction orders. Compare the chosen path with dtype-appropriate tolerances; even float64 is not a general bitwise-equality guarantee. Algebraic initialization identities likewise need a numerical check for the selected coefficients and reduction order.

Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.

Imports & aliases​

These names share a definition with another public module. Follow a name for its full contract, parameters, and examples.

Import from this moduleCanonical reference
sigmoid_polynomial_coeffsomnibias.core.sigmoid_polynomial_coeffs
FUNCTION

sigmoid_nth_derivative​

omnibias.keras.fastpath.sigmoid_nth_derivativeSource ↗
sigmoid_nth_derivative(z: Any, n: int) -> Any

sigma^(n)(z) in closed form via Eulerian polynomials.

One sigmoid call regardless of n, then O(n) multiply-adds.

Parameters

NameType & defaultContract
zpositional-or-keywordAnyRequiredSee the operation contract and implementation below.
npositional-or-keywordintRequiredSee the operation contract and implementation below.
ReturnsAny
Explicit validation & failure cases
  • When n < 0, raises ValueError(f'order n must be >= 0, got {n}').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · negative order raises

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_negative_order_raises(fn) -> None:
    with pytest.raises(ValueError):
        fn(_t(np.zeros(3)), -1)
python -m pytest "packages/omnibias-keras/tests/test_fastpath_correctness.py::test_negative_order_raises[sigmoid_nth_derivative]" -q
Regression example · fastpath order zero is forward

This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_fastpath_order_zero_is_forward(fn) -> None:
    z = np.linspace(-2.0, 2.0, 11)
    out0 = _np(fn(_t(z), 0))
    assert out0.shape == z.shape
    assert np.all(np.isfinite(out0))
python -m pytest packages/omnibias-keras/tests/test_fastpath_correctness.py -k test_fastpath_order_zero_is_forward -q
Read the implementation
def sigmoid_nth_derivative(z: Any, n: int) -> Any:
    """``sigma^(n)(z)`` in closed form via Eulerian polynomials.

    One ``sigmoid`` call regardless of ``n``, then ``O(n)`` multiply-adds.
    """
    if n < 0:
        raise ValueError(f"order n must be >= 0, got {n}")
    s = ops.sigmoid(z)
    if n == 0:
        return s
    return _horner(sigmoid_polynomial_coeffs(n), s)
Other public import paths
  • omnibias.keras.fastpath.sigmoid_nth_derivative
  • omnibias.keras.fastpath.eulerian.sigmoid_nth_derivative
FUNCTION

sigmoid_tower​

omnibias.keras.fastpath.eulerian.sigmoid_towerSource ↗
sigmoid_tower(z: Any, max_order: int) -> Any

All derivatives through max_order from one native sigmoid evaluation.

Parameters

NameType & defaultContract
zpositional-or-keywordAnyRequiredSee the operation contract and implementation below.
max_orderpositional-or-keywordintRequiredSee the operation contract and implementation below.
ReturnsAny
Explicit validation & failure cases
  • When max_order < 0, raises ValueError('max_order must be nonnegative').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · registered shared tower

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_registered_shared_tower(name: str) -> None:
    spec = get_activation(name)
    assert spec.tower is not None and spec.fastpath is not None
    value = ops.convert_to_tensor([-0.2, 0.0, 0.5])
    tower = spec.tower(value, 6)
    for order in range(7):
        np.testing.assert_array_equal(ops.convert_to_numpy(tower[order]),
                                      ops.convert_to_numpy(spec.fastpath(value, order)))
    with pytest.raises(ValueError, match="nonnegative"):
        spec.tower(value, -1)
python -m pytest "packages/omnibias-keras/tests/test_shared_tower.py::test_registered_shared_tower[sigmoid]" -q
Read the implementation
def sigmoid_tower(z: Any, max_order: int) -> Any:
    """All derivatives through max_order from one native sigmoid evaluation."""
    if max_order < 0:
        raise ValueError("max_order must be nonnegative")
    value = ops.sigmoid(z)
    rows = [value] + [_horner(sigmoid_polynomial_coeffs(n), value) for n in range(1, max_order + 1)]
    return ops.stack(rows, axis=0)
FUNCTION

softplus_nth_derivative​

omnibias.keras.fastpath.softplus_nth_derivativeSource ↗
softplus_nth_derivative(z: Any, n: int) -> Any

softplus^(n)(z): softplus(z) for n == 0, else sigma^(n-1)(z).

Parameters

NameType & defaultContract
zpositional-or-keywordAnyRequiredSee the operation contract and implementation below.
npositional-or-keywordintRequiredSee the operation contract and implementation below.
ReturnsAny
Explicit validation & failure cases
  • When n < 0, raises ValueError(f'order n must be >= 0, got {n}').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · tempered converges to relu

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_tempered_converges_to_relu() -> None:
    relu = get_activation("relu")
    z = ops.convert_to_tensor(np.array([-3.0, -1.0, -0.3, 0.3, 1.0, 3.0]))
    err = float(np.max(np.abs(_np(TemperedActivation("softplus", beta=128.0)(z)) - _np(relu.forward(z)))))
    assert err < 1e-2
python -m pytest "packages/omnibias-keras/tests/test_tempered_blocks.py::test_tempered_converges_to_relu" -q
Read the implementation
def softplus_nth_derivative(z: Any, n: int) -> Any:
    """``softplus^(n)(z)``: ``softplus(z)`` for ``n == 0``, else ``sigma^(n-1)(z)``."""
    if n < 0:
        raise ValueError(f"order n must be >= 0, got {n}")
    if n == 0:
        return ops.softplus(z)
    return sigmoid_nth_derivative(z, n - 1)
Other public import paths
  • omnibias.keras.fastpath.softplus_nth_derivative
  • omnibias.keras.fastpath.eulerian.softplus_nth_derivative
FUNCTION

softplus_tower​

omnibias.keras.fastpath.eulerian.softplus_towerSource ↗
softplus_tower(z: Any, max_order: int) -> Any

Softplus value and its sigmoid derivative tower with one sigmoid call.

Parameters

NameType & defaultContract
zpositional-or-keywordAnyRequiredSee the operation contract and implementation below.
max_orderpositional-or-keywordintRequiredSee the operation contract and implementation below.
ReturnsAny
Explicit validation & failure cases
  • When max_order < 0, raises ValueError('max_order must be nonnegative').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · registered shared tower

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_registered_shared_tower(name: str) -> None:
    spec = get_activation(name)
    assert spec.tower is not None and spec.fastpath is not None
    value = ops.convert_to_tensor([-0.2, 0.0, 0.5])
    tower = spec.tower(value, 6)
    for order in range(7):
        np.testing.assert_array_equal(ops.convert_to_numpy(tower[order]),
                                      ops.convert_to_numpy(spec.fastpath(value, order)))
    with pytest.raises(ValueError, match="nonnegative"):
        spec.tower(value, -1)
python -m pytest "packages/omnibias-keras/tests/test_shared_tower.py::test_registered_shared_tower[softplus]" -q
Read the implementation
def softplus_tower(z: Any, max_order: int) -> Any:
    """Softplus value and its sigmoid derivative tower with one sigmoid call."""
    if max_order < 0:
        raise ValueError("max_order must be nonnegative")
    rows = [ops.softplus(z)]
    if max_order:
        derivatives = sigmoid_tower(z, max_order - 1)
        rows.extend(derivatives[n] for n in range(max_order))
    return ops.stack(rows, axis=0)