Skip to main content

omnibias.keras.blocks.linear

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

Operator-typed dense layer: cmbDense.

A drop-in for keras.layers.Dense followed by an OperatorBlock on the output features. Mirrors omnibias.torch.blocks.linear.cmbLinear.

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.

CLASS

cmbDense​

omnibias.keras.cmbDenseSource ↗
class cmbDense(layers.Layer)

keras.layers.Dense + per-feature OperatorBlock.

Parameters

units : int Number of output features. op : OpName, default "identity" base : str or ActivationSpec, default "sigmoid" use_bias : bool, default True Dense-layer bias (independent of the OMBU bias terms). block_kwargs : dict, optional Extra keyword arguments passed to OperatorBlock.

Parameters

NameType & defaultContract
unitspositional-or-keywordintRequiredint Number of output features.
oppositional-or-keywordOpNameDefault: 'identity'OpName, default "identity"
basepositional-or-keywordstr | ActivationSpec[Any]Default: 'sigmoid'str or ActivationSpec, default "sigmoid"
use_biaspositional-or-keywordboolDefault: Truebool, default True Dense-layer bias (independent of the OMBU bias terms).
block_kwargspositional-or-keyworddict[str, Any] | NoneDefault: Nonedict, optional Extra keyword arguments passed to OperatorBlock.
kwargsvariadic keywordAnyRequiredSee the operation contract and implementation below.
Executed regression · cmbdense shape and finite

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_cmbdense_shape_and_finite() -> None:
    x = np.random.default_rng(5).normal(size=(8, 6))
    layer = cmbDense(units=16, op="identity", base="tanh")
    out = _np(layer(_t(x)))
    assert out.shape == (8, 16)
    assert np.all(np.isfinite(out))
python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbdense_shape_and_finite" -q

Fields & methods

__init__method
__init__(self, units: int, op: OpName='identity', base: str | ActivationSpec[Any]='sigmoid', use_bias: bool=True, block_kwargs: dict[str, Any] | None=None, **kwargs: Any) -> None

See the class contract above and the exact method implementation below.

Parameters

NameType & defaultContract
unitspositional-or-keywordintRequiredSee the operation contract and implementation below.
oppositional-or-keywordOpNameDefault: 'identity'See the operation contract and implementation below.
basepositional-or-keywordstr | ActivationSpec[Any]Default: 'sigmoid'See the operation contract and implementation below.
use_biaspositional-or-keywordboolDefault: TrueSee the operation contract and implementation below.
block_kwargspositional-or-keyworddict[str, Any] | NoneDefault: NoneSee the operation contract and implementation below.
kwargsvariadic keywordAnyRequiredSee the operation contract and implementation below.

Returns: None

Executed regression · cmbdense shape and finite

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_cmbdense_shape_and_finite() -> None:
    x = np.random.default_rng(5).normal(size=(8, 6))
    layer = cmbDense(units=16, op="identity", base="tanh")
    out = _np(layer(_t(x)))
    assert out.shape == (8, 16)
    assert np.all(np.isfinite(out))
python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbdense_shape_and_finite" -q
Method implementation
    def __init__(
        self,
        units: int,
        op: OpName = "identity",
        base: str | ActivationSpec[Any] = "sigmoid",
        use_bias: bool = True,
        block_kwargs: dict[str, Any] | None = None,
        **kwargs: Any,
    ) -> None:
        super().__init__(**kwargs)
        self.units = units
        self._op = op
        self._base_name = base if isinstance(base, str) else base.name
        self._use_bias = use_bias
        self._block_kwargs = block_kwargs or {}
        self.dense = layers.Dense(units, use_bias=use_bias)
        self.block = OperatorBlock(
            op=op, base=base, channels=units, **self._block_kwargs
        )
View source ↗
callmethod
call(self, x: Any) -> Any

See the class contract above and the exact method implementation below.

Parameters

NameType & defaultContract
xpositional-or-keywordAnyRequiredSee the operation contract and implementation below.

Returns: Any

Executed regression · cmbdense shape and finite

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_cmbdense_shape_and_finite() -> None:
    x = np.random.default_rng(5).normal(size=(8, 6))
    layer = cmbDense(units=16, op="identity", base="tanh")
    out = _np(layer(_t(x)))
    assert out.shape == (8, 16)
    assert np.all(np.isfinite(out))
python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbdense_shape_and_finite" -q
Method implementation
    def call(self, x: Any) -> Any:
        return self.block(self.dense(x))
View source ↗
get_configmethod
get_config(self) -> dict[str, Any]

See the class contract above and the exact method implementation below.

Returns: dict[str, Any]

Method implementation
    def get_config(self) -> dict[str, Any]:
        config = super().get_config()
        config.update(
            {
                "units": self.units,
                "op": self._op,
                "base": self._base_name,
                "use_bias": self._use_bias,
                "block_kwargs": self._block_kwargs,
            }
        )
        return config
View source ↗
unitsattribute
units: int = units

Number of output features.

View source ↗
denseattribute
dense = layers.Dense(units, use_bias=use_bias)

Public instance attribute assigned by __init__. The source assignment is dense = layers.Dense(units, use_bias=use_bias); it describes instance state, not a literal constructor default.

View source ↗
blockattribute
block = OperatorBlock(op=op, base=base, channels=units, **self._block_kwargs)

Public instance attribute assigned by __init__. The source assignment is block = OperatorBlock(op=op, base=base, channels=units, **self._block_kwargs); it describes instance state, not a literal constructor default.

View source ↗
Read the implementation
class cmbDense(layers.Layer):
    """``keras.layers.Dense`` + per-feature :class:`OperatorBlock`.

    Parameters
    ----------
    units : int
        Number of output features.
    op : :class:`OpName`, default ``"identity"``
    base : str or :class:`ActivationSpec`, default ``"sigmoid"``
    use_bias : bool, default True
        Dense-layer bias (independent of the OMBU bias terms).
    block_kwargs : dict, optional
        Extra keyword arguments passed to :class:`OperatorBlock`.
    """

    def __init__(
        self,
        units: int,
        op: OpName = "identity",
        base: str | ActivationSpec[Any] = "sigmoid",
        use_bias: bool = True,
        block_kwargs: dict[str, Any] | None = None,
        **kwargs: Any,
    ) -> None:
        super().__init__(**kwargs)
        self.units = units
        self._op = op
        self._base_name = base if isinstance(base, str) else base.name
        self._use_bias = use_bias
        self._block_kwargs = block_kwargs or {}
        self.dense = layers.Dense(units, use_bias=use_bias)
        self.block = OperatorBlock(
            op=op, base=base, channels=units, **self._block_kwargs
        )

    def call(self, x: Any) -> Any:
        return self.block(self.dense(x))

    def get_config(self) -> dict[str, Any]:
        config = super().get_config()
        config.update(
            {
                "units": self.units,
                "op": self._op,
                "base": self._base_name,
                "use_bias": self._use_bias,
                "block_kwargs": self._block_kwargs,
            }
        )
        return config
Other public import paths
  • omnibias.keras.cmbDense
  • omnibias.keras.blocks.cmbDense
  • omnibias.keras.blocks.linear.cmbDense