-
Notifications
You must be signed in to change notification settings - Fork 37
Allow generation of ParamsWithStats from FastLDF plus parameters, and also bundle_samples
#1129
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
Changes from 5 commits
fa32c88
2bf5b18
2fad97b
8129340
5d4527a
82616cd
60dbab1
0a9557e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -133,3 +133,60 @@ function ParamsWithStats( | |||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| return ParamsWithStats(params, stats) | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| ParamsWithStats( | ||||||||||||||||||||||||||||||||||
| param_vector::AbstractVector, | ||||||||||||||||||||||||||||||||||
| ldf::DynamicPPL.Experimental.FastLDF, | ||||||||||||||||||||||||||||||||||
| stats::NamedTuple=NamedTuple(); | ||||||||||||||||||||||||||||||||||
| include_colon_eq::Bool=true, | ||||||||||||||||||||||||||||||||||
| include_log_probs::Bool=true, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Generate a `ParamsWithStats` by re-evaluating the given `ldf` with the provided | ||||||||||||||||||||||||||||||||||
| `param_vector`. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| This method is intended to replace the old method of obtaining parameters and statistics | ||||||||||||||||||||||||||||||||||
| via `unflatten` plus re-evaluation. It is faster for two reasons: | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| 1. It does not rely on `deepcopy`-ing the VarInfo object (this used to be mandatory as | ||||||||||||||||||||||||||||||||||
| otherwise re-evaluation would mutate the VarInfo, rendering it unusable for subsequent | ||||||||||||||||||||||||||||||||||
| MCMC iterations). | ||||||||||||||||||||||||||||||||||
| 2. The re-evaluation is faster as it uses `OnlyAccsVarInfo`. | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| function ParamsWithStats( | ||||||||||||||||||||||||||||||||||
| param_vector::AbstractVector, | ||||||||||||||||||||||||||||||||||
| ldf::DynamicPPL.Experimental.FastLDF, | ||||||||||||||||||||||||||||||||||
| stats::NamedTuple=NamedTuple(); | ||||||||||||||||||||||||||||||||||
| include_colon_eq::Bool=true, | ||||||||||||||||||||||||||||||||||
| include_log_probs::Bool=true, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| strategy = InitFromParams( | ||||||||||||||||||||||||||||||||||
| VectorWithRanges(ldf._iden_varname_ranges, ldf._varname_ranges, param_vector), | ||||||||||||||||||||||||||||||||||
| nothing, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| accs = if include_log_probs | ||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||
| DynamicPPL.LogPriorAccumulator(), | ||||||||||||||||||||||||||||||||||
| DynamicPPL.LogLikelihoodAccumulator(), | ||||||||||||||||||||||||||||||||||
| DynamicPPL.ValuesAsInModelAccumulator(include_colon_eq), | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+170
to
+172
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am looking at Lines 247 to 262 in 5d4527a
LogJacobianAccumulator
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, right. I think it doesn't matter for the present purposes because we always want the output to not include the Jacobian term i.e. logprior and logjoint are 'as seen in the model'. |
||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| (DynamicPPL.ValuesAsInModelAccumulator(include_colon_eq),) | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| _, vi = DynamicPPL.Experimental.fast_evaluate!!( | ||||||||||||||||||||||||||||||||||
| ldf.model, strategy, AccumulatorTuple(accs) | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| params = DynamicPPL.getacc(vi, Val(:ValuesAsInModel)).values | ||||||||||||||||||||||||||||||||||
| if include_log_probs | ||||||||||||||||||||||||||||||||||
| stats = merge( | ||||||||||||||||||||||||||||||||||
| stats, | ||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||
| logprior=DynamicPPL.getlogprior(vi), | ||||||||||||||||||||||||||||||||||
| loglikelihood=DynamicPPL.getloglikelihood(vi), | ||||||||||||||||||||||||||||||||||
| lp=DynamicPPL.getlogjoint(vi), | ||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| return ParamsWithStats(params, stats) | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.