You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using @torfjelde's trick to set the initial parameters to the theoretical mean of the priors. Unfortunately, I've noticed that it doesn't seem to work with the "new" syntax for fitting models
Works:
using Turing
@modelfunctionmymodel(y)
x ~Normal(0, 1)
for i in1:length(y)
y[i] ~Normal(x, 1)
endend
fitted =mymodel([1.0, 2.0, 3.0])
initial_params =mapreduce(DynamicPPL.tovec ∘ mean, vcat, values(Turing.extract_priors(fitted)))
Errors:
@modelfunctionmymodel(y)
x ~Normal(0, 1)
for i in1:length(y)
y[i] ~Normal(x, 1)
endend
fitted =mymodel() | (y=[1.0, 2.0, 3.0],)
initial_params =mapreduce(DynamicPPL.tovec ∘ mean, vcat, values(Turing.extract_priors(fitted)))
ERROR: UndefVarError: `y` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
[1] macro expansion
@ C:\Users\domma\.julia\packages\DynamicPPL\cvlfK\src\compiler.jl:584 [inlined]
[2] mymodel(__model__::DynamicPPL.Model{…}, __varinfo__::DynamicPPL.ThreadSafeVarInfo{…}, __context__::DynamicPPL.PriorExtractorContext{…})
@ Main .\Untitled-1:5
[3] _evaluate!!
@ C:\Users\domma\.julia\packages\DynamicPPL\cvlfK\src\model.jl:914 [inlined]
[4] evaluate_threadsafe!!(model::DynamicPPL.Model{…}, varinfo::DynamicPPL.UntypedVarInfo{…}, context::DynamicPPL.PriorExtractorContext{…})
@ DynamicPPL C:\Users\domma\.julia\packages\DynamicPPL\cvlfK\src\model.jl:903
[5] evaluate!!(model::DynamicPPL.Model{…}, varinfo::DynamicPPL.UntypedVarInfo{…}, context::DynamicPPL.PriorExtractorContext{…})
@ DynamicPPL C:\Users\domma\.julia\packages\DynamicPPL\cvlfK\src\model.jl:833
[6] extract_priors
@ C:\Users\domma\.julia\packages\DynamicPPL\cvlfK\src\extract_priors.jl:117 [inlined]
[7] extract_priors(args::DynamicPPL.Model{typeof(mymodel), (), (), (), Tuple{}, Tuple{}, DynamicPPL.ConditionContext{…}})
@ DynamicPPL C:\Users\domma\.julia\packages\DynamicPPL\cvlfK\src\extract_priors.jl:113
[8] top-level scope
@ Untitled-1:23
Some type information was truncated. Use `show(err)` to see complete types.
Julia version info
versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af (2024-12-01 20:02 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 16 × 11th Gen Intel(R) Core(TM) i9-11950H @ 2.60GHz
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, tigerlake)
Threads: 16 default, 0 interactive, 8 GC (on 16 virtual cores)
Environment:
JULIA_EDITOR = code
@modelfunctionmymodel() # `y` is no longer a function argument
x ~Normal(0, 1)
y =Vector{Float64}(undef, 3) # this line needs to be addedfor i in1:length(y)
y[i] ~Normal(x, 1)
endend
fitted =mymodel() | (y=[1.0, 2.0, 3.0],)
The main issue is that lhs ~ rhs doesn't define lhs until after the tilde statement, so 1:length(y) won't work. (In the original model, it does work because the function argument y is in scope at that point).
I guess in principle this could be reworked, but it would require some fairly complex surgery in DynamicPPL and imo there are other underlying problems with conditioning on vectors that are more pressing. So, although I'll open a corresponding issue in DynamicPPL to track this, I think it's unlikely to be 'fixed' in the near future - hopefully this is a good enough fix :)
If the above doesn't work for any reason, let me know, and we can reopen.
Minimal working example
Description
I've been using @torfjelde's trick to set the initial parameters to the theoretical mean of the priors. Unfortunately, I've noticed that it doesn't seem to work with the "new" syntax for fitting models
Works:
Errors:
Julia version info
versioninfo()
Manifest
]st --manifest
The text was updated successfully, but these errors were encountered: