Skip to main content

omnibias.keras.identity_init

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

Lemma 1 (identity nesting) init helpers (Keras backend).

For any base activation sigma and signs summing to one, tying all biases gives sum_k s_k sigma(z + b_k) = sigma(z + b) by the stated algebraic identity. These helpers build the NumPy init arrays satisfying the lemma so a fresh OMBU returns its base activation at step zero. Mirrors omnibias.torch.identity_init.

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
identity_signsomnibias.keras.identity_init.identity_signs
FUNCTION

identity_init_biases​

omnibias.keras.identity_init.identity_init_biasesSource ↗
identity_init_biases(num_channels: int, K: int, bias_value: float=0.0, dtype: str | None=None) -> np.ndarray

Tied biases for identity nesting: a (num_channels, K) array.

dtype defaults to keras.config.floatx().

Parameters

NameType & defaultContract
num_channelspositional-or-keywordintRequiredSee the operation contract and implementation below.
Kpositional-or-keywordintRequiredSee the operation contract and implementation below.
bias_valuepositional-or-keywordfloatDefault: 0.0See the operation contract and implementation below.
dtypepositional-or-keywordstr | NoneDefault: NoneSee the operation contract and implementation below.
Returnsnp.ndarray
Explicit validation & failure cases
  • When num_channels < 1, raises ValueError(f'num_channels must be >= 1, got {num_channels}').
  • When K < 1, raises ValueError(f'K must be >= 1, got {K}').

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

Executed regression · identity init signs sum to one

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_identity_init_signs_sum_to_one(K: int) -> None:
    biases = identity_init_biases(3, K)
    signs = identity_init_signs(3, K)
    assert verify_identity_init(biases, signs, atol=1e-12)
python -m pytest "packages/omnibias-keras/tests/test_identity_nesting.py::test_identity_init_signs_sum_to_one[1]" -q
Read the implementation
def identity_init_biases(
    num_channels: int,
    K: int,
    bias_value: float = 0.0,
    dtype: str | None = None,
) -> np.ndarray:
    """Tied biases for identity nesting: a ``(num_channels, K)`` array.

    ``dtype`` defaults to :func:`keras.config.floatx()`.
    """
    if num_channels < 1:
        raise ValueError(f"num_channels must be >= 1, got {num_channels}")
    if K < 1:
        raise ValueError(f"K must be >= 1, got {K}")
    return np.full((num_channels, K), bias_value, dtype=_default_dtype(dtype))
FUNCTION

identity_init_signs​

omnibias.keras.identity_init.identity_init_signsSource ↗
identity_init_signs(num_channels: int, K: int, dtype: str | None=None) -> np.ndarray

Signs that sum to one, broadcast across channels: (num_channels, K).

dtype defaults to keras.config.floatx().

Parameters

NameType & defaultContract
num_channelspositional-or-keywordintRequiredSee the operation contract and implementation below.
Kpositional-or-keywordintRequiredSee the operation contract and implementation below.
dtypepositional-or-keywordstr | NoneDefault: NoneSee the operation contract and implementation below.
Returnsnp.ndarray
Executed regression · identity init signs sum to one

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_identity_init_signs_sum_to_one(K: int) -> None:
    biases = identity_init_biases(3, K)
    signs = identity_init_signs(3, K)
    assert verify_identity_init(biases, signs, atol=1e-12)
python -m pytest "packages/omnibias-keras/tests/test_identity_nesting.py::test_identity_init_signs_sum_to_one[1]" -q
Read the implementation
def identity_init_signs(
    num_channels: int,
    K: int,
    dtype: str | None = None,
) -> np.ndarray:
    """Signs that sum to one, broadcast across channels: ``(num_channels, K)``.

    ``dtype`` defaults to :func:`keras.config.floatx()`.
    """
    base = identity_signs(K, dtype=_default_dtype(dtype))
    return np.broadcast_to(base, (num_channels, K)).copy()
FUNCTION

verify_identity_init​

omnibias.keras.identity_init.verify_identity_initSource ↗
verify_identity_init(biases: np.ndarray, signs: np.ndarray, atol: float=0.0) -> bool

True if the init satisfies Lemma 1 (tied biases, signs sum to one).

Parameters

NameType & defaultContract
biasespositional-or-keywordnp.ndarrayRequiredSee the operation contract and implementation below.
signspositional-or-keywordnp.ndarrayRequiredSee the operation contract and implementation below.
atolpositional-or-keywordfloatDefault: 0.0See the operation contract and implementation below.
Returnsbool
Explicit validation & failure cases
  • When biases.shape != signs.shape, raises ValueError(f'biases and signs must have the same shape, got {biases.shape} vs {signs.shape}').

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

Executed regression · identity init signs sum to one

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_identity_init_signs_sum_to_one(K: int) -> None:
    biases = identity_init_biases(3, K)
    signs = identity_init_signs(3, K)
    assert verify_identity_init(biases, signs, atol=1e-12)
python -m pytest "packages/omnibias-keras/tests/test_identity_nesting.py::test_identity_init_signs_sum_to_one[1]" -q
Read the implementation
def verify_identity_init(
    biases: np.ndarray,
    signs: np.ndarray,
    atol: float = 0.0,
) -> bool:
    """True if the init satisfies Lemma 1 (tied biases, signs sum to one)."""
    biases = np.asarray(biases)
    signs = np.asarray(signs)
    if biases.shape != signs.shape:
        raise ValueError(
            f"biases and signs must have the same shape, got {biases.shape} vs {signs.shape}"
        )
    bias_constancy = float(np.abs(biases - biases[..., :1]).max())
    sign_sum_err = float(np.abs(signs.sum(axis=-1) - 1.0).max())
    return bias_constancy <= atol and sign_sum_err <= atol