Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@
A second correctness review: every fix below was reproduced against a
brute-force reference or a closed-form value and has a regression test.

### Truncated bidirectional machines

- `generative_model` no longer reports lower bounds of a truncation as bounds on the process. When the reverse
ε-machine is infinite but its mixed states merge within numerical tolerance, the bidirectional machine is a finite
truncation (`bidir_class` `"truncated"`). Its generators are verified against the forward machine, so the upper
bound holds, but the excess entropy, the support-type, flow and coverage bounds, SCIP's dual bound on the exact
path, the heaviest-term bounds and the restricted global bound were computed on the truncation, and their sources
read "(certified)": on a 2-state ternary process the generator coverage bound of the truncation came within
`1.5e-6` of the best generator's entropy, 0.9982954, where the future-window bound is 0.9981857. These stages are
now skipped, as is the share of the budget held back for the final heaviest-term bound. The lower bound is the
larger future-window generator coverage bound at `L = 2` and 3 (`window_spec`, Löhr & Ay 2009), computed first
from the forward machine with at most 30% of the budget. `minimal_wyner_model` reports `lower` 0 on a truncated build.
- `resolve_bidirectional` classes a bidirectional input `"truncated"` when the reverse ε-machine of its forward
machine is infinite (was: always `"finite"`), as the build does.
- The simplex-chain search treats a Gauss-Newton step whose SVD does not converge (`numpy.linalg.LinAlgError`) as a
failed snap; on a binary 3-state process the error ended `generative_model` after 116 s.
- The simplex-chain search checks its deadline inside an atom step. The reverse side of a truncated build can have
~100 states, and one wall tangent there (a finite-difference Jacobian over every atom coordinate) took minutes: with
the truncation's lower bounds skipped the search ran, and `generative_model` on a 2-state ternary process with 90
reverse states was still running at 1,020 s on a 300 s budget. On a 53-state reverse side a 2 s search took 95 s.
- `bilevel_search` checks its deadline at every evaluation of its objective, keeping the best channel scored, where
Powell's callback checked it once an iteration. An iteration line-searches every logit of the channel, and on a
truncated build with 69 reverse states the search ran 163 s past its share (`generative_model` took 392 s on a
300 s budget, 491 s on `main`).

### Coverage bound: least entropy under the caps

- `coverage_entropy_lower(caps)`, the last step of `coverage_bound`, `generator_coverage_bound` and the pipeline's
Expand Down
13 changes: 13 additions & 0 deletions docs/generators/generative_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ feeds them to :func:`~sofic.generators.generator_caps.generator_coverage_bound`
on :math:`C_g` from the forward ε-machine alone. On the :math:`(2, \infty)` process a
two-symbol window already gives :math:`C_g \ge 3/2`.

Some processes with infinite reverse ε-machines still build a bidirectional machine: the reverse
mixed states merge within numerical tolerance, and the build is a finite truncation (``bidir_class``
``"truncated"``; a bidirectional machine passed in is classed the same way). The generators found on it
are verified against the forward machine's words, so the upper bound holds for the process, but the excess
entropy, the support-type, flow and coverage bounds, SCIP's dual bound on the exact path, the heaviest-term
bounds and the restricted global bound would bound the truncation, not the process.
:func:`~sofic.generators.generative_search.generative_model` therefore skips them, and keeps no budget for
the final heaviest-term bound. Its lower bound is the larger future-window generator coverage bound at
:math:`L = 2` and 3 (1,000 and 2,000 boxes for the two explicit caps at :math:`L = 2`, 300 and 600 at
:math:`L = 3`), computed first, with at most 30% of the time budget :cite:`LohrAy2009`.
:func:`~sofic.generators.generative_search.minimal_wyner_model` reports ``lower`` 0 on a truncated build.
Machines whose bidirectional build fails still raise.

Supports without 2 × 2 rectangles
---------------------------------

Expand Down
25 changes: 15 additions & 10 deletions sofic/generators/coupled_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,36 +729,41 @@ def bilevel_search(
"""Outer search over channels ``c[pair, w]`` scoring ``H[W] + weight * t(c)``, where ``t`` is the
linear-programming violation of :func:`generator_kernel`, from the given starting channels (derivative-free;
small problems). Returns ``(entropy, violation, channel)`` per start, best feasible first. Past
``deadline`` (a :func:`time.monotonic` value) the current start stops and no new one begins.
``deadline`` (a :func:`time.monotonic` value) the current start stops, keeping the best channel it has
scored, and no new one begins.
"""
problem = _GeneratorProblem(bidir)
n = len(problem.lifted.p)
out = []
for c0 in starts:
k = c0.shape[1]
best: dict[str, Any] = {"score": np.inf, "z": None}

def channel(z: np.ndarray, k: int = k) -> np.ndarray:
z = z.reshape(n, k)
z = np.exp(z - z.max(axis=1, keepdims=True))
return z / z.sum(axis=1, keepdims=True)

def score(z: np.ndarray, channel=channel) -> float:
# checked per evaluation: one Powell iteration line-searches every logit, minutes on a large problem
def score(z: np.ndarray, channel=channel, best=best) -> float:
if deadline is not None and time.monotonic() > deadline:
raise _DeadlineReachedError
c = channel(z)
pi = problem.lifted.p @ c
p = pi[pi > 1e-15]
return float(-(p * np.log2(p)).sum()) + weight * generator_kernel(problem, c)[0]
value = float(-(p * np.log2(p)).sum()) + weight * generator_kernel(problem, c)[0]
if value < best["score"]:
best.update(score=value, z=z.copy())
return value

if deadline is not None and out and time.monotonic() > deadline:
break

def stop(intermediate_result: Any) -> None:
if deadline is not None and time.monotonic() > deadline:
raise StopIteration

z0 = np.log(np.maximum(c0, 1e-6)).ravel()
z = minimize(
score, z0, method="Powell", callback=stop, options={"maxiter": maxiter, "xtol": 1e-6, "ftol": 1e-10}
).x
try:
z = minimize(score, z0, method="Powell", options={"maxiter": maxiter, "xtol": 1e-6, "ftol": 1e-10}).x
except _DeadlineReachedError:
z = z0 if best["z"] is None else best["z"]
c = channel(z)
pi = problem.lifted.p @ c
p = pi[pi > 1e-15]
Expand Down
Loading
Loading