Repository navigation
Add nano joint preferential-discovery estimator to numerical library - #90
Conversation
૮ >ﻌ< ა ci reviewrunning on 74df8b2 — fix(numeric): build bands on the log of the amount above the Still running 17 jobs: ❌ Job failuresOS-specific tests / macOS-only tests · View jobJob OS-specific tests / macOS-only tests failed. |
The emitter contract and the doc page told generated code to call failed(reason, ...) and excluded(reason, ...). The inherited constructors take note, so failed(reason='x') raises TypeError. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The estimator labelled its bands Laplace but took their covariance from the BFGS search's working matrix. That matrix starts as the identity and is reset to it after any short step, which is every step near convergence, so it described the route the search took and not how sharply the history fixes the parameters. On simulated histories it was exactly the identity in 53 of 60 fits, and the upper bound the stop rule reads moved 0.87, 0.37, 0.23 with the correction against 1.66, 0.37, 0.54 without it on the same drying-out history. The covariance is now the inverse of the loss's curvature at the fitted parameters, measured by central differences after the search ends. The search keeps its matrix for the next warm start only. A curvature that is not positive definite reports the estimate as unidentifiable. The search itself is untouched: against the fixture generated by the source program, every fitted parameter, point estimate, count and status code is unchanged. The ends of the bands and the stop decisions read from them change, so the fixture test no longer compares those, and two tests that fail on the previous file cover them: the covariance must invert an independently measured curvature, and the bands must not depend on whether the fit was reached in one step or many. The file is therefore no longer a byte-for-byte copy of nano-graphrag's. The notices, doc page and registered provenance say so, and the estimator reports preferential_incidence_estimator_v3. The catalog test now relates the reported version to the registered provenance instead of repeating the string. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Conflicts with the value-of-computation estimator (#89) in README.md, episode_builder/admission.py, episode_builder/planner.py and numeric_control_library/__init__.py were additive; both sides are kept.
With the covariance corrected, the band symmetric about the estimate proved too narrow on the side the stop rule reads. On histories drawn from the model, the true next yield lay above the upper end in 13% to 21% of runs; 2.5% is intended. The banded quantities cannot fall below a floor (zero, or the count already observed), so the normal approximation now applies to the logarithm of the amount above that floor. The true value then lies above the upper end in about 2% to 5% of runs, in a steady regime and in a fast-drying one. An importance-sampled posterior around the same fit gave 1% to 7% and upper ends of similar size, so the wider upper end is what the fitted model implies and not an artefact of the form. The upper end is further from the estimate than before. On the fixture's single-channel drying-out history it reads 4.85, 3.52, 1.96, 1.37, 1.05 over the last five attempts and no stop is reached within the 13 attempts; with the symmetric band it read 0.87, 0.37, 0.23, 0.14, 0.09 and stopped at the twelfth. Thresholds chosen against the earlier bands will stop later. Two tests fail on the symmetric form: a band must spread by the same ratio on both sides of its floor, and across 200 histories drawn from the model the true next yield may exceed the reported upper end in at most 10% (10 of 200 with this form, 38 with the symmetric one). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FfzyrvFGRVKR5LMMXbXonU
Both this branch and the preferential discovery estimator merged in #90 register an estimator in the same places and describe it in the README. Keep both. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FfzyrvFGRVKR5LMMXbXonU
What does this PR do?
Adds nano-graphrag's
joint_preferential_discovery_v1estimator and controller to OpenChia's reusable numerical function library, with two corrections to how its uncertainty is computed. Episodes can select the joint observation/discovery model and controller while preserving ordered attempts, identity deduplication, failures, exclusions, and independent histories for each Episode path.The existing Chao2 estimator and approved Architecture bindings remain unchanged. The new model needs ordered history, which cannot be recovered from their anonymous incidence counts.
Changes Made
numeric_control_library/preferential_discovery.pyis adapted fromquestion_pipeline/utilities/rarefaction.pyat nano-graphrag revision60a167f9eeda0c9ea2ca294724174948947baf3f(source SHA25602af1965…cdd35). It is no longer a byte-for-byte copy; see the next section.rarefaction.joint_preferential_discovery_v1andcontroller_composition.compose_preferential_controller; provide typed observations at the existingGrain.controllerboundary.Correction to the uncertainty bands
The source labels its bands Laplace but takes their covariance from the BFGS search's working matrix. That matrix starts as the identity and is reset to it after any short step, which is every step near convergence. On simulated histories it was exactly the identity in 53 of 60 fits. The stop rule reads the upper bound that comes out of it.
Here the covariance is the inverse of the loss's curvature at the fitted parameters, measured by central differences after the search ends. The search keeps its matrix for the next warm start only. A curvature that is not positive definite reports the estimate as unidentifiable.
What this changes and what it does not:
preferential_incidence_estimator_v3, and the notices, doc page and registered provenance state the difference.The same defect is still in nano-graphrag at
60a167f.Correction to the shape of the bands
With the covariance corrected, a band symmetric about the estimate was too narrow on the side the stop rule reads. On histories drawn from the model itself, the true next yield lay above the upper end in 13% to 21% of runs; 2.5% is intended.
The banded quantities cannot fall below a floor (zero, or the count already observed), so the normal approximation is now applied to the logarithm of the amount above that floor.
250 to 300 simulated histories per cell. The sampled posterior is a check on the form, not something this PR ships.
This makes Episodes stop later. Upper bound on expected next discoveries over the last five attempts of the fixture's single-channel drying-out history:
Thresholds chosen against the earlier bands will stop later. The band change is its own commit (
74df8b2b12) and can be reverted separately from the covariance fix.Also corrected: the emitter contract and doc page told generated code to call
failed(reason, ...); the argument isnote.How to Test
32 passed, 0 failed on Linux x86-64, Python 3.14.7, through the canonical runner.
test_the_search_still_produces_what_the_source_program_doescompares against the source-generated fixture, leaving out band ends, stop decisions and the version label.test_band_covariance_inverts_the_curvature_of_the_fitted_lossmultiplies the reported covariance by an independently measured curvature and requires the identity. Fails on the source file.test_bands_do_not_depend_on_the_route_the_search_tookfits one history step by step and in one go and requires the same bands. Fails on the source file (0.139 against 0.415).test_a_band_spreads_by_the_same_ratio_on_both_sides_of_its_floorandtest_the_true_next_yield_rarely_exceeds_the_upper_bound_the_stop_rule_reads(200 simulated histories, at most 10% above the upper end; 10 of 200 here, 38 with the symmetric band).tests/numeric_control_library/ tests/episode_builder/ tests/function_library/ tests/method_loop/: 115 passed, 5 failed. The same five fail onmain: two intest_repeatable_call_materialization.py, two intest_episode_tree_recursion.py, one intest_api_failure_continuation.py.The original head of this PR failed its fixture test on Linux: the fixture is from macOS arm64, and the identity-matrix covariance amplified last-digit differences between hosts. With band ends out of the comparison, the Linux run agrees with the fixture to nine decimal places.
Known limits, not addressed here
method_loop/episode.py; this controller is the first to request a transition.Grain.controller.This transfers nano-graphrag's adaptation of a joint sampling/outcome model. It does not implement Diggle et al.'s spatial GP/Cox-process model.
🤖 Generated with Claude Code