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
30 changes: 20 additions & 10 deletions docs/generators/generative_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ runs the same search when the bidirectional machine is already known.
:func:`~sofic.generators.coverage_bound.mu_hyperplane_cap` (branch and bound over the plane
containing the columns of a rank-2 matrix; exact since nonnegative rank two equals rank two
:cite:`cohen1993nonnegative`);
* the persistent-crypticity criteria; when both vanish every separating variable
is a generator state and :math:`C_g = \op{G}{S^+ : S^-}`;
* the persistent-crypticity criteria, with the cryptic orders and the block persistent crypticities; when both
criteria vanish (cryptic order at most 1) every separating variable is a generator state,
:math:`C_g = \op{G}{S^+ : S^-}`, and the exact path computes it with at most :math:`K(P)` states
(:doc:`separating_generators`); at cryptic orders 2 and 3 the lookahead generator is a candidate;
* the exact-common-information optima (dit, several starts, since the optimum
need not be unique and only some optima generate), each polished to exact
separation with :func:`~sofic.generators.coupled_generators.polish_separating_channel`
Expand Down Expand Up @@ -389,8 +391,9 @@ assignments on each connected component of the support and also reports the leas
most ``k`` blocks. Kumar, Li & El Gamal :cite:`Kumar2014` show that some optimal separating
variable has at most :math:`|S^+||S^-|` values (and at most :math:`2^{\min(|S^+|, |S^-|)} - 1`);
their argument restricted to the support gives at most the number of support cells, which caps the
number of terms :func:`~sofic.generators.coupled_generators.separating_optima` tries. The partition
solver is not from the literature.
number of terms :func:`~sofic.generators.coupled_generators.separating_optima` tries, and merges and
null moves bring any decomposition down to :math:`K(P) = \lfloor (|\mathrm{supp}\, P| + \min(|S^+|, |S^-|)) / 2
\rfloor` terms (:doc:`separating_generators`). The partition solver is not from the literature.

The skip-one chain shows that a minimal generator can need more than
:math:`\min(|S^+|, |S^-|) + 1` states. It is the first-order Markov chain on :math:`\mathbb{Z}_6`
Expand All @@ -417,9 +420,12 @@ generator with at most ``k`` states and says nothing about larger ones. It is th
bound on :math:`C_g` only once the number of states of a minimal generator is bounded. No general
bound is known, and :math:`\min(|S^+|, |S^-|) + 1` is not one: the skip-one chain (under
`Supports without 2 × 2 rectangles`_) needs :math:`|S^+| + 2` states. When both persistent
crypticities vanish, ``k`` equal to the number of cells in the support of the causal-state joint
suffices. It is also numerical, not a certificate: the equations with data on the right-hand side are relaxed by ``data_tol``, and SCIP
works to its own tolerances. SCIP's solution satisfies necessary conditions only;
crypticities vanish (cryptic order at most 1), ``k`` equal to :math:`K(P)` suffices
(:doc:`separating_generators`). It is also numerical, not a certificate: the equations with data on the right-hand side are relaxed by ``data_tol``, and SCIP
works to its own tolerances, and its presolve and optimization-based bound tightening can go wrong
(``presolve=False, obbt=False`` gives a second opinion; see :doc:`separating_generators`).
:func:`~sofic.generators.global_bound.separating_global_bound` is the static version, over separating
decompositions with ``k`` terms. SCIP's solution satisfies necessary conditions only;
:func:`~sofic.generators.hmm_search.hmm_generator_search` with ``initial`` polishes it into a
generator. On the binary process with symbol matrices
:math:`T^{(0)} = \begin{pmatrix} p & 0 \\ q & 0 \end{pmatrix}` and
Expand All @@ -429,11 +435,13 @@ generator. On the binary process with symbol matrices
generator with at most 3 states does :math:`10^{-4}` bits better.

The pipeline runs it with ``global_bound=True``, after the belief-free search, for
``global_bound_states`` states (default :math:`\min(|S^+|, |S^-|) + 1`, a convention, not a bound).
``global_bound_states`` states (default :math:`K(P)`, lowered until the model has at most 2,000 SCIP
variables; a bound on the states of a minimal generator only at cryptic order at most 1).
It gets half the remaining
budget (120 s without a budget) and the best candidate's entropy as its objective limit, and it is
skipped above 2,000 SCIP variables. The value goes to ``restricted_lower`` and ``restricted_states``,
not to ``lower``, so ``certified`` is unchanged; the polished solution is offered as a candidate. The
skipped above 2,000 SCIP variables. The value goes to ``restricted_lower`` and ``restricted_states``.
It enters ``lower`` (as a numerical bound) only at cryptic order at most 1 with :math:`K(P)` states;
otherwise ``certified`` is unchanged. The polished solution is offered as a candidate. The
two-step flows and this restricted use are not from the literature.

