omnibias.core.verified.tm_neuron
Coefficient recurrences, activation contracts, jet algebra, and verified arithmetic shared by the numerical backends.
import omnibias.core.verified.tm_neuronModule contract & mathematical conventions
Taylor-model neuron (theory 09-05).
A unit whose output is a TaylorModel, not a float. Affine
image plus sigma via the closed-form tower (founding bias collapse
delta -> 0) and a Lagrange remainder. Temperature collapse
(beta -> inf, feasibility) does not appear. Do not conflate the
two.
Sound enclosure of a shallow monotone cell over the supplied input domain.
theorem_prover_verified is not asserted.
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.
DEFAULT_SPEC
omnibias.core.verified.tm_neuron.DEFAULT_SPECSource ↗DEFAULT_SPEC = TMNeuronSpec()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
DEFAULT_SPEC = TMNeuronSpec()DISCLAIMER
omnibias.core.verified.tm_neuron.DISCLAIMERSource ↗DISCLAIMER = 'TM hidden state; sound remainder, not a deep-net certificate, not ImageNet'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.
Regression example · honesty
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_honesty() -> None:
payload = honesty_payload()
assert payload["imagenet_claim"] is False
assert payload["stretch_claim"] is False
assert payload["theorem_prover_verified"] is False
assert "not a deep-net" in DISCLAIMERpython -m pytest packages/omnibias-core/tests/verified/test_tm_neuron.py -k test_honesty -qRead the implementation
DISCLAIMER = (
"TM hidden state; sound remainder, not a deep-net certificate, not ImageNet"
)TMNeuronSpec
omnibias.core.verified.tm_neuron.TMNeuronSpecSource ↗class TMNeuronSpecDataclass constructor fields; inherited fields, if any, are declared by the base class. A field(...) expression describes a default factory or field options, not a literal argument default.
The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
orderdataclass field | intDefault: 1 | See the operation contract and implementation below. |
activationdataclass field | strDefault: 'sigmoid' | See the operation contract and implementation below. |
Regression example · g1 soundness grid and sample
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_g1_soundness_grid_and_sample() -> None:
spec = TMNeuronSpec(order=1, activation="sigmoid")
tm = tm_dense(input_tm(0.0, 0.2, spec.order), 1.0, 0.0, spec)
assert contains_grid_and_sample(tm, "sigmoid", 0.0, 0.2)python -m pytest packages/omnibias-core/tests/verified/test_tm_neuron.py -k test_g1_soundness_grid_and_sample -qFields & methods
orderfield
order: int = 1Declared int field on TMNeuronSpec. Default expression: 1.
Regression example · g1 soundness grid and sample
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_g1_soundness_grid_and_sample() -> None:
spec = TMNeuronSpec(order=1, activation="sigmoid")
tm = tm_dense(input_tm(0.0, 0.2, spec.order), 1.0, 0.0, spec)
assert contains_grid_and_sample(tm, "sigmoid", 0.0, 0.2)python -m pytest packages/omnibias-core/tests/verified/test_tm_neuron.py -k test_g1_soundness_grid_and_sample -qactivationfield
activation: str = 'sigmoid'Declared str field on TMNeuronSpec. Default expression: 'sigmoid'.
Read the implementation
class TMNeuronSpec:
order: int = 1
activation: str = "sigmoid"compose_sigma_tm
omnibias.core.verified.tm_neuron.compose_sigma_tmSource ↗compose_sigma_tm(tm: TaylorModel, name: str, order: int) -> TaylorModelsigma of a 1-D TM: polynomial tower plus Lagrange remainder.
Parameters
| Name | Type & default | Contract |
|---|---|---|
tmpositional-or-keyword | TaylorModelRequired | See the operation contract and implementation below. |
namepositional-or-keyword | strRequired | See the operation contract and implementation below. |
orderpositional-or-keyword | intRequired | See the operation contract and implementation below. |
TaylorModelExplicit validation & failure cases
- When
order < 1, raisesValueError('TM-sigma needs order >= 1').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · g2 non vacuous
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_g2_non_vacuous() -> None:
ex = worked_example()
assert float(ex["remainder_width"]) < 0.1
assert ex["vacuous"] is False
assert float(ex["width"]) < 0.1python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -qRead the implementation
def compose_sigma_tm(tm: TaylorModel, name: str, order: int) -> TaylorModel:
"""``sigma`` of a 1-D TM: polynomial tower plus Lagrange remainder."""
if order < 1:
raise ValueError("TM-sigma needs order >= 1")
mid = tm.coeffs[0].mid
tower = sigma_tower_interval(name, Interval.point(mid), order)
shifted = tm - mid
poly = TaylorModel.constant(tower[0], tm.center, tm.radius, tm.order)
power = TaylorModel.constant(1.0, tm.center, tm.radius, tm.order)
fact = 1
for k in range(1, order + 1):
fact *= k
power = power * shifted
poly = poly + power * (tower[k] * Interval.from_rational(Fraction(1, fact)))
rng = hull([tm.bound(), Interval.point(mid)])
tail = sigma_tower_interval(name, rng, order + 1)[order + 1]
h_range = tm.bound() - Interval.point(mid)
lagrange = tail * Interval.from_rational(Fraction(1, math.factorial(order + 1))) * _even_pow(
h_range, order + 1
)
result = TaylorModel(tm.center, tm.radius, poly.coeffs, poly.remainder + lagrange)
direct = sigma_value_interval(name, tm.bound())
poly_bound = result._poly_bound()
cap = direct - poly_bound
new_lo = max(result.remainder.lo, cap.lo)
new_hi = min(result.remainder.hi, cap.hi)
if new_lo <= new_hi:
return TaylorModel(tm.center, tm.radius, result.coeffs, Interval(new_lo, new_hi))
return resultcontains_grid_and_sample
omnibias.core.verified.tm_neuron.contains_grid_and_sampleSource ↗contains_grid_and_sample(tm: TaylorModel, fn: str, lo: float, hi: float, *, n_grid: int=65, n_sample: int=32, seed: int=20260821) -> boolCore verified contract: enclosure holds a grid and a random sample.
Parameters
| Name | Type & default | Contract |
|---|---|---|
tmpositional-or-keyword | TaylorModelRequired | See the operation contract and implementation below. |
fnpositional-or-keyword | strRequired | See the operation contract and implementation below. |
lopositional-or-keyword | floatRequired | See the operation contract and implementation below. |
hipositional-or-keyword | floatRequired | See the operation contract and implementation below. |
n_gridkeyword-only | intDefault: 65 | See the operation contract and implementation below. |
n_samplekeyword-only | intDefault: 32 | See the operation contract and implementation below. |
seedkeyword-only | intDefault: 20260821 | See the operation contract and implementation below. |
boolExecuted regression · g1 soundness grid and sample
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_g1_soundness_grid_and_sample() -> None:
spec = TMNeuronSpec(order=1, activation="sigmoid")
tm = tm_dense(input_tm(0.0, 0.2, spec.order), 1.0, 0.0, spec)
assert contains_grid_and_sample(tm, "sigmoid", 0.0, 0.2)python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g1_soundness_grid_and_sample" -qRead the implementation
def contains_grid_and_sample(
tm: TaylorModel,
fn: str,
lo: float,
hi: float,
*,
n_grid: int = 65,
n_sample: int = 32,
seed: int = 20260821,
) -> bool:
"""Core verified contract: enclosure holds a grid and a random sample."""
box = tm.bound()
xs = [lo + (hi - lo) * i / (n_grid - 1) for i in range(n_grid)]
rng = random.Random(seed)
xs.extend(rng.uniform(lo, hi) for _ in range(n_sample))
for x in xs:
if fn == "sigmoid":
ez = math.exp(-x) if x >= 0.0 else math.exp(x)
true = 1.0 / (1.0 + ez) if x >= 0.0 else ez / (1.0 + ez)
elif fn == "tanh":
true = math.tanh(x)
else:
raise ValueError(f"unsupported sample activation {fn!r}")
if not box.contains(true):
return False
return Truedepth_honesty
omnibias.core.verified.tm_neuron.depth_honestySource ↗depth_honesty(*, layers: int=6) -> dict[str, float | bool | int]G3: a 6-layer random-sign nest. Explosion is allowed and recorded.
Parameters
| Name | Type & default | Contract |
|---|---|---|
layerskeyword-only | intDefault: 6 | See the operation contract and implementation below. |
dict[str, float | bool | int]Executed regression · g3 depth honesty records explosion
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_g3_depth_honesty_records_explosion() -> None:
report = depth_honesty()
assert "enclosure_exploded" in report
if float(report["remainder_width"]) > 1e3:
assert report["enclosure_exploded"] is Truepython -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g3_depth_honesty_records_explosion" -qRead the implementation
def depth_honesty(*, layers: int = 6) -> dict[str, float | bool | int]:
"""G3: a 6-layer random-sign nest. Explosion is allowed and recorded."""
rng = random.Random(20260821)
weights = [rng.uniform(-3.0, 3.0) for _ in range(layers)]
biases = [rng.uniform(-0.5, 0.5) for _ in range(layers)]
tm = nest_layers(weights, biases)
width = tm.remainder.width
exploded = width > 1e3
return {
"layers": layers,
"remainder_width": width,
"bound_width": tm.bound().width,
"enclosure_exploded": exploded,
}honesty_payload
omnibias.core.verified.tm_neuron.honesty_payloadSource ↗honesty_payload() -> dict[str, bool]The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.
dict[str, bool]Executed regression · honesty
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_honesty() -> None:
payload = honesty_payload()
assert payload["imagenet_claim"] is False
assert payload["stretch_claim"] is False
assert payload["theorem_prover_verified"] is False
assert "not a deep-net" in DISCLAIMERpython -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_honesty" -qRead the implementation
def honesty_payload() -> dict[str, bool]:
return {
"imagenet_claim": False,
"stretch_claim": False,
"deep_net_certificate": False,
"ns_regularity": False,
"theorem_prover_verified": False,
}input_tm
omnibias.core.verified.tm_neuron.input_tmSource ↗input_tm(lo: float, hi: float, order: int) -> TaylorModelIdentity Taylor model on [lo, hi].
Parameters
| Name | Type & default | Contract |
|---|---|---|
lopositional-or-keyword | floatRequired | See the operation contract and implementation below. |
hipositional-or-keyword | floatRequired | See the operation contract and implementation below. |
orderpositional-or-keyword | intRequired | See the operation contract and implementation below. |
TaylorModelExplicit validation & failure cases
- When
hi < lo, raisesValueError(f'empty box: [{lo}, {hi}]').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · g2 non vacuous
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_g2_non_vacuous() -> None:
ex = worked_example()
assert float(ex["remainder_width"]) < 0.1
assert ex["vacuous"] is False
assert float(ex["width"]) < 0.1python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -qRegression example · g1 soundness grid and sample
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_g1_soundness_grid_and_sample() -> None:
spec = TMNeuronSpec(order=1, activation="sigmoid")
tm = tm_dense(input_tm(0.0, 0.2, spec.order), 1.0, 0.0, spec)
assert contains_grid_and_sample(tm, "sigmoid", 0.0, 0.2)python -m pytest packages/omnibias-core/tests/verified/test_tm_neuron.py -k test_g1_soundness_grid_and_sample -qRead the implementation
def input_tm(lo: float, hi: float, order: int) -> TaylorModel:
"""Identity Taylor model on ``[lo, hi]``."""
if hi < lo:
raise ValueError(f"empty box: [{lo}, {hi}]")
center = 0.5 * (lo + hi)
radius = 0.5 * (hi - lo)
return TaylorModel.identity(center, radius, order)nest_layers
omnibias.core.verified.tm_neuron.nest_layersSource ↗nest_layers(weights: Sequence[float], biases: Sequence[float], *, lo: float=0.0, hi: float=0.2, spec: TMNeuronSpec | None=None) -> TaylorModelThe module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
weightspositional-or-keyword | Sequence[float]Required | See the operation contract and implementation below. |
biasespositional-or-keyword | Sequence[float]Required | See the operation contract and implementation below. |
lokeyword-only | floatDefault: 0.0 | See the operation contract and implementation below. |
hikeyword-only | floatDefault: 0.2 | See the operation contract and implementation below. |
speckeyword-only | TMNeuronSpec | NoneDefault: None | See the operation contract and implementation below. |
TaylorModelExecuted regression · g3 depth honesty records explosion
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_g3_depth_honesty_records_explosion() -> None:
report = depth_honesty()
assert "enclosure_exploded" in report
if float(report["remainder_width"]) > 1e3:
assert report["enclosure_exploded"] is Truepython -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g3_depth_honesty_records_explosion" -qRead the implementation
def nest_layers(
weights: Sequence[float],
biases: Sequence[float],
*,
lo: float = 0.0,
hi: float = 0.2,
spec: TMNeuronSpec | None = None,
) -> TaylorModel:
cfg = DEFAULT_SPEC if spec is None else spec
tm = input_tm(lo, hi, cfg.order)
for weight, bias in zip(weights, biases, strict=True):
tm = tm_dense(tm, weight, bias, cfg)
return tmsource_imports_no_backend
omnibias.core.verified.tm_neuron.source_imports_no_backendSource ↗source_imports_no_backend(path: Path | None=None) -> boolG4: the authored module must not import torch / jax / tensorflow / keras.
Parameters
| Name | Type & default | Contract |
|---|---|---|
pathpositional-or-keyword | Path | NoneDefault: None | See the operation contract and implementation below. |
boolExecuted regression · g4 no backend leak
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_g4_no_backend_leak() -> None:
assert source_imports_no_backend()python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g4_no_backend_leak" -qRead the implementation
def source_imports_no_backend(path: Path | None = None) -> bool:
"""G4: the authored module must not import torch / jax / tensorflow / keras."""
src = Path(path) if path is not None else Path(__file__)
tree = ast.parse(src.read_text(encoding="utf-8"))
blocked = {"torch", "jax", "tensorflow", "keras"}
for node in ast.walk(tree):
if isinstance(node, ast.Import):
for alias in node.names:
if alias.name.split(".", 1)[0] in blocked:
return False
elif isinstance(node, ast.ImportFrom) and node.module:
if node.module.split(".", 1)[0] in blocked:
return False
return Truetm_dense
omnibias.core.verified.tm_neuron.tm_denseSource ↗tm_dense(tm_in: TaylorModel, weight: float, bias: float, spec: TMNeuronSpec | None=None) -> TaylorModelAffine w * x + b then TM-sigma. Pure Python; no torch / jax.
Parameters
| Name | Type & default | Contract |
|---|---|---|
tm_inpositional-or-keyword | TaylorModelRequired | See the operation contract and implementation below. |
weightpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
biaspositional-or-keyword | floatRequired | See the operation contract and implementation below. |
specpositional-or-keyword | TMNeuronSpec | NoneDefault: None | See the operation contract and implementation below. |
TaylorModelExecuted regression · g2 non vacuous
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_g2_non_vacuous() -> None:
ex = worked_example()
assert float(ex["remainder_width"]) < 0.1
assert ex["vacuous"] is False
assert float(ex["width"]) < 0.1python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -qRegression example · g1 soundness grid and sample
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_g1_soundness_grid_and_sample() -> None:
spec = TMNeuronSpec(order=1, activation="sigmoid")
tm = tm_dense(input_tm(0.0, 0.2, spec.order), 1.0, 0.0, spec)
assert contains_grid_and_sample(tm, "sigmoid", 0.0, 0.2)python -m pytest packages/omnibias-core/tests/verified/test_tm_neuron.py -k test_g1_soundness_grid_and_sample -qRead the implementation
def tm_dense(
tm_in: TaylorModel,
weight: float,
bias: float,
spec: TMNeuronSpec | None = None,
) -> TaylorModel:
"""Affine ``w * x + b`` then TM-sigma. Pure Python; no torch / jax."""
cfg = DEFAULT_SPEC if spec is None else spec
pre = tm_in * Interval.point(weight) + Interval.point(bias)
return compose_sigma_tm(pre, cfg.activation, cfg.order)worked_example
omnibias.core.verified.tm_neuron.worked_exampleSource ↗worked_example() -> dict[str, float | bool]Order-1 sigmoid TM on [0, 0.2] about 0.1.
dict[str, float | bool]Executed regression · g2 non vacuous
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_g2_non_vacuous() -> None:
ex = worked_example()
assert float(ex["remainder_width"]) < 0.1
assert ex["vacuous"] is False
assert float(ex["width"]) < 0.1python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -qRead the implementation
def worked_example() -> dict[str, float | bool]:
"""Order-1 sigmoid TM on ``[0, 0.2]`` about ``0.1``."""
spec = TMNeuronSpec(order=1, activation="sigmoid")
tm = tm_dense(input_tm(0.0, 0.2, spec.order), 1.0, 0.0, spec)
box = tm.bound()
return {
"lo": box.lo,
"hi": box.hi,
"width": box.width,
"remainder_width": tm.remainder.width,
"vacuous": box.width >= 1e6,
}