mixle.experimental.wake_sleep module¶
P12 (experimental) – wake-sleep library learning over a model-structure grammar.
DreamCoder’s loop, in miniature, for mixle’s structure grammar:
WAKE – solve each modeling task by greedy search over a library of structure atoms (each atom is a group of basis components), scoring candidates by description length (MDL).
SLEEP-ABSTRACTION – compress the solutions: a set of primitives that recurs across many solved tasks is anti-unified into a single reusable library fragment.
Re-solving tasks that need that motif now reaches it in ONE search step (pick the fragment) instead of composing it primitive by primitive – so search cost drops.
The card’s claim: on a corpus of related tasks sharing a latent motif, the wake-sleep loop discovers the motif as a fragment and cuts held-out search cost, with the fragment reused across the corpus. The kill criterion is measured, not assumed: if no fragment is reused enough, or the speedup does not materialize, the receipt says so.
Exploratory mixle.experimental code (P12 card).
- class Atom(name, cols)[source]
Bases:
objectA library atom: a named group of feature-column indices (primitive = 1 col; fragment = many).
- class SearchResult(selected: 'list[str]', used_cols: 'tuple[int, ...]', n_evals: 'int')[source]
Bases:
object
- greedy_search(y, features, library, *, penalty=2.0)[source]
Forward-selection structure search; returns the chosen atoms and the number of fit evaluations.
- primitive_library(n_primitives)[source]
One atom per basis component.
- make_task(rng, features, motif, n_specific)[source]
A regression target built from the shared motif plus a few task-specific components.
The motif components carry a strong coefficient (so greedy reliably recovers all of them), the task-specific ones a weaker coefficient.
- abstract_fragment(solutions, *, min_support=0.6, min_size=2)[source]
Return the largest exact itemset jointly present in at least
min_supportof solutions.Ties are resolved by larger exact support and then lexicographically. Every returned fragment is therefore a subset of at least the required number of observed solutions; individually frequent columns are never unioned into a fragment unless that exact union is also jointly frequent.
- class WakeSleepReport(fragment: 'Atom | None', flat_evals: 'float', library_evals: 'float', speedup: 'float', fragment_reuse: 'int', history: 'list' = <factory>)[source]
Bases:
object
- wake_sleep(*, n_train=30, n_heldout=30, n_primitives=16, n_t=160, motif=(2, 5, 8, 11, 3, 13, 6), n_specific=1, seed=0)[source]
Run one wake-sleep round and measure held-out search cost with vs without the learned fragment.