Skip to main content

omnibias.jax.weight_loss_jet

0.5.0rc1Release candidatePython >=3.10Apache-2.0

JAX activation derivatives, functional network jets, direct contractions, and parameter-differentiable numerical models.

import omnibias.jax.weight_loss_jet
Module contract & mathematical conventions

Closed-form one-layer weight-space loss jets, JAX twin.

Host-side conversion into omnibias.core.weight_loss_jet. Bit-identical to the torch twin on the same floats. Do not jit the driver.

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
WeightLossJetSpecomnibias.core.WeightLossJetSpec
honesty_payloadomnibias.core.weight_loss_jet.honesty_payload
one_layer_param_countomnibias.core.one_layer_param_count
pack_one_layer_paramsomnibias.core.pack_one_layer_params
unpack_one_layer_paramsomnibias.core.unpack_one_layer_params
FUNCTION

one_layer_loss​

omnibias.jax.one_layer_lossSource ↗
one_layer_loss(features: Array, targets: Array, params: Array, hidden: int, dim: int, activation: str='tanh') -> float

The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.

Parameters

NameType & defaultContract
featurespositional-or-keywordArrayRequiredSee the operation contract and implementation below.
targetspositional-or-keywordArrayRequiredSee the operation contract and implementation below.
paramspositional-or-keywordArrayRequiredSee the operation contract and implementation below.
hiddenpositional-or-keywordintRequiredSee the operation contract and implementation below.
dimpositional-or-keywordintRequiredSee the operation contract and implementation below.
activationpositional-or-keywordstrDefault: 'tanh'See the operation contract and implementation below.
Returnsfloat
Read the implementation
def one_layer_loss(
    features: Array,
    targets: Array,
    params: Array,
    hidden: int,
    dim: int,
    activation: str = "tanh",
) -> float:
    return core.one_layer_loss(
        _rows(features), _vec(targets), _vec(params), hidden, dim, activation
    )
Other public import paths
  • omnibias.jax.one_layer_loss
  • omnibias.jax.weight_loss_jet.one_layer_loss
FUNCTION

one_layer_loss_grad​

omnibias.jax.one_layer_loss_gradSource ↗
one_layer_loss_grad(features: Array, targets: Array, params: Array, hidden: int, dim: int, activation: str='tanh') -> list[float]

The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.

Parameters

NameType & defaultContract
featurespositional-or-keywordArrayRequiredSee the operation contract and implementation below.
targetspositional-or-keywordArrayRequiredSee the operation contract and implementation below.
paramspositional-or-keywordArrayRequiredSee the operation contract and implementation below.
hiddenpositional-or-keywordintRequiredSee the operation contract and implementation below.
dimpositional-or-keywordintRequiredSee the operation contract and implementation below.
activationpositional-or-keywordstrDefault: 'tanh'See the operation contract and implementation below.
Returnslist[float]
Read the implementation
def one_layer_loss_grad(
    features: Array,
    targets: Array,
    params: Array,
    hidden: int,
    dim: int,
    activation: str = "tanh",
) -> list[float]:
    return core.one_layer_loss_grad(
        _rows(features), _vec(targets), _vec(params), hidden, dim, activation
    )
Other public import paths
  • omnibias.jax.one_layer_loss_grad
  • omnibias.jax.weight_loss_jet.one_layer_loss_grad
FUNCTION

one_layer_loss_hessian​

omnibias.jax.one_layer_loss_hessianSource ↗
one_layer_loss_hessian(features: Array, targets: Array, params: Array, hidden: int, dim: int, activation: str='tanh', *, max_params: int=256) -> list[list[float]]

The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.

Parameters

NameType & defaultContract
featurespositional-or-keywordArrayRequiredSee the operation contract and implementation below.
targetspositional-or-keywordArrayRequiredSee the operation contract and implementation below.
paramspositional-or-keywordArrayRequiredSee the operation contract and implementation below.
hiddenpositional-or-keywordintRequiredSee the operation contract and implementation below.
dimpositional-or-keywordintRequiredSee the operation contract and implementation below.
activationpositional-or-keywordstrDefault: 'tanh'See the operation contract and implementation below.
max_paramskeyword-onlyintDefault: 256See the operation contract and implementation below.
Returnslist[list[float]]
Read the implementation
def one_layer_loss_hessian(
    features: Array,
    targets: Array,
    params: Array,
    hidden: int,
    dim: int,
    activation: str = "tanh",
    *,
    max_params: int = 256,
) -> list[list[float]]:
    return core.one_layer_loss_hessian(
        _rows(features),
        _vec(targets),
        _vec(params),
        hidden,
        dim,
        activation,
        max_params=max_params,
    )
