Skip to content

Refactor modelbuilder fit #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 13, 2023
Merged

Conversation

pdb5627
Copy link
Contributor

@pdb5627 pdb5627 commented Jun 13, 2023

In response to #196, I made an attempt at the refactoring.

The first commit naively duplicates the existing fit function for both mcmc and find_MAP fitting methods. The fourth commit puts some of the setup and cleanup code back in the fit function and switches only the actual inference part. I didn't know which way the team might prefer, so they're both there.

I considered making an Enum for the fitting methods, but I saw that pymc.sampling.sample() uses str, so that's what I did here.

I don't feel great about the handling of sampler_config arguments here. There is some overlap in args to mcmc sample_* and find_MAP, but some args are different. At least scipy.optimize.minimize doesn't accept extraneous kwargs, so I pass through only whitelisted args to find_MAP.

pdb5627 added 4 commits June 13, 2023 19:09
Added method-specific inference functions to ModelBuilder and made fit
call them based on a fit_method parameter. Tests coming in the next
commit. Also need to try to factor out code common to both methods.
Added fit_method as a parameter to the tests so that test models are
tested with mcmc and MAP fitting methods.
When test_save_load failed, pytest complained about the temp file not
being closed. It didn't seem to cause any problems, but maybe this is
nicer.
Refactored the ModelBuilder.fit method again to eliminate code
redundancy between the two fitting methods. Eliminated extra kwargs from
being passed to scipy.optimize.minimize.
@twiecki twiecki merged commit 2da3c81 into pymc-devs:main Jun 13, 2023
@twiecki
Copy link
Member

twiecki commented Jun 13, 2023

Thanks @pdb5627!

michaelraczycki added a commit that referenced this pull request Jun 19, 2023
michaelraczycki added a commit that referenced this pull request Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants