Skip to main content

omnibias.core.verified.tm_neuron

0.5.0rc1Release candidatePython >=3.10Apache-2.0

Coefficient recurrences, activation contracts, jet algebra, and verified arithmetic shared by the numerical backends.

import omnibias.core.verified.tm_neuron
Module 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.

CONSTANT

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()
CONSTANT

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 DISCLAIMER
python -m pytest packages/omnibias-core/tests/verified/test_tm_neuron.py -k test_honesty -q
Read the implementation
DISCLAIMER = (
    "TM hidden state; sound remainder, not a deep-net certificate, not ImageNet"
)
CLASS

TMNeuronSpec​

omnibias.core.verified.tm_neuron.TMNeuronSpecSource ↗
class TMNeuronSpec

Dataclass 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

NameType & defaultContract
orderdataclass fieldintDefault: 1See the operation contract and implementation below.
activationdataclass fieldstrDefault: '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 -q

Fields & methods

orderfield
order: int = 1

Declared 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 -q
View source ↗
activationfield
activation: str = 'sigmoid'

Declared str field on TMNeuronSpec. Default expression: 'sigmoid'.

View source ↗
Read the implementation
class TMNeuronSpec:
    order: int = 1
    activation: str = "sigmoid"
FUNCTION

compose_sigma_tm​

omnibias.core.verified.tm_neuron.compose_sigma_tmSource ↗
compose_sigma_tm(tm: TaylorModel, name: str, order: int) -> TaylorModel

sigma of a 1-D TM: polynomial tower plus Lagrange remainder.

Parameters

NameType & defaultContract
tmpositional-or-keywordTaylorModelRequiredSee the operation contract and implementation below.
namepositional-or-keywordstrRequiredSee the operation contract and implementation below.
orderpositional-or-keywordintRequiredSee the operation contract and implementation below.
ReturnsTaylorModel
Explicit validation & failure cases
  • When order < 1, raises ValueError('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.1
python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -q
Read 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 result
FUNCTION

contains_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) -> bool

Core verified contract: enclosure holds a grid and a random sample.

Parameters

NameType & defaultContract
tmpositional-or-keywordTaylorModelRequiredSee the operation contract and implementation below.
fnpositional-or-keywordstrRequiredSee the operation contract and implementation below.
lopositional-or-keywordfloatRequiredSee the operation contract and implementation below.
hipositional-or-keywordfloatRequiredSee the operation contract and implementation below.
n_gridkeyword-onlyintDefault: 65See the operation contract and implementation below.
n_samplekeyword-onlyintDefault: 32See the operation contract and implementation below.
seedkeyword-onlyintDefault: 20260821See the operation contract and implementation below.
Returnsbool
Executed 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" -q
Read 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 True
FUNCTION

depth_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

NameType & defaultContract
layerskeyword-onlyintDefault: 6See the operation contract and implementation below.
Returnsdict[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 True
python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g3_depth_honesty_records_explosion" -q
Read 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,
    }
FUNCTION

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.

Returnsdict[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 DISCLAIMER
python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_honesty" -q
Read 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,
    }
FUNCTION

input_tm​

omnibias.core.verified.tm_neuron.input_tmSource ↗
input_tm(lo: float, hi: float, order: int) -> TaylorModel

Identity Taylor model on [lo, hi].

Parameters

NameType & defaultContract
lopositional-or-keywordfloatRequiredSee the operation contract and implementation below.
hipositional-or-keywordfloatRequiredSee the operation contract and implementation below.
orderpositional-or-keywordintRequiredSee the operation contract and implementation below.
ReturnsTaylorModel
Explicit validation & failure cases
  • When hi < lo, raises ValueError(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.1
python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -q
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 -q
Read 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)
FUNCTION

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) -> TaylorModel

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

Parameters

NameType & defaultContract
weightspositional-or-keywordSequence[float]RequiredSee the operation contract and implementation below.
biasespositional-or-keywordSequence[float]RequiredSee the operation contract and implementation below.
lokeyword-onlyfloatDefault: 0.0See the operation contract and implementation below.
hikeyword-onlyfloatDefault: 0.2See the operation contract and implementation below.
speckeyword-onlyTMNeuronSpec | NoneDefault: NoneSee the operation contract and implementation below.
ReturnsTaylorModel
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 True
python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g3_depth_honesty_records_explosion" -q
Read 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 tm
FUNCTION

source_imports_no_backend​

omnibias.core.verified.tm_neuron.source_imports_no_backendSource ↗
source_imports_no_backend(path: Path | None=None) -> bool

G4: the authored module must not import torch / jax / tensorflow / keras.

Parameters

NameType & defaultContract
pathpositional-or-keywordPath | NoneDefault: NoneSee the operation contract and implementation below.
Returnsbool
Executed 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" -q
Read 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 True
FUNCTION

tm_dense​

omnibias.core.verified.tm_neuron.tm_denseSource ↗
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.

Parameters

NameType & defaultContract
tm_inpositional-or-keywordTaylorModelRequiredSee the operation contract and implementation below.
weightpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
biaspositional-or-keywordfloatRequiredSee the operation contract and implementation below.
specpositional-or-keywordTMNeuronSpec | NoneDefault: NoneSee the operation contract and implementation below.
ReturnsTaylorModel
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.1
python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -q
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 -q
Read 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)
FUNCTION

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.

Returnsdict[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.1
python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -q
Read 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,
    }