omnibias.torch.blocks.operator
PyTorch activation derivatives, trainable operator layers, network jets, and direct differential-operator contractions.
import omnibias.torch.blocks.operatorModule contract & mathematical conventions
Operator-typed wrapper around OperatorMultiBiasUnit.
An OperatorBlock carries an explicit operator role tag --
"identity", "grad", "laplacian", "derivative", "band", or
"integral" -- that selects both the multi-bias arity K and the
forward-pass behaviour:
============ === ================================================ ===================================
op K forward sign init / typical use
============ === ================================================ ===================================
identity 1 sigma(z + b) Lemma 1; drop-in for the base sigma
grad 2 closed-form sigma'(z + b_mean) analytic; ignored signs
laplacian 3 closed-form sigma''(z + b_mean) analytic; ignored signs
derivative n+1 closed-form sigma^(n)(z + b_mean) analytic; ignored signs
band 2 literal sigma(z + b_hi) - sigma(z + b_lo) fixed oriented signs
integral 2 closed-form S(z + b_hi) - S(z + b_lo), S'=sigma fixed oriented signs
============ === ================================================ ===================================
The "grad", "laplacian", and "derivative" paths use the
activation's fast-path kernel. The "integral" path uses the activation's
antiderivative kernel. These roles therefore require a base activation whose
ActivationSpec provides the matching kernel. Combinations without
one raise a clear TypeError at construction.
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.
OpName
omnibias.torch.blocks.operator.OpNameSource ↗OpName = Literal['identity', 'grad', 'laplacian', 'derivative', 'band', 'integral']This exported constant is defined by the expression above. Its exact value and annotation come from the pinned source; use it with the module contract.
Read the implementation
OpName = Literal["identity", "grad", "laplacian", "derivative", "band", "integral"]OperatorBlock
omnibias.torch.OperatorBlockSource ↗class OperatorBlock(nn.Module)An OMBU with operator-type semantics.
Parameters
op : "identity" | "grad" | "laplacian" | "derivative" | "band" | "integral" Operator role; determines K and the forward behaviour.
base : str or ActivationSpec, default "gaussian" Base activation. "grad" / "laplacian" / "derivative" require a derivative fast-path kernel; "integral" requires an antiderivative kernel.
channels : int, default 1 Number of independent channels.
init_delta : float, optional Spread between adjacent biases at init. Default is 0.0 for "identity" / "grad" / "laplacian" (Lemma 1) and 1.0 for "integral" (so the integral window is non-empty at init).
learnable_biases : bool, default True
learnable_signs : bool, default False Expert option for "band" / "integral". Fixed signs preserve clean window semantics; learnable signs turn the operator into a learned activation or antiderivative mixture.
derivative_order : int, optional Required for op="derivative". The block uses K = order + 1 and evaluates sigma^(order)(z + b_mean) through the activation fast path. Use op="grad" / op="laplacian" as aliases for orders 1 and 2.
normalize_integral : bool, default False For op="integral", divide the window area by its positive width.
integral_small_width : float, default 1e-4 For strict integral windows, use the midpoint Taylor limit below this width to avoid subtractive cancellation.
Parameters
| Name | Type & default | Contract |
|---|---|---|
oppositional-or-keyword | OpNameRequired | "identity" | "grad" | "laplacian" | "derivative" | "band" | "integral" Operator role; determines K and the forward behaviour. |
basepositional-or-keyword | str | ActivationSpec[Tensor]Default: 'gaussian' | str or ActivationSpec, default "gaussian" Base activation. "grad" / "laplacian" / "derivative" require a derivative fast-path kernel; "integral" requires an antiderivative kernel. |
channelspositional-or-keyword | intDefault: 1 | int, default 1 Number of independent channels. |
init_biaspositional-or-keyword | floatDefault: 0.0 | See the operation contract and implementation below. |
init_deltapositional-or-keyword | float | NoneDefault: None | float, optional Spread between adjacent biases at init. Default is 0.0 for "identity" / "grad" / "laplacian" (Lemma 1) and 1.0 for "integral" (so the integral window is non-empty at init). |
learnable_biasespositional-or-keyword | boolDefault: True | bool, default True |
learnable_signspositional-or-keyword | bool | NoneDefault: None | bool, default False Expert option for "band" / "integral". Fixed signs preserve clean window semantics; learnable signs turn the operator into a learned activation or antiderivative mixture. |
derivative_orderpositional-or-keyword | int | NoneDefault: None | int, optional Required for op="derivative". The block uses K = order + 1 and evaluates sigma^(order)(z + b_mean) through the activation fast path. Use op="grad" / op="laplacian" as aliases for orders 1 and 2. |
normalize_integralpositional-or-keyword | boolDefault: False | bool, default False For op="integral", divide the window area by its positive width. |
integral_small_widthpositional-or-keyword | floatDefault: 0.0001 | float, default 1e-4 For strict integral windows, use the midpoint Taylor limit below this width to avoid subtractive cancellation. |
Executed regression · invalid op 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_invalid_op_raises() -> None:
with pytest.raises(ValueError):
OperatorBlock(op="curl", base="sigmoid", channels=2)python -m pytest "packages/omnibias-torch/tests/test_blocks.py::test_invalid_op_raises" -qRegression example · derivative block requires order
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_derivative_block_requires_order() -> None:
with pytest.raises(ValueError):
OperatorBlock(op="derivative", base="sigmoid", channels=3)python -m pytest packages/omnibias-torch/tests/test_blocks.py -k test_derivative_block_requires_order -qFields & methods
ombufield
ombu: OperatorMultiBiasUnitDeclared OperatorMultiBiasUnit field on OperatorBlock. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
Regression example · integral block defaults to fixed signs
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_integral_block_defaults_to_fixed_signs() -> None:
block = OperatorBlock(op="integral", base="sigmoid", channels=3)
assert not isinstance(block.ombu.signs, torch.nn.Parameter)python -m pytest packages/omnibias-torch/tests/test_blocks.py -k test_integral_block_defaults_to_fixed_signs -q__init__method
__init__(self, op: OpName, base: str | ActivationSpec[Tensor]='gaussian', channels: int=1, init_bias: float=0.0, init_delta: float | None=None, learnable_biases: bool=True, learnable_signs: bool | None=None, derivative_order: int | None=None, normalize_integral: bool=False, integral_small_width: float=0.0001) -> NoneSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
oppositional-or-keyword | OpNameRequired | See the operation contract and implementation below. |
basepositional-or-keyword | str | ActivationSpec[Tensor]Default: 'gaussian' | See the operation contract and implementation below. |
channelspositional-or-keyword | intDefault: 1 | See the operation contract and implementation below. |
init_biaspositional-or-keyword | floatDefault: 0.0 | See the operation contract and implementation below. |
init_deltapositional-or-keyword | float | NoneDefault: None | See the operation contract and implementation below. |
learnable_biasespositional-or-keyword | boolDefault: True | See the operation contract and implementation below. |
learnable_signspositional-or-keyword | bool | NoneDefault: None | See the operation contract and implementation below. |
derivative_orderpositional-or-keyword | int | NoneDefault: None | See the operation contract and implementation below. |
normalize_integralpositional-or-keyword | boolDefault: False | See the operation contract and implementation below. |
integral_small_widthpositional-or-keyword | floatDefault: 0.0001 | See the operation contract and implementation below. |
Returns: None
Validation & failure cases
- When
op not in _VALID_OPS, raisesValueError(f'op must be one of {list(_VALID_OPS)}, got {op!r}.'). - When
derivative_order is not None and op in ('grad', 'laplacian'), raisesValueError(f"derivative_order is only valid with op='derivative'; use op={op!r} without it or op='derivative' for arbitrary order."). - When
derivative_order is None, raisesValueError("OperatorBlock(op='derivative') requires derivative_order."). - When
derivative_order < 1, raisesValueError(f'derivative_order must be >= 1, got {derivative_order}.'). - When
spec.fastpath is None, raisesTypeError(f'OperatorBlock(op={op!r}) requires a base activation with a closed-form derivative kernel; activation {spec.name!r} has none. Choose one of: sigmoid, tanh, softplus, gaussian, exp, huber, arctan, log1pu2.'). - When
op == 'integral' and spec.integral is None, raisesTypeError(f"OperatorBlock(op='integral') requires a base activation with a closed-form integral kernel; activation {spec.name!r} has none.").
Executed regression · invalid op 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_invalid_op_raises() -> None:
with pytest.raises(ValueError):
OperatorBlock(op="curl", base="sigmoid", channels=2)python -m pytest "packages/omnibias-torch/tests/test_blocks.py::test_invalid_op_raises" -qMethod implementation
def __init__(
self,
op: OpName,
base: str | ActivationSpec[Tensor] = "gaussian",
channels: int = 1,
init_bias: float = 0.0,
init_delta: float | None = None,
learnable_biases: bool = True,
learnable_signs: bool | None = None,
derivative_order: int | None = None,
normalize_integral: bool = False,
integral_small_width: float = 1e-4,
) -> None:
super().__init__()
if op not in _VALID_OPS:
raise ValueError(f"op must be one of {list(_VALID_OPS)}, got {op!r}.")
self.op = op
self.normalize_integral = normalize_integral
self.integral_small_width = integral_small_width
if derivative_order is not None and op in ("grad", "laplacian"):
raise ValueError(
f"derivative_order is only valid with op='derivative'; use op={op!r} without it "
f"or op='derivative' for arbitrary order."
)
if op == "derivative":
if derivative_order is None:
raise ValueError("OperatorBlock(op='derivative') requires derivative_order.")
if derivative_order < 1:
raise ValueError(f"derivative_order must be >= 1, got {derivative_order}.")
K = derivative_order + 1
self._derivative_order = derivative_order
else:
K = _OP_K[op]
self._derivative_order = _OP_DERIVATIVE_ORDER[op]
spec = base if isinstance(base, ActivationSpec) else get_activation(base)
# Validate fast-path availability for the analytic-derivative ops.
if op in ("grad", "laplacian", "derivative"):
required_order = self._derivative_order
if spec.fastpath is None:
raise TypeError(
f"OperatorBlock(op={op!r}) requires a base activation with a "
f"closed-form derivative kernel; activation {spec.name!r} has none. "
"Choose one of: sigmoid, tanh, softplus, gaussian, exp, "
"huber, arctan, log1pu2."
)
try:
spec.fastpath(torch.zeros(1), required_order)
except NotImplementedError as e:
raise TypeError(
f"OperatorBlock(op={op!r}) requires order-{required_order} "
f"derivative; activation {spec.name!r} only supports a partial "
f"fastpath. ({e})"
) from None
if op == "integral" and spec.integral is None:
raise TypeError(
f"OperatorBlock(op='integral') requires a base activation with a "
f"closed-form integral kernel; activation {spec.name!r} has none."
)
# Per-op defaults for init_delta and learnable_signs.
if init_delta is None:
init_delta = 1.0 if op in ("band", "integral") else 0.0
if learnable_signs is None:
learnable_signs = False
# Custom init for bias windows. "band" stores literal low/high
# endpoints; strict "integral" stores (center, raw_width) so the
# ordered positive width cannot cross during training.
if op == "band":
signs_init = _window_signs(channels, K, dtype=torch.get_default_dtype())
offsets = central_bias_offsets(K, init_delta).unsqueeze(0)
biases_init = identity_init_biases(channels, K, bias_value=init_bias) + offsets
elif op == "integral":
signs_init = _window_signs(channels, K, dtype=torch.get_default_dtype())
biases_init = torch.empty(channels, K, dtype=torch.get_default_dtype())
biases_init[:, 0] = init_bias
biases_init[:, 1] = _inverse_softplus(init_delta)
else:
signs_init = None
biases_init = None # let OMBU build Lemma-1 init internally
self.ombu = OperatorMultiBiasUnit(
num_channels=channels,
K=K,
base=spec,
init_bias=init_bias,
init_delta=init_delta if op not in ("band", "integral") else 0.0,
learnable_biases=learnable_biases,
learnable_signs=learnable_signs,
biases_init=biases_init,
signs_init=signs_init,
)channelsproperty
channels(self) -> intSee the class contract above and the exact method implementation below.
Returns: int
Method implementation
def channels(self) -> int:
return self.ombu.num_channelsKproperty
K(self) -> intSee the class contract above and the exact method implementation below.
Returns: int
Executed regression · derivative block supports k7 order6
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_derivative_block_supports_k7_order6() -> None:
block = OperatorBlock(op="derivative", derivative_order=6, base="tanh", channels=2)
z = torch.randn(5, 2)
out = block(z)
ref = block.ombu.spec.fastpath(z, 6)
assert block.K == 7
assert block.derivative_order == 6
assert torch.allclose(out, ref, atol=1e-6)python -m pytest "packages/omnibias-torch/tests/test_blocks.py::test_derivative_block_supports_k7_order6" -qMethod implementation
def K(self) -> int:
return self.ombu.Kbase_nameproperty
base_name(self) -> strSee the class contract above and the exact method implementation below.
Returns: str
Method implementation
def base_name(self) -> str:
return self.ombu.spec.namederivative_orderproperty
derivative_order(self) -> intSee the class contract above and the exact method implementation below.
Returns: int
Executed regression · derivative block supports k7 order6
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_derivative_block_supports_k7_order6() -> None:
block = OperatorBlock(op="derivative", derivative_order=6, base="tanh", channels=2)
z = torch.randn(5, 2)
out = block(z)
ref = block.ombu.spec.fastpath(z, 6)
assert block.K == 7
assert block.derivative_order == 6
assert torch.allclose(out, ref, atol=1e-6)python -m pytest "packages/omnibias-torch/tests/test_blocks.py::test_derivative_block_supports_k7_order6" -qMethod implementation
def derivative_order(self) -> int:
return self._derivative_orderforwardmethod
forward(self, z: Tensor) -> TensorDispatch to the appropriate forward path for this op type.
"identity": literal forward (==sigma(z + b)for K=1)."grad"/"laplacian"/"derivative": closed-form analytic derivative."integral": closed-form sign-weighted antiderivative.
Parameters
| Name | Type & default | Contract |
|---|---|---|
zpositional-or-keyword | TensorRequired | See the operation contract and implementation below. |
Returns: Tensor
Executed regression · cmblinear forward shape
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_cmblinear_forward_shape() -> None:
layer = cmbLinear(5, 3, op="identity", base="tanh")
out = layer(torch.randn(2, 5))
assert out.shape == (2, 3)python -m pytest "packages/omnibias-torch/tests/test_blocks.py::test_cmblinear_forward_shape" -qMethod implementation
def forward(self, z: Tensor) -> Tensor:
"""Dispatch to the appropriate forward path for this op type.
- ``"identity"``: literal forward (== ``sigma(z + b)`` for K=1).
- ``"grad"`` / ``"laplacian"`` / ``"derivative"``: closed-form analytic derivative.
- ``"integral"``: closed-form sign-weighted antiderivative.
"""
if self.op == "identity":
out: Tensor = self.ombu(z)
return out
if self.op == "band":
out = self.ombu(z)
return out
if self.op == "integral":
return self.ombu.analytic_integral(
z,
strict_window=True,
normalize=self.normalize_integral,
small_width_threshold=self.integral_small_width,
)
return self.ombu.analytic_derivative(z, order=self._derivative_order)literal_forwardmethod
literal_forward(self, z: Tensor) -> TensorLiteral activation-space counterpart for diagnostics.
For strict "integral" blocks this returns the corresponding
activation band over the ordered window endpoints.
Parameters
| Name | Type & default | Contract |
|---|---|---|
zpositional-or-keyword | TensorRequired | See the operation contract and implementation below. |
Returns: Tensor
Executed regression · operator integral derivative recovers band
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_operator_integral_derivative_recovers_band() -> None:
integral = OperatorBlock(op="integral", base="tanh", channels=1, init_delta=0.75).double()
band = OperatorBlock(op="band", base="tanh", channels=1, init_delta=0.75).double()
with torch.no_grad():
band.ombu.biases[:, 0] = integral.ombu.biases[:, 0] - 0.5 * torch.nn.functional.softplus(
integral.ombu.biases[:, 1]
)
band.ombu.biases[:, 1] = integral.ombu.biases[:, 0] + 0.5 * torch.nn.functional.softplus(
integral.ombu.biases[:, 1]
)
z = torch.linspace(-1.0, 1.0, 21, dtype=torch.double).unsqueeze(-1).requires_grad_(True)
area = integral(z)
(grad,) = torch.autograd.grad(area.sum(), z)
assert torch.allclose(grad, band(z), atol=1e-10, rtol=1e-10)
assert torch.allclose(integral.literal_forward(z.detach()), band(z.detach()), atol=1e-10, rtol=1e-10)python -m pytest "packages/omnibias-torch/tests/test_integral_primitives.py::test_operator_integral_derivative_recovers_band" -qMethod implementation
def literal_forward(self, z: Tensor) -> Tensor:
"""Literal activation-space counterpart for diagnostics.
For strict ``"integral"`` blocks this returns the corresponding
activation band over the ordered window endpoints.
"""
if self.op == "integral":
center = self.ombu.biases[:, 0]
width = F.softplus(self.ombu.biases[:, 1])
half_width = 0.5 * width
endpoints = torch.stack((center - half_width, center + half_width), dim=-1)
return multibias_literal_forward(z, endpoints, self.ombu.signs, self.ombu.spec.forward)
out: Tensor = self.ombu(z)
return outextra_reprmethod
extra_repr(self) -> strSee the class contract above and the exact method implementation below.
Returns: str
Method implementation
def extra_repr(self) -> str:
return (
f"op={self.op!r}, K={self.K}, derivative_order={self.derivative_order}, "
f"base={self.base_name!r}, channels={self.channels}"
)normalize_integralattribute
normalize_integral: bool = normalize_integralFor op="integral", divide the window area by its positive width.
integral_small_widthattribute
integral_small_width: float = integral_small_widthFor strict integral windows, use the midpoint Taylor limit below this width to avoid subtractive cancellation.
Read the implementation
class OperatorBlock(nn.Module):
"""An OMBU with operator-type semantics.
Parameters
----------
op : ``"identity"`` | ``"grad"`` | ``"laplacian"`` | ``"derivative"`` | ``"band"`` | ``"integral"``
Operator role; determines K and the forward behaviour.
base : str or :class:`ActivationSpec`, default ``"gaussian"``
Base activation. ``"grad"`` / ``"laplacian"`` / ``"derivative"``
require a derivative fast-path kernel; ``"integral"`` requires an
antiderivative kernel.
channels : int, default 1
Number of independent channels.
init_delta : float, optional
Spread between adjacent biases at init. Default is ``0.0`` for
``"identity"`` / ``"grad"`` / ``"laplacian"`` (Lemma 1) and
``1.0`` for ``"integral"`` (so the integral window is non-empty
at init).
learnable_biases : bool, default True
learnable_signs : bool, default False
Expert option for ``"band"`` / ``"integral"``. Fixed signs preserve
clean window semantics; learnable signs turn the operator into a
learned activation or antiderivative mixture.
derivative_order : int, optional
Required for ``op="derivative"``. The block uses ``K = order + 1``
and evaluates ``sigma^(order)(z + b_mean)`` through the activation
fast path. Use ``op="grad"`` / ``op="laplacian"`` as aliases for
orders 1 and 2.
normalize_integral : bool, default False
For ``op="integral"``, divide the window area by its positive width.
integral_small_width : float, default 1e-4
For strict integral windows, use the midpoint Taylor limit below this
width to avoid subtractive cancellation.
"""
op: OpName
ombu: OperatorMultiBiasUnit
def __init__(
self,
op: OpName,
base: str | ActivationSpec[Tensor] = "gaussian",
channels: int = 1,
init_bias: float = 0.0,
init_delta: float | None = None,
learnable_biases: bool = True,
learnable_signs: bool | None = None,
derivative_order: int | None = None,
normalize_integral: bool = False,
integral_small_width: float = 1e-4,
) -> None:
super().__init__()
if op not in _VALID_OPS:
raise ValueError(f"op must be one of {list(_VALID_OPS)}, got {op!r}.")
self.op = op
self.normalize_integral = normalize_integral
self.integral_small_width = integral_small_width
if derivative_order is not None and op in ("grad", "laplacian"):
raise ValueError(
f"derivative_order is only valid with op='derivative'; use op={op!r} without it "
f"or op='derivative' for arbitrary order."
)
if op == "derivative":
if derivative_order is None:
raise ValueError("OperatorBlock(op='derivative') requires derivative_order.")
if derivative_order < 1:
raise ValueError(f"derivative_order must be >= 1, got {derivative_order}.")
K = derivative_order + 1
self._derivative_order = derivative_order
else:
K = _OP_K[op]
self._derivative_order = _OP_DERIVATIVE_ORDER[op]
spec = base if isinstance(base, ActivationSpec) else get_activation(base)
# Validate fast-path availability for the analytic-derivative ops.
if op in ("grad", "laplacian", "derivative"):
required_order = self._derivative_order
if spec.fastpath is None:
raise TypeError(
f"OperatorBlock(op={op!r}) requires a base activation with a "
f"closed-form derivative kernel; activation {spec.name!r} has none. "
"Choose one of: sigmoid, tanh, softplus, gaussian, exp, "
"huber, arctan, log1pu2."
)
try:
spec.fastpath(torch.zeros(1), required_order)
except NotImplementedError as e:
raise TypeError(
f"OperatorBlock(op={op!r}) requires order-{required_order} "
f"derivative; activation {spec.name!r} only supports a partial "
f"fastpath. ({e})"
) from None
if op == "integral" and spec.integral is None:
raise TypeError(
f"OperatorBlock(op='integral') requires a base activation with a "
f"closed-form integral kernel; activation {spec.name!r} has none."
)
# Per-op defaults for init_delta and learnable_signs.
if init_delta is None:
init_delta = 1.0 if op in ("band", "integral") else 0.0
if learnable_signs is None:
learnable_signs = False
# Custom init for bias windows. "band" stores literal low/high
# endpoints; strict "integral" stores (center, raw_width) so the
# ordered positive width cannot cross during training.
if op == "band":
signs_init = _window_signs(channels, K, dtype=torch.get_default_dtype())
offsets = central_bias_offsets(K, init_delta).unsqueeze(0)
biases_init = identity_init_biases(channels, K, bias_value=init_bias) + offsets
elif op == "integral":
signs_init = _window_signs(channels, K, dtype=torch.get_default_dtype())
biases_init = torch.empty(channels, K, dtype=torch.get_default_dtype())
biases_init[:, 0] = init_bias
biases_init[:, 1] = _inverse_softplus(init_delta)
else:
signs_init = None
biases_init = None # let OMBU build Lemma-1 init internally
self.ombu = OperatorMultiBiasUnit(
num_channels=channels,
K=K,
base=spec,
init_bias=init_bias,
init_delta=init_delta if op not in ("band", "integral") else 0.0,
learnable_biases=learnable_biases,
learnable_signs=learnable_signs,
biases_init=biases_init,
signs_init=signs_init,
)
@property
def channels(self) -> int:
return self.ombu.num_channels
@property
def K(self) -> int:
return self.ombu.K
@property
def base_name(self) -> str:
return self.ombu.spec.name
@property
def derivative_order(self) -> int:
return self._derivative_order
def forward(self, z: Tensor) -> Tensor:
"""Dispatch to the appropriate forward path for this op type.
- ``"identity"``: literal forward (== ``sigma(z + b)`` for K=1).
- ``"grad"`` / ``"laplacian"`` / ``"derivative"``: closed-form analytic derivative.
- ``"integral"``: closed-form sign-weighted antiderivative.
"""
if self.op == "identity":
out: Tensor = self.ombu(z)
return out
if self.op == "band":
out = self.ombu(z)
return out
if self.op == "integral":
return self.ombu.analytic_integral(
z,
strict_window=True,
normalize=self.normalize_integral,
small_width_threshold=self.integral_small_width,
)
return self.ombu.analytic_derivative(z, order=self._derivative_order)
def literal_forward(self, z: Tensor) -> Tensor:
"""Literal activation-space counterpart for diagnostics.
For strict ``"integral"`` blocks this returns the corresponding
activation band over the ordered window endpoints.
"""
if self.op == "integral":
center = self.ombu.biases[:, 0]
width = F.softplus(self.ombu.biases[:, 1])
half_width = 0.5 * width
endpoints = torch.stack((center - half_width, center + half_width), dim=-1)
return multibias_literal_forward(z, endpoints, self.ombu.signs, self.ombu.spec.forward)
out: Tensor = self.ombu(z)
return out
def extra_repr(self) -> str:
return (
f"op={self.op!r}, K={self.K}, derivative_order={self.derivative_order}, "
f"base={self.base_name!r}, channels={self.channels}"
)Other public import paths
omnibias.torch.OperatorBlockomnibias.torch.blocks.OperatorBlockomnibias.torch.blocks.operator.OperatorBlock