omnibias.core.verified.enclosure_collapse
Coefficient recurrences, activation contracts, jet algebra, and verified arithmetic shared by the numerical backends.
import omnibias.core.verified.enclosure_collapseModule contract & mathematical conventions
Enclosure Collapse algebra and the Width Law (theory 01-14).
The founding bias collapse (delta -> 0) yields a smooth
sigma^(K-1). Temperature collapse (beta -> inf, feasibility)
yields a 0/1 step. Enclosure Collapse is the third limit:
width -> 0 of a *sound enclosure*. The output is a point plus a proof,
not a derivative and not a 0/1 step. Do not conflate the three.
There is no operator Collapse([lo, hi]) -> point. Identifying
endpoints (lo := hi) is unsound and is not an API.
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 module | Canonical reference |
|---|---|
WidthBudget | omnibias.core.verified.enclosure_collapse.WidthBudget |
CRITICAL_POINT_FACTOR
omnibias.core.verified.enclosure_collapse.CRITICAL_POINT_FACTORSource ↗CRITICAL_POINT_FACTOR = 1This 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 · g1 width law critical point factor
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_width_law_critical_point_factor(activation: str, n: int, center: float) -> None:
law = width_law(activation, n, center, kind="critical_point")
assert law.exponent == 2
assert CRITICAL_POINT_FACTOR == 1
r = 1e-3
enc = measured_critical_width(activation, n, center, r)
ratio = enc.width / (r**2)
assert abs(ratio - law.predicted_leading.mid) / max(law.predicted_leading.mid, 1e-12) < 0.25python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_critical_point_factor -qRead the implementation
CRITICAL_POINT_FACTOR = 1MEAN_VALUE_FACTOR
omnibias.core.verified.enclosure_collapse.MEAN_VALUE_FACTORSource ↗MEAN_VALUE_FACTOR = 2This 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 · g1 width law mean value limit
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_width_law_mean_value_limit(activation: str, n: int, center: float) -> None:
law = width_law(activation, n, center, kind="mean_value")
assert law.exponent == 1
assert law.kind == "mean_value"
errors: list[float] = []
for r in (1e-2, 1e-3, 1e-4):
enc = measured_mean_value_width(activation, n, center, r)
ratio = enc.width / (MEAN_VALUE_FACTOR * r)
errors.append(abs(ratio - law.predicted_leading.mid))
pred = predicted_width(law, r)
assert pred.lo >= 0.0
assert errors[-1] < 5e-3
assert errors[-1] <= errors[0]python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_mean_value_limit -qRead the implementation
MEAN_VALUE_FACTOR = 2RecommendedAction
omnibias.core.verified.RecommendedActionSource ↗class RecommendedActionDataclass 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.
What to do when a named WidthBudget piece dominates.
Parameters
| Name | Type & default | Contract |
|---|---|---|
dominantdataclass field | DominantNameRequired | See the operation contract and implementation below. |
actiondataclass field | ActionNameRequired | See the operation contract and implementation below. |
reasondataclass field | strRequired | See the operation contract and implementation below. |
Executed regression · diagnose width maps each dominant
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_diagnose_width_maps_each_dominant() -> None:
expected = {
"truncation": "raise_order",
"wrapping": "subdivide",
"jacobian": "shrink_step",
"rounding": "stop_floor",
}
for dominant, action in expected.items():
parts = {"truncation": 0.0, "jacobian": 0.0, "wrapping": 0.0, "rounding": 0.0}
parts[dominant] = 1.0
rec = diagnose_width(WidthBudget(**parts))
assert isinstance(rec, RecommendedAction)
assert rec.dominant == dominant
assert rec.action == action
payload = rec.to_payload()
assert payload["dominant"] == dominant
assert payload["action"] == action
assert payload["reason"]python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_diagnose_width_maps_each_dominant" -qFields & methods
dominantfield
dominant: DominantNameDeclared DominantName field on RecommendedAction. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗actionfield
action: ActionNameDeclared ActionName field on RecommendedAction. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗reasonfield
reason: strDeclared str field on RecommendedAction. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗to_payloadmethod
to_payload(self) -> dict[str, str]See the class contract above and the exact method implementation below.
Returns: dict[str, str]
Executed regression · diagnose width maps each dominant
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_diagnose_width_maps_each_dominant() -> None:
expected = {
"truncation": "raise_order",
"wrapping": "subdivide",
"jacobian": "shrink_step",
"rounding": "stop_floor",
}
for dominant, action in expected.items():
parts = {"truncation": 0.0, "jacobian": 0.0, "wrapping": 0.0, "rounding": 0.0}
parts[dominant] = 1.0
rec = diagnose_width(WidthBudget(**parts))
assert isinstance(rec, RecommendedAction)
assert rec.dominant == dominant
assert rec.action == action
payload = rec.to_payload()
assert payload["dominant"] == dominant
assert payload["action"] == action
assert payload["reason"]python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_diagnose_width_maps_each_dominant" -qMethod implementation
def to_payload(self) -> dict[str, str]:
return {
"dominant": self.dominant,
"action": self.action,
"reason": self.reason,
}Read the implementation
class RecommendedAction:
"""What to do when a named ``WidthBudget`` piece dominates."""
dominant: DominantName
action: ActionName
reason: str
def to_payload(self) -> dict[str, str]:
return {
"dominant": self.dominant,
"action": self.action,
"reason": self.reason,
}Other public import paths
omnibias.core.verified.RecommendedActionomnibias.core.verified.enclosure_collapse.RecommendedAction
WidthLaw
omnibias.core.verified.WidthLawSource ↗class WidthLawDataclass 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.
Closed-form leading coefficient of enclosure width.
Parameters
| Name | Type & default | Contract |
|---|---|---|
centerdataclass field | floatRequired | See the operation contract and implementation below. |
orderdataclass field | intRequired | See the operation contract and implementation below. |
predicted_leadingdataclass field | IntervalRequired | See the operation contract and implementation below. |
exponentdataclass field | intRequired | See the operation contract and implementation below. |
activationdataclass field | strRequired | See the operation contract and implementation below. |
kinddataclass field | WidthLawKindRequired | See the operation contract and implementation below. |
Fields & methods
centerfield
center: floatDeclared float field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗orderfield
order: intDeclared int field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗predicted_leadingfield
predicted_leading: IntervalDeclared Interval field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗exponentfield
exponent: intDeclared int field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗activationfield
activation: strDeclared str field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗kindfield
kind: WidthLawKindDeclared WidthLawKind field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
View source ↗Read the implementation
class WidthLaw:
"""Closed-form leading coefficient of enclosure width."""
center: float
order: int
predicted_leading: Interval
exponent: int
activation: str
kind: WidthLawKindOther public import paths
omnibias.core.verified.WidthLawomnibias.core.verified.enclosure_collapse.WidthLaw
diagnose_width
omnibias.core.verified.diagnose_widthSource ↗diagnose_width(budget: WidthBudget) -> RecommendedActionRecommend an action from an existing WidthBudget. Does not fork the type.
Parameters
| Name | Type & default | Contract |
|---|---|---|
budgetpositional-or-keyword | WidthBudgetRequired | See the operation contract and implementation below. |
RecommendedActionExecuted regression · diagnose width maps each dominant
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_diagnose_width_maps_each_dominant() -> None:
expected = {
"truncation": "raise_order",
"wrapping": "subdivide",
"jacobian": "shrink_step",
"rounding": "stop_floor",
}
for dominant, action in expected.items():
parts = {"truncation": 0.0, "jacobian": 0.0, "wrapping": 0.0, "rounding": 0.0}
parts[dominant] = 1.0
rec = diagnose_width(WidthBudget(**parts))
assert isinstance(rec, RecommendedAction)
assert rec.dominant == dominant
assert rec.action == action
payload = rec.to_payload()
assert payload["dominant"] == dominant
assert payload["action"] == action
assert payload["reason"]python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_diagnose_width_maps_each_dominant" -qRead the implementation
def diagnose_width(budget: WidthBudget) -> RecommendedAction:
"""Recommend an action from an existing ``WidthBudget``. Does not fork the type."""
match budget.dominant:
case "truncation" | "jacobian" | "wrapping" | "rounding" as name:
return RecommendedAction(name, _ACTIONS[name], _REASONS[name])
case other:
raise ValueError(f"unknown WidthBudget dominant {other!r}")Other public import paths
omnibias.core.verified.diagnose_widthomnibias.core.verified.enclosure_collapse.diagnose_width
honesty_payload
omnibias.core.verified.enclosure_collapse.honesty_payloadSource ↗honesty_payload() -> dict[str, object]The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.
dict[str, object]Executed regression · honesty names three limits
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_names_three_limits() -> None:
payload = honesty_payload()
assert payload["founding_bias_collapse"] is True
assert payload["temperature_collapse"] is False
assert payload["enclosure_collapse"] is True
assert payload["width_to_zero"] is True
assert payload["not_a_derivative"] is True
assert payload["not_a_01_step"] is True
assert payload["theorem_prover_verified"] is Falsepython -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_honesty_names_three_limits" -qRead the implementation
def honesty_payload() -> dict[str, object]:
return {
"founding_bias_collapse": True,
"temperature_collapse": False,
"enclosure_collapse": True,
"width_to_zero": True,
"not_a_derivative": True,
"not_a_01_step": True,
"theorem_prover_verified": False,
"mathlib_verified": False,
}measured_critical_width
omnibias.core.verified.measured_critical_widthSource ↗measured_critical_width(activation: str, n: int, center: float, r: float) -> IntervalSecond-order form f(c) + f''(I)·(I-c)^2 (factor locked to 1).
Parameters
| Name | Type & default | Contract |
|---|---|---|
activationpositional-or-keyword | strRequired | See the operation contract and implementation below. |
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
centerpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
rpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
IntervalExplicit validation & failure cases
- When
n < 0, raisesValueError('n must be >= 0').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · g1 width law critical point factor
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_width_law_critical_point_factor(activation: str, n: int, center: float) -> None:
law = width_law(activation, n, center, kind="critical_point")
assert law.exponent == 2
assert CRITICAL_POINT_FACTOR == 1
r = 1e-3
enc = measured_critical_width(activation, n, center, r)
ratio = enc.width / (r**2)
assert abs(ratio - law.predicted_leading.mid) / max(law.predicted_leading.mid, 1e-12) < 0.25python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g1_width_law_critical_point_factor[sigmoid-1-0.0]" -qRead the implementation
def measured_critical_width(activation: str, n: int, center: float, r: float) -> Interval:
"""Second-order form ``f(c) + f''(I)·(I-c)^2`` (factor locked to 1)."""
if n < 0:
raise ValueError("n must be >= 0")
c, box = _box(center, r)
f_c = sigma_tower_interval(activation, c, n)[n]
f_pp = sigma_tower_interval(activation, box, n + 2)[n + 2]
return f_c + f_pp * (box - c) ** 2Other public import paths
omnibias.core.verified.measured_critical_widthomnibias.core.verified.enclosure_collapse.measured_critical_width
measured_mean_value_width
omnibias.core.verified.measured_mean_value_widthSource ↗measured_mean_value_width(activation: str, n: int, center: float, r: float) -> IntervalMean-value enclosure f(c) + f'(I)·(I-c) of sigma^(n) on I(r).
Parameters
| Name | Type & default | Contract |
|---|---|---|
activationpositional-or-keyword | strRequired | See the operation contract and implementation below. |
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
centerpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
rpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
IntervalExplicit validation & failure cases
- When
n < 0, raisesValueError('n must be >= 0').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · mean value rejects nonpositive radius
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_mean_value_rejects_nonpositive_radius() -> None:
with pytest.raises(ValueError, match="positive"):
measured_mean_value_width("sigmoid", 0, 0.0, 0.0)python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_mean_value_rejects_nonpositive_radius" -qRegression example · g1 width law critical point factor
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_width_law_critical_point_factor(activation: str, n: int, center: float) -> None:
law = width_law(activation, n, center, kind="critical_point")
assert law.exponent == 2
assert CRITICAL_POINT_FACTOR == 1
r = 1e-3
enc = measured_critical_width(activation, n, center, r)
ratio = enc.width / (r**2)
assert abs(ratio - law.predicted_leading.mid) / max(law.predicted_leading.mid, 1e-12) < 0.25python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_critical_point_factor -qRead the implementation
def measured_mean_value_width(activation: str, n: int, center: float, r: float) -> Interval:
"""Mean-value enclosure ``f(c) + f'(I)·(I-c)`` of ``sigma^(n)`` on ``I(r)``."""
if n < 0:
raise ValueError("n must be >= 0")
c, box = _box(center, r)
f_c = sigma_tower_interval(activation, c, n)[n]
f_prime = sigma_tower_interval(activation, box, n + 1)[n + 1]
return f_c + f_prime * (box - c)Other public import paths
omnibias.core.verified.measured_mean_value_widthomnibias.core.verified.enclosure_collapse.measured_mean_value_width
measured_taylor_remainder
omnibias.core.verified.measured_taylor_remainderSource ↗measured_taylor_remainder(activation: str, n: int, center: float, r: float, order: int) -> IntervalLagrange remainder enclosure of sigma^(n) after order N.
Parameters
| Name | Type & default | Contract |
|---|---|---|
activationpositional-or-keyword | strRequired | See the operation contract and implementation below. |
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
centerpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
rpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
orderpositional-or-keyword | intRequired | See the operation contract and implementation below. |
IntervalExplicit validation & failure cases
- When
n < 0 or order < 0, raisesValueError('n and order must be >= 0').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · g1 width law taylor remainder
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_width_law_taylor_remainder() -> None:
activation, n, center, order = "sigmoid", 0, 0.3, 2
law = width_law(activation, n, center, kind="taylor_remainder", order=order)
assert law.exponent == order + 1
r = 5e-3
rem = measured_taylor_remainder(activation, n, center, r, order)
pred = predicted_width(law, r)
assert rem.width > 0.0
assert pred.contains(rem.width) or abs(rem.width - pred.mid) / max(pred.mid, 1e-18) < 0.5python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g1_width_law_taylor_remainder" -qRead the implementation
def measured_taylor_remainder(activation: str, n: int, center: float, r: float, order: int) -> Interval:
"""Lagrange remainder enclosure of ``sigma^(n)`` after order ``N``."""
if n < 0 or order < 0:
raise ValueError("n and order must be >= 0")
_c, box = _box(center, r)
deriv = sigma_tower_interval(activation, box, n + order + 1)[n + order + 1]
return deriv * (box - Interval.point(float(center))) ** (order + 1) / float(_factorial(order + 1))Other public import paths
omnibias.core.verified.measured_taylor_remainderomnibias.core.verified.enclosure_collapse.measured_taylor_remainder
predicted_width
omnibias.core.verified.predicted_widthSource ↗predicted_width(law: WidthLaw, r: float) -> IntervalEnclosure of the predicted width C * r^exponent (with locked factors).
Parameters
| Name | Type & default | Contract |
|---|---|---|
lawpositional-or-keyword | WidthLawRequired | See the operation contract and implementation below. |
rpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
IntervalExecuted regression · g1 width law taylor remainder
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_width_law_taylor_remainder() -> None:
activation, n, center, order = "sigmoid", 0, 0.3, 2
law = width_law(activation, n, center, kind="taylor_remainder", order=order)
assert law.exponent == order + 1
r = 5e-3
rem = measured_taylor_remainder(activation, n, center, r, order)
pred = predicted_width(law, r)
assert rem.width > 0.0
assert pred.contains(rem.width) or abs(rem.width - pred.mid) / max(pred.mid, 1e-18) < 0.5python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g1_width_law_taylor_remainder" -qRegression example · g1 width law mean value limit
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_width_law_mean_value_limit(activation: str, n: int, center: float) -> None:
law = width_law(activation, n, center, kind="mean_value")
assert law.exponent == 1
assert law.kind == "mean_value"
errors: list[float] = []
for r in (1e-2, 1e-3, 1e-4):
enc = measured_mean_value_width(activation, n, center, r)
ratio = enc.width / (MEAN_VALUE_FACTOR * r)
errors.append(abs(ratio - law.predicted_leading.mid))
pred = predicted_width(law, r)
assert pred.lo >= 0.0
assert errors[-1] < 5e-3
assert errors[-1] <= errors[0]python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_mean_value_limit -qRead the implementation
def predicted_width(law: WidthLaw, r: float) -> Interval:
"""Enclosure of the predicted width ``C * r^exponent`` (with locked factors)."""
radius = _require_radius(r)
scale = Interval.point(radius) ** law.exponent
if law.kind == "mean_value":
return law.predicted_leading * scale * MEAN_VALUE_FACTOR
if law.kind == "critical_point":
return law.predicted_leading * scale * CRITICAL_POINT_FACTOR
factor = 2 if law.exponent % 2 == 1 else 1
return law.predicted_leading * scale * factorOther public import paths
omnibias.core.verified.predicted_widthomnibias.core.verified.enclosure_collapse.predicted_width
rounding_floor_witness
omnibias.core.verified.rounding_floor_witnessSource ↗rounding_floor_witness() -> IntervalLemma Floor: a non-exact evaluation whose width is at least 2 ulp.
IntervalExecuted regression · g2 lemma floor two ulp
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_lemma_floor_two_ulp() -> None:
witness = rounding_floor_witness()
assert witness.width >= two_ulp(0.0)
mid = witness.mid
assert witness.contains(1.0 / 3.0) or abs(mid - 1.0 / 3.0) <= witness.width
assert witness.lo < witness.hipython -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g2_lemma_floor_two_ulp" -qRead the implementation
def rounding_floor_witness() -> Interval:
"""Lemma Floor: a non-exact evaluation whose width is at least ``2 ulp``."""
return Interval.point(1.0) / 3.0Other public import paths
omnibias.core.verified.rounding_floor_witnessomnibias.core.verified.enclosure_collapse.rounding_floor_witness
two_ulp
omnibias.core.verified.enclosure_collapse.two_ulpSource ↗two_ulp(x: float) -> floatTwo outward steps from x in the +inf direction.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
floatExecuted regression · g2 lemma floor two ulp
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_lemma_floor_two_ulp() -> None:
witness = rounding_floor_witness()
assert witness.width >= two_ulp(0.0)
mid = witness.mid
assert witness.contains(1.0 / 3.0) or abs(mid - 1.0 / 3.0) <= witness.width
assert witness.lo < witness.hipython -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g2_lemma_floor_two_ulp" -qRead the implementation
def two_ulp(x: float) -> float:
"""Two outward steps from ``x`` in the ``+inf`` direction."""
return math.nextafter(math.nextafter(float(x), math.inf), math.inf)width_law
omnibias.core.verified.width_lawSource ↗width_law(activation: str, n: int, center: float, *, kind: WidthLawKind='mean_value', order: int | None=None) -> WidthLawLeading coefficient of w(r) from the closed-form tower.
n is the order of f = sigma^(n). Mean-value uses
|f'(c)| = |sigma^(n+1)(c)| with exponent 1. Critical-point uses
|f''(c)| with exponent 2 and factor CRITICAL_POINT_FACTOR.
Taylor remainder of order N uses |f^{(N+1)}(c)| / (N+1)!.
Parameters
| Name | Type & default | Contract |
|---|---|---|
activationpositional-or-keyword | strRequired | See the operation contract and implementation below. |
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
centerpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
kindkeyword-only | WidthLawKindDefault: 'mean_value' | See the operation contract and implementation below. |
orderkeyword-only | int | NoneDefault: None | See the operation contract and implementation below. |
WidthLawExplicit validation & failure cases
- When
n < 0, raisesValueError('n must be >= 0'). - When
not first[n + 1].contains_zero() and abs(first[n + 1].mid) > 1e-09, raisesValueError("critical_point requires f'(c) near 0"). - When
n_order < 0, raisesValueError('Taylor order N must be >= 0').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · g1 width law critical point factor
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_width_law_critical_point_factor(activation: str, n: int, center: float) -> None:
law = width_law(activation, n, center, kind="critical_point")
assert law.exponent == 2
assert CRITICAL_POINT_FACTOR == 1
r = 1e-3
enc = measured_critical_width(activation, n, center, r)
ratio = enc.width / (r**2)
assert abs(ratio - law.predicted_leading.mid) / max(law.predicted_leading.mid, 1e-12) < 0.25python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g1_width_law_critical_point_factor[sigmoid-1-0.0]" -qRegression example · g1 width law taylor remainder
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_width_law_taylor_remainder() -> None:
activation, n, center, order = "sigmoid", 0, 0.3, 2
law = width_law(activation, n, center, kind="taylor_remainder", order=order)
assert law.exponent == order + 1
r = 5e-3
rem = measured_taylor_remainder(activation, n, center, r, order)
pred = predicted_width(law, r)
assert rem.width > 0.0
assert pred.contains(rem.width) or abs(rem.width - pred.mid) / max(pred.mid, 1e-18) < 0.5python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_taylor_remainder -qRead the implementation
def width_law(
activation: str,
n: int,
center: float,
*,
kind: WidthLawKind = "mean_value",
order: int | None = None,
) -> WidthLaw:
"""Leading coefficient of ``w(r)`` from the closed-form tower.
``n`` is the order of ``f = sigma^(n)``. Mean-value uses
``|f'(c)| = |sigma^(n+1)(c)|`` with exponent 1. Critical-point uses
``|f''(c)|`` with exponent 2 and factor ``CRITICAL_POINT_FACTOR``.
Taylor remainder of order ``N`` uses ``|f^{(N+1)}(c)| / (N+1)!``.
"""
if n < 0:
raise ValueError("n must be >= 0")
name = str(activation)
if kind == "mean_value":
leading = _abs_at_center(name, center, n + 1)
return WidthLaw(float(center), 0, leading, 1, name, kind)
if kind == "critical_point":
first = sigma_tower_interval(name, Interval.point(float(center)), n + 2)
if not first[n + 1].contains_zero() and abs(first[n + 1].mid) > 1e-9:
raise ValueError("critical_point requires f'(c) near 0")
leading = first[n + 2].abs()
return WidthLaw(float(center), 1, leading, 2, name, kind)
if kind == "taylor_remainder":
n_order = 2 if order is None else int(order)
if n_order < 0:
raise ValueError("Taylor order N must be >= 0")
deriv_order = n + n_order + 1
leading = _abs_at_center(name, center, deriv_order) / float(_factorial(n_order + 1))
return WidthLaw(float(center), n_order, leading, n_order + 1, name, kind)
raise ValueError(f"unknown WidthLaw kind {kind!r}")Other public import paths
omnibias.core.verified.width_lawomnibias.core.verified.enclosure_collapse.width_law