Skip to main content

omnibias.qcalculus.jax

0.1.0a2AlphaPython >=3.10Apache-2.0

q-numbers, Jackson derivatives and integrals, q-series, and the ordinary-calculus limit as q approaches one.

import omnibias.qcalculus.jax
Module contract & mathematical conventions

JAX twin of the Jackson q-derivative of an activation.

Bit-identical mirror of omnibias.qcalculus.torch, jit / vmap / grad-safe (name and q are static, only z is traced). q_derivative is the batched Jackson quotient (sigma(qz) - sigma(z)) / ((q-1)z); q_derivative_limit is the closed-form sigma'(z) -- the exact q -> 1 limit (the **distinct** q-limit, not the delta -> 0 founding collapse).

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
QOMBUConfigomnibias.qcalculus.QOMBUConfig
q_ombu_forwardomnibias.qcalculus.jax.q_ombu_forward
FUNCTION

q_derivative​

omnibias.qcalculus.jax.q_derivativeSource ↗
q_derivative(name: str, z: Array, q: float) -> Array

Batched Jackson q-derivative (sigma(qz) - sigma(z)) / ((q-1)z) (q != 1).

Parameters

NameType & defaultContract
namepositional-or-keywordstrRequiredSee the operation contract and implementation below.
zpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
qpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
ReturnsArray
Explicit validation & failure cases
  • When q == 1.0, raises ValueError('q_derivative needs q != 1 (the q -> 1 limit is q_derivative_limit)').

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

Executed regression · jax twin matches torch twin

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_jax_twin_matches_torch_twin() -> None:
    torch = pytest.importorskip("torch")
    jax = pytest.importorskip("jax")
    jax.config.update("jax_enable_x64", True)
    import jax.numpy as jnp
    from omnibias.qcalculus.jax import q_derivative as jq
    from omnibias.qcalculus.torch import q_derivative as tq

    xs = [0.5, 0.9, 1.4, 1.9]
    q = 0.95
    t = tq("sigmoid", torch.tensor(xs, dtype=torch.float64), q).tolist()
    j = jq("sigmoid", jnp.asarray(xs, dtype=jnp.float64), q).tolist()
    for a, b in zip(t, j, strict=False):
        assert a == pytest.approx(b, rel=1e-10, abs=1e-12)
python -m pytest "packages/omnibias-qcalculus/tests/test_package.py::test_jax_twin_matches_torch_twin" -q
Read the implementation
def q_derivative(name: str, z: Array, q: float) -> Array:
    r"""Batched Jackson q-derivative ``(sigma(qz) - sigma(z)) / ((q-1)z)`` (``q != 1``)."""
    if q == 1.0:
        raise ValueError("q_derivative needs q != 1 (the q -> 1 limit is q_derivative_limit)")
    spec = get_activation(name)
    return (spec.forward(q * z) - spec.forward(z)) / ((q - 1.0) * z)
FUNCTION

q_derivative_limit​

omnibias.qcalculus.jax.q_derivative_limitSource ↗
q_derivative_limit(name: str, z: Array) -> Array

Closed-form sigma'(z) via the backend fastpath -- the exact q -> 1 limit.

Parameters

NameType & defaultContract
namepositional-or-keywordstrRequiredSee the operation contract and implementation below.
zpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Explicit validation & failure cases
  • When spec.fastpath is None, raises NotImplementedError(f'activation {name!r} has no closed-form derivative kernel').

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

Read the implementation
def q_derivative_limit(name: str, z: Array) -> Array:
    r"""Closed-form ``sigma'(z)`` via the backend fastpath -- the exact ``q -> 1`` limit."""
    spec = get_activation(name)
    if spec.fastpath is None:
        raise NotImplementedError(f"activation {name!r} has no closed-form derivative kernel")
    out: Array = spec.fastpath(z, 1)
    return out
FUNCTION

q_derivative_residual​

omnibias.qcalculus.jax.q_derivative_residualSource ↗
q_derivative_residual(name: str, z: Array, q: float) -> Array

q_derivative - q_derivative_limit; -> 0 as q -> 1.

Parameters

NameType & defaultContract
namepositional-or-keywordstrRequiredSee the operation contract and implementation below.
zpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
qpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
ReturnsArray
Read the implementation
def q_derivative_residual(name: str, z: Array, q: float) -> Array:
    r"""``q_derivative - q_derivative_limit``; ``-> 0`` as ``q -> 1``."""
    return q_derivative(name, z, q) - q_derivative_limit(name, z)