API
Expand Down Expand Up @@ -461,6 +469,8 @@ Coupled generators and bounds
.. autofunction:: sofic.generators.hmm_search.coupled_seed_from_hmm
.. autofunction:: sofic.generators.global_bound.generator_global_bound
.. autoclass:: sofic.generators.global_bound.GlobalBoundResult
.. autofunction:: sofic.generators.global_bound.separating_global_bound
.. autoclass:: sofic.generators.global_bound.SeparatingBoundResult
.. autoclass:: sofic.generators.generative_search.GenerativeModelResult
:members: certified, gap, g_optima_generate
.. autofunction:: sofic.generators.coverage_bound.coverage_entropy_lower
Expand Down
1 change: 1 addition & 0 deletions docs/generators/generators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Computational mechanics
predictive_rate_distortion
symbolic_hmm
generative_models
separating_generators
canonical_generators
directional_flow
alternative_complexity
Expand Down
137 changes: 137 additions & 0 deletions docs/generators/separating_generators.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
.. separating_generators.rst
.. py:module:: sofic.generators.separating_generators

**************************************
Cryptic Order and Exact Generators
**************************************

Every generator state separates the forward and reverse causal states, so
:math:`C_g \ge \op{G}{S^+ : S^-}` :cite:`LohrAy2009`, the exact common information :cite:`Kumar2014` of the
causal-state joint :math:`P`. :mod:`sofic.generators.separating_generators` computes :math:`C_g` exactly when the
cryptic order is at most 1, and bounds it above by lookahead generators when the cryptic order is larger
(:doc:`generative_models` describes the rest of the search).

Cryptic order at most 1
=======================

The persistent crypticity :math:`p.\chi^+ = \H{S^+_1 \mid S^-_0, X_0}` equals :math:`\H{S^+_1 \mid X_{0:}}`,
because the reverse causal state :math:`S^-_0` shields the future from the past. That is
:math:`\chi^+ - \H{S^+_0 \mid X_0, S^+_1}`, Theorem 1 of Mahoney, Ellison and Crutchfield :cite:`Mahoney2009` at
:math:`k = 1`, so :math:`p.\chi^+` vanishes exactly when the cryptic order :math:`\kappa^+` is at most 1. The
forward and reverse cryptic orders are equal, the cryptic-order counterpart of the time symmetry of the Markov
order :cite:`Ellison2011`. When :math:`\chi^+ = 0` the past depends on the future only through :math:`S^+`, so
:math:`S^-` is a relabeling of :math:`S^+` and :math:`\chi^- = 0`. For orders of at least 1, the two persistent
crypticities of each block process (below) vanish together, so :math:`\max(\kappa^+, 1) = \max(\kappa^-, 1)`. Both
persistent crypticities therefore vanish exactly when the cryptic order is at most 1, and then every separating
variable of :math:`P` is a generator state and :math:`C_g = \op{G}{S^+ : S^-}`.

:func:`theorem_generator` writes the generator down. For a separating decomposition
:math:`P = \sum_w \pi_w Q_w R_w^\top` let :math:`c(w \mid a, b) = \pi_w Q_w(a) R_w(b) / P(a, b)`, and let
:math:`\phi(b, x) = S^+_1` be the forward state after :math:`X_0 = x` from :math:`S^-_0 = b`, a function because
:math:`p.\chi^+ = 0`. The kernel

.. math::

