Skip to main content

omnibias.keras.fastpath.hermite

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.hermite
Module contract & mathematical conventions

Closed-form derivatives of the Gaussian activation via probabilist's Hermite polynomials, evaluated with keras.ops.

Let g(z) = exp(-z^2/2). Then g^(n)(z) = (-1)^n He_n(z) g(z), where He_n obeys He_0 = 1, He_1 = z, He_{n+1} = z He_n - n He_{n-1}. Coefficients come from the shared omnibias.core.polynomials.

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
hermite_coeffsomnibias.core.hermite_coeffs
FUNCTION

gaussian_forward​

omnibias.keras.fastpath.gaussian_forwardSource ↗
gaussian_forward(z: Any) -> Any

g(z) = exp(-z^2/2).

Parameters

NameType & defaultContract
zpositional-or-keywordAnyRequiredSee the operation contract and implementation below.
ReturnsAny
Executed regression · fastpath order zero is forward

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_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::test_fastpath_order_zero_is_forward[gaussian_nth_derivative]" -q
Read the implementation
def gaussian_forward(z: Any) -> Any:
    """``g(z) = exp(-z^2/2)``."""
    return ops.exp(-0.5 * z * z)
Other public import paths
  • omnibias.keras.fastpath.gaussian_forward
  • omnibias.keras.fastpath.hermite.gaussian_forward
FUNCTION

gaussian_nth_derivative​

omnibias.keras.fastpath.gaussian_nth_derivativeSource ↗
gaussian_nth_derivative(z: Any, n: int) -> Any

g^(n)(z) via g^(n)(z) = (-1)^n He_n(z) g(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 · 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[gaussian_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 gaussian_nth_derivative(z: Any, n: int) -> Any:
    """``g^(n)(z)`` via ``g^(n)(z) = (-1)^n He_n(z) g(z)``."""
    if n < 0:
        raise ValueError(f"order n must be >= 0, got {n}")
    g = gaussian_forward(z)
    if n == 0:
        return g
    poly = _horner(hermite_coeffs(n), z)
    sign = -1.0 if (n & 1) else 1.0
    return sign * poly * g
Other public import paths
  • omnibias.keras.fastpath.gaussian_nth_derivative
  • omnibias.keras.fastpath.hermite.gaussian_nth_derivative