Repository navigation
perf(hierarchical): faster options for EmpiricalBayes and VariationalBayes - #103
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Speeds up hierarchical fitting. The defaults are unchanged, so results for a fixed seed stay the same; the faster paths are options.
In a speed comparison with cbm (RLRW, 100 participants, 120 trials), cpm made about as many objective evaluations as cbm but each one cost more: 17.3 against 5.0 ms per participant and iteration. These changes reduce that cost.
Changes
FminBoundwithapprox_grad=Truecomputes the finite-difference gradient itself, together with the objective, as SciPy does. The results are bit-identical, and hierarchical fits are 19% faster.hessianargument onFminBound,Fmin,MinimizeandBads.hessian="finite_differences"computes the Hessian at the optimum with bounded finite differences, using 7 instead of 22 evaluations per participant and iteration. The default,"numdifftools", keeps the previous Hessian.startargument onEmpiricalBayesandVariationalBayes.start="prior_mean"starts every participant's first optimisation from the current prior's location, clipped into the bounds, as cbm does. The default,"random", keeps the previous starts.positive_definitecolumn in thefitofEmpiricalBayesandVariationalBayes, and anot_positive_definitecount in theirhyperparameters. Estimates on a bound can have a Hessian that is not positive definite; they are kept because the bounds must be respected.benchmarks/hierarchical_profile.pyprofiles aVariationalBayesfit. The before/after results and the cbm comparison are inbenchmarks/results/.LogLikelihood.bernoulliskipsnan_to_numwhen every value is finite.Results
Using
hessian="finite_differences",start="prior_mean"andnumber_of_starts=1together bringsEmpiricalBayesfrom 20.8 to 6.8 ms per participant and iteration, andVariationalBayesfrom 20.1 to 7.0 ms. cbm takes 4.4 ms. Throughout, RMSE against 0.26.0.dev1 stays within the bootstrap 95% intervals.Testing
hessianoption on every optimiser,start, and the positive-definite record.Not addressed here
FminBound(parallel=True)finds worse optima than serial runs.FminBoundcompares later starts only with the first.VariationalBayesdocstring gives 1000 as the default foriteration; the code uses 50.🤖 Generated with Claude Code