K(x, v \mid w) = \sum_{b, b'} R_w(b) \Pr(X_0 = x, S^-_1 = b' \mid S^-_0 = b)\, c(v \mid \phi(b, x), b')

satisfies the coupled generator equations, and its word process is the source's.

The support bound
-----------------

A decomposition :math:`P = \sum_w A_w R_w^\top`, with row masses :math:`A_w = \pi_w Q_w` and column distributions
:math:`R_w`, has two moves that keep it exact and do not raise the entropy of the weights
(:func:`reduce_decomposition`). Two terms with proportional row masses or equal column factors merge. When the
column factors of the terms covering a row are linearly dependent, mass moves along the dependency until one of
those cells empties, at whichever end has less entropy (the entropy is concave along the move). At the end the
terms covering each row have independent column factors, and each row has at most one term supported on that row
alone, so at most

.. math::

K(P) = \left\lfloor \frac{|\mathrm{supp}\, P| + \min(|S^+|, |S^-|)}{2} \right\rfloor

terms remain (:func:`support_bound_states`; the moves run on the side with fewer rows or columns). Kumar, Li and
El Gamal :cite:`Kumar2014` bound the number of values by :math:`|S^+||S^-|` and :math:`2^{\min(|S^+|, |S^-|)} - 1`.
So at cryptic order at most 1 some minimal generator has at most :math:`K(P)` states.

Computing the exact common information
--------------------------------------

:func:`separating_decomposition` works on each connected component of the support. A component in one row or
column is a single term. A component without :math:`2 \times 2` rectangles is solved exactly by
:func:`~sofic.generators.generator_bounds.one_wide_exact_common_information`. Otherwise SCIP minimizes the entropy
over decompositions with the component's :math:`K` terms
(:func:`~sofic.generators.global_bound.separating_global_bound`). The components combine as
:math:`\H{C} + \sum_c \Pr(c)\, G_c`, since the component label :math:`C` is a common function of both sides.

SCIP needs a second opinion. On Kumar, Li and El Gamal's Example 2, the erasure joint
:math:`\begin{pmatrix} 0.05 & 0 & 0.45 \\ 0 & 0.05 & 0.45 \end{pmatrix}`, presolve declares the model with
:math:`k = 2` infeasible, though :math:`W = S^+` is feasible. On the :math:`3 \times 3` joint with five cells in
``tests/test_separating_generators.py``, optimization-based bound tightening (OBBT) at :math:`k = 3` cuts off the
optimum and SCIP reports "optimal" at :math:`1.447803`, above a feasible :math:`1.343763`. With presolve and OBBT
off (``presolve=False, obbt=False``) both come out right. Each component therefore runs both settings, an
"infeasible" counts as no bound (a decomposition with :math:`K` terms always exists), and the smaller dual bound is
the component's lower bound. SCIP's primal solutions satisfy the constraints only to about :math:`10^{-6}`, which
can put their entropy below the true optimum, so each is reduced, projected onto exact decompositions by least
squares on its support, and descended, alongside multistart descents; the best exact decomposition is kept.
Without PySCIPOpt the multistart descents alone give the upper bound and such components contribute 0 to the
lower bound.

In the pipeline
---------------

:func:`~sofic.generators.generative_search.generative_model` logs the cryptic orders and the block persistent
crypticities in its ``persistent criteria`` stage. When both persistent crypticities vanish it runs the
``exact path`` stage after the ε-machine candidates: :func:`separating_decomposition`, :func:`reduce_decomposition`
and :func:`theorem_generator`, offering the generator as a candidate. Its lower bound enters ``lower``. It is
labelled ``separating global bound (numerical)``, with ``lower_certified`` False, whenever SCIP solved a
component; the certified bounds that run later can replace it. The restricted global bound
(``global_bound=True``) defaults to :math:`K(P)` states, lowered to fit its variable cap, and at cryptic order at
most 1 with :math:`K(P)` states it enters ``lower`` too.

On the 510 processes of cryptic order at most 1 in a survey dataset of 808 two- and three-state ε-machines on two
and three symbols, the exact path reproduced every certified value to :math:`10^{-6}` bits, with at most
:math:`K(P)` states, generator residuals below :math:`3 \times 10^{-11}` and word-process errors below
:math:`2 \times 10^{-11}`. Of the 1,140 components, 970 were single rows or columns, 115 rectangle-free and 55 went
to SCIP, where the numerical lower bound came within :math:`10^{-5}` bits.

Block processes and lookahead generators
========================================

A generator whose state determines its next :math:`L - 1` symbols is the same thing as a generator of the
sliding-block process :math:`Y_t = X_{t:t+L}`. The forward causal states of :math:`Y_L` are pairs
:math:`(X_{t:t+L-1}, S^+_{t+L-1})`, and its persistent crypticity is :math:`\H{S^+_L \mid X_{0:}}`. That vanishes
exactly when :math:`L` reaches the cryptic order, which Mahoney et al. define as the least such :math:`L`
:cite:`Mahoney2011`. At :math:`L = \kappa` the construction above applies to :math:`Y_L`, and keeping the first
symbol of each emission gives a generator of the source, so

.. math::

C_g \le \H{X_{0:L-1}} + \sum_u \Pr(u)\, \op{G}{S^+_{L-1} : S^-_0 \mid X_{0:L-1} = u}.

:func:`lookahead_generator` builds :math:`Y_L`'s ε-machine, runs :func:`separating_decomposition` and
:func:`theorem_generator` on it, projects, and checks the word process against the source exactly. On the
:math:`(2, \infty)` process (``restricted_golden_mean(2)``, cryptic order 2) it gives :math:`3/2 = C_g` with 3
states. On the butterfly process (cryptic order 2) it gives :math:`3.1219`, with 9 states, above
:math:`C_g = C_\mu = \log_2 5 = 2.3219` (the support-type bound certifies the ε-machine): the construction can
lose to the ε-machine. On the survey dataset the lookahead value equals the certified :math:`C_g` on 32 of the 49
closed processes of cryptic order 2 and on none of the closed processes of cryptic order 3, whose minimal
generators do not determine their next two symbols. It takes at most about a second there, and the pipeline offers it as a
candidate at cryptic orders 2 and 3; with a 60 s budget it lowered the pipeline's upper bound on 4 of 81 such
processes and tied on 45.

The support bound, the reduction, the kernel of :func:`theorem_generator` and the lookahead construction are not
from the literature, and none of :cite:`Mahoney2009,Mahoney2011,Crutchfield2009,Ellison2011` states the equality
of the cryptic orders.

API
===

.. autofunction:: support_bound_states
.. autofunction:: reduce_decomposition
.. autofunction:: separating_decomposition
.. autoclass:: SeparatingDecomposition
.. autofunction:: theorem_generator
.. autofunction:: lookahead_generator
.. autoclass:: LookaheadGenerator
12 changes: 12 additions & 0 deletions docs/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ @article{Mahoney2011
eprint = {1108.1510},
}

@article{Mahoney2009,
author = {Mahoney, John R. and Ellison, Christopher J. and Crutchfield, James P.},
title = {Information Accessibility and Cryptic Processes},
journal = {Journal of Physics A: Mathematical and Theoretical},
volume = {42},
number = {36},
pages = {362002},
year = {2009},
doi = {10.1088/1751-8113/42/36/362002},
eprint = {0905.4787},
}

@article{James2013,
author = {James, Ryan G. and Burke, John R. and Crutchfield, James P.},
title = {Chaos Forgets and Remembers: Information Anatomy of Complex Processes},
Expand Down
25 changes: 24 additions & 1 deletion scripts/benchmark_generative_robustness.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from sofic.examples import golden_mean, golden_mean_bidirectional
from sofic.examples.epsilon_machines import from_symbol_matrices
from sofic.examples.processes import rip, stretched_gm
from sofic.generators.bidirectional_epsilon_machine import BidirectionalEpsilonMachine
from sofic.generators.generative_search import generative_model, generative_model_from_bidirectional

Expand All @@ -25,6 +26,23 @@ def _h(p: float) -> float:
return float(-(p * np.log2(p) + (1 - p) * np.log2(1 - p)))


def _entropy(p: list[float]) -> float:
p = np.asarray(p, dtype=float)
return float(-(p * np.log2(p)).sum())


def _kappa1_scip() -> object:
"""Cryptic order 1 with a full-support 2 x 2 causal-state joint: the exact path solves it with SCIP."""
return from_symbol_matrices(
(0, 1),
(0, 1),
{
0: np.array([[0.8620162340426342, 0.0], [0.26088622236842307, 0.0]]),
1: np.array([[0.0, 0.1379837659573659], [0.0, 0.7391137776315769]]),
},
)


def _rll() -> BidirectionalEpsilonMachine:
machine = from_symbol_matrices(
("A", "B", "C"),
Expand Down Expand Up @@ -107,8 +125,13 @@ def main() -> None:
cases = [
Case("golden_mean_forward", golden_mean(0.5), gm_target, True),
Case("golden_mean_bidir", golden_mean_bidirectional(0.5), gm_target, True),
Case("rll", _rll(), 1.5, False),
Case("rll", _rll(), 1.5, True),
Case("interleaved_0.1", _interleaved(0.1), 2 * _h(4 / 9), None),
# cryptic order at most 1: certified by the exact path (separating_generators)
Case("rip", rip(), _entropy([0.4, 0.2, 0.4]), True),
Case("stretched_gm_2", stretched_gm(2), 1.5, True),
Case("stretched_gm_3", stretched_gm(3), _entropy([0.4, 0.2, 0.2, 0.2]), True),
Case("kappa1_scip", _kappa1_scip(), 0.7970965391094695, True),
]

print(f"{'case':<22} {'time':>6} {'upper':>8} {'lower':>8} {'gap':>8} {'cert':>5} {'source':<40}")
Expand Down
Loading
Loading