Repository navigation
fix: ship log_likelihood_ceiling disabled by default — the magnitude is not unit-safe - #1550
Merged
Merged
Conversation
…is not unit-safe PR #1545 shipped the `general.test.log_likelihood_ceiling` guard enabled at 1.0e+20. The threshold is not unit-safe: a log likelihood is `-0.5 * chi_squared - 0.5 * noise_normalization`, and both terms scale with the noise map — chi_squared as `noise ** -2`, noise_normalization linearly in the pixel count. A dataset whose noise map is expressed in a small unit can produce a legitimate log likelihood above 1e20, and every model would be silently mapped to the resample sentinel, leaving the search unable to fit at all. The guard reads only a magnitude, so it cannot tell that case from the fp64-Cholesky garbage it was built for. The code path stays; the packaged default flips off. - `autofit/config/general.yaml` and `test_autofit/config/general.yaml`: `log_likelihood_ceiling` is now blank (disabled), with the units argument in the comment and a pointer at the surface that opts in. - `LOG_LIKELIHOOD_CEILING_DEFAULT` is now `inf`, so a config that never mentions the key inherits today's default rather than the one that shipped with the guard's first release. - `Fitness.call` warns once per process, on the numpy path, the first time the guard actually rejects a value — a rejection is otherwise indistinguishable from "the model is bad" from inside the search. The jit/vmap paths reject silently by construction (the mask is a tracer); no fire counter is exposed for them, because incrementing one from traced code needs a host callback or a donated buffer, and a counter blind to the traced paths would read 0 on a jitted run that rejected every sample. - Docstrings in `fitness.py` and `nss/search.py` describe an opt-in guard. - Tests: the "default 1e20" expectations become "default disabled"; every enabled-path test sets the ceiling explicitly, as a user's `general.yaml` would; new coverage for the first-fire warning, its once-per-process latch, its silence when nothing is rejected, and its absence on the jit path. autolens_profiling opts in at 1.0e+20 (its own config), citing run 341908_5. Refs #1549.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1545 (merged
b70cf7fc3), which shipped thegeneral.test.log_likelihood_ceilingguard enabled at1.0e+20.The threshold is not unit-safe. A log likelihood is
-0.5 * chi_squared - 0.5 * noise_normalization, and both terms scale with the noise-map units —chi_squaredasnoise ** -2,noise_normalizationlinearly in the pixel count. A dataset whose noise map is expressed in a small unit can therefore produce a legitimate log likelihood above1e20; every model would be silently mapped to the resample figure of merit, and the search would see nothing but rejections and could not fit at all. The guard reads only a magnitude in unspecified units, so it cannot distinguish that from the fp64-Cholesky garbage it was built for (a non-positive-definite regularization matrix returning finite~3e+303, which a nested sampler accepts as its peak and never terminates on).A default that can silently break a correctly-specified fit is the wrong default. The code path stays; the packaged default flips off, and the guard becomes opt-in on surfaces whose units are known.
autolens_profilingenables it at1.0e+20in its own config, citing run341908_5(PyAutoLabs/autolens_profiling — separate, independent PR). Whether real PyAutoLens analyses should enable it is deferred until the Wave-B harvest gives enough results to say what magnitudes science fits actually reach.Also added: a first-fire warning. A rejection is invisible from inside the search — it looks exactly like a bad model — so the numpy path says so once per process, naming the value, the ceiling and the units caveat. The
jax.jit/jax.vmappaths cannot warn: the rejection is anxp.whereon a tracer, with no Python-visible moment at which the guard fires, so they reject silently by construction. No fire counter is offered for them either — incrementing one from traced code needs a host callback or a donated buffer, which perturbs the code being profiled and does not survivevmap/grad, and a counter blind to the traced paths would read0on a jitted run that rejected every sample. Both facts are documented at the call site.API Changes
The guard's default behaviour changes:
general.test.log_likelihood_ceilingnow ships blank, and a config that omits the key is now treated as disabled rather than1.0e20. Fits that were silently rejecting finite log likelihoods above1e20will now accept them, restoring pre-#1545 behaviour unless a config opts in.LOG_LIKELIHOOD_CEILING_DEFAULTis still exported but its value changes from1.0e20toinf. No symbol is removed or renamed, and no signature changes.See full details below.
Test Plan
pytest test_autofit/— 2375 passed, 3 skippedpytest test_autofit/non_linear/— 791 passed, 2 skippedgeneral.yamlfiles parse the blank key asNone→get_log_likelihood_ceiling()returnsinfautolens_workspace) resolves toinfautolens_profiling's layered override resolves to1e+20while its siblingtest:keys still merge from the packaged defaultsFull API Changes (for automation & release notes)
Changed Behaviour
general.test.log_likelihood_ceiling(config) — ships blank/disabled; was1.0e+20. Applies toautofit/config/general.yamlandtest_autofit/config/general.yaml.autofit.non_linear.fitness.get_log_likelihood_ceiling()— an absent config key now returnsinf(disabled); it previously returned1.0e20.null, non-positive and unparseable entries still map toinf, unchanged.autofit.non_linear.fitness.Fitness.call— emits a singlelogger.warningper process the first time the magnitude guard rejects a value on the numpy path. Thejax.jit/jax.vmappaths are unchanged and silent.autofit.non_linear.search.nest.nss.search.nss_log_likelihood_from— its default ceiling (read from config) is now disabled; an explicitlog_likelihood_ceiling=argument is unchanged. Its non-finite (NaN/inf) guard is unaffected and still unconditional.Changed Value
autofit.non_linear.fitness.LOG_LIKELIHOOD_CEILING_DEFAULT—1.0e20→float("inf").Added
autofit.non_linear.fitness.Fitness._is_jax(private property) — whether the array backend is JAX, so the warning stays off the traced paths.Migration
config/general.yaml:Closes #1549.
Generated by the PyAutoLabs agent workflow.