-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Correct the order of rvs
sent to compile_dlogp
in find_MAP
#5928
Conversation
pymc/tuning/starting.py
Outdated
@@ -120,7 +120,8 @@ def find_MAP( | |||
compiled_logp_func = DictToArrayBijection.mapf(model.compile_logp(jacobian=False), start) | |||
logp_func = lambda x: compiled_logp_func(RaveledVars(x, x0.point_map_info)) | |||
|
|||
rvs = [model.values_to_rvs[value] for value in vars] | |||
vars_dict = {var.name: var for var in vars} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could replace the var_names
set above with this dict so that we don't create two objects with similar purposes.
Looks perfect! I left a small refactoring suggestion above, let me know what you think. |
5ff87c0
to
4970a76
Compare
Makes sense. I've made the change you suggested. |
Codecov Report
@@ Coverage Diff @@
## main #5928 +/- ##
=======================================
Coverage 89.52% 89.52%
=======================================
Files 73 73
Lines 13267 13267
=======================================
Hits 11877 11877
Misses 1390 1390
|
Thanks @quantheory! |
This PR is a quick fix for the bad behavior of
find_MAP
in v4 (closes #5923).When using a gradient-based method in
scipy.minimize
, we need the order of derivatives in the Jacobian to match the order of the variables inx
. Sincex0.point_map_info
is used to define this order in the rest of the function, I just use it to set the order of variables in thervs
argument sent tocompile_dlogp
, which fixes the issue.I've also added
test_find_MAP_issue_5923
, which fails for the old code and passes in this commit. (In fact, the originaltest_find_MAP
test would also fail if we used a starting point slightly farther from the MAP.)