Other public import paths
  • omnibias.jax.one_layer_loss_hessian
  • omnibias.jax.weight_loss_jet.one_layer_loss_hessian
FUNCTION

one_layer_loss_jet​

omnibias.jax.one_layer_loss_jetSource ↗
one_layer_loss_jet(features: Array, targets: Array, params: Array, direction: Array, *, order: int, hidden: int, dim: int, activation: str='tanh') -> list[float]

φ^(k)(0) via the shared core assembler.

Parameters

NameType & defaultContract
featurespositional-or-keywordArrayRequiredSee the operation contract and implementation below.
targetspositional-or-keywordArrayRequiredSee the operation contract and implementation below.
paramspositional-or-keywordArrayRequiredSee the operation contract and implementation below.
directionpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
orderkeyword-onlyintRequiredSee the operation contract and implementation below.
hiddenkeyword-onlyintRequiredSee the operation contract and implementation below.
dimkeyword-onlyintRequiredSee the operation contract and implementation below.
activationkeyword-onlystrDefault: 'tanh'See the operation contract and implementation below.
Returnslist[float]
Regression example · torch jax core loss jet parity

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_torch_jax_core_loss_jet_parity() -> None:
    torch = pytest.importorskip("torch")
    jax = pytest.importorskip("jax")
    jax.config.update("jax_enable_x64", True)
    import jax.numpy as jnp
    from omnibias.jax.weight_loss_jet import one_layer_loss_jet as jax_jet
    from omnibias.torch.weight_loss_jet import one_layer_loss_jet as torch_jet

    torch.set_default_dtype(torch.float64)
    expected = core_jet(
        _XS,
        _YS,
        _THETA,
        _DIR,
        order=3,
        hidden=2,
        dim=2,
        activation="tanh",
    )
    t_out = torch_jet(
        torch.tensor(_XS, dtype=torch.float64),
        torch.tensor(_YS, dtype=torch.float64),
        torch.tensor(_THETA, dtype=torch.float64),
        torch.tensor(_DIR, dtype=torch.float64),
        order=3,
        hidden=2,
        dim=2,
        activation="tanh",
    )
    j_out = jax_jet(
        jnp.asarray(_XS, dtype=jnp.float64),
        jnp.asarray(_YS, dtype=jnp.float64),
        jnp.asarray(_THETA, dtype=jnp.float64),
        jnp.asarray(_DIR, dtype=jnp.float64),
        order=3,
        hidden=2,
        dim=2,
        activation="tanh",
    )
    assert t_out == expected
    assert j_out == expected
python -m pytest tests/test_weight_loss_jet_parity.py -k test_torch_jax_core_loss_jet_parity -q
Read the implementation
def one_layer_loss_jet(
    features: Array,
    targets: Array,
    params: Array,
    direction: Array,
    *,
    order: int,
    hidden: int,
    dim: int,
    activation: str = "tanh",
) -> list[float]:
    """``φ^(k)(0)`` via the shared core assembler."""
    return core.one_layer_loss_jet(
        _rows(features),
        _vec(targets),
        _vec(params),
        _vec(direction),
        order=order,
        hidden=hidden,
        dim=dim,
        activation=activation,
    )
Other public import paths
  • omnibias.jax.one_layer_loss_jet
  • omnibias.jax.weight_loss_jet.one_layer_loss_jet
FUNCTION

one_layer_newton_direction​

omnibias.jax.one_layer_newton_directionSource ↗
one_layer_newton_direction(grad: Array | Sequence[float], hess: Array | Sequence[Sequence[float]], *, damping: float=1e-06) -> list[float]

The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.

Parameters

NameType & defaultContract
gradpositional-or-keywordArray | Sequence[float]RequiredSee the operation contract and implementation below.
hesspositional-or-keywordArray | Sequence[Sequence[float]]RequiredSee the operation contract and implementation below.
dampingkeyword-onlyfloatDefault: 1e-06See the operation contract and implementation below.
Returnslist[float]
Read the implementation
def one_layer_newton_direction(
    grad: Array | Sequence[float],
    hess: Array | Sequence[Sequence[float]],
    *,
    damping: float = 1e-6,
) -> list[float]:
    if isinstance(hess, Array):
        rows = [[float(v) for v in row] for row in hess]
    else:
        rows = [[float(v) for v in row] for row in hess]
    return core.one_layer_newton_direction(_vec(grad), rows, damping=damping)
Other public import paths
  • omnibias.jax.one_layer_newton_direction
  • omnibias.jax.weight_loss_jet.one_layer_newton_direction