-
Notifications
You must be signed in to change notification settings - Fork 29
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
setval! is being weird #167
Comments
Seems like this is the offending line: https://github.com/TuringLang/DynamicPPL.jl/blob/master/src/varinfo.jl#L1183..L1183 When ran on the failing example, |
Uhhh: julia> regex = r"^m[1]$|^m[1]\["
r"^m[1]$|^m[1]\["
julia> match(regex, "m[1]") === nothing
true |
Crap, of course: julia> regex = r"m\[1\]$|m\[1\]\["
r"m\[1\]$|m\[1\]\["
julia> match(regex, "m[1]")
RegexMatch("m[1]") So we need to escape the names! |
You have to escape julia> regex = r"^m\[1\]$|^m\[1\]\[" |
Lol @devmotion , you didn't get that until NOW? #5secondsfaster |
Could we maybe use |
We don't have |
No I realized that it's probably not useful, exactly due to this issue. |
Immediate solution: function regex_escape(s::AbstractString)
res = replace(s, r"([()[\]{}?*+\-|^\$\\.&~#\s=!<>|:])" => s"\\\1")
replace(res, "\0" => "\\0")
end But you're right though, |
But it does fix the issue: julia> using DynamicPPL, Turing
[ Info: Precompiling DynamicPPL [366bfd00-2699-11ea-058f-f148b4cae6d8]
[ Info: Precompiling Turing [fce5fe82-541a-59a6-adf8-730c64b5f9a0]
julia> Turing.turnprogress(false)
[ Info: [Turing]: progress logging is disabled globally
[ Info: [AdvancedVI]: global PROGRESS is set as false
false
julia> @model function demo(xs, ::Type{TV} = Vector{Float64}) where {TV}
m = TV(undef, 2)
for i in 1:2
m[i] ~ Normal(0, 1)
end
for i in eachindex(xs)
xs[i] ~ Normal(m[1], 1.)
end
return (m, )
end
demo (generic function with 2 methods)
julia> xs = randn(3);
julia> model = demo(xs);
julia> chain = sample(model, NUTS(0.65), 100);
┌ Info: Found initial step size
└ ϵ = 1.6
julia> generated_quantities(model, chain)
50×1 Array{Tuple{Array{Float64,1}},2}:
([-0.6466888684208906, -1.0605924818561454],)
([-0.6466888684208906, -1.0605924818561454],)
([-0.21895508638907632, 1.6653331143718089],)
([-0.21895508638907632, 1.6653331143718089],)
([-0.2997309317443484, -0.029323999401321466],)
([-1.0387336145893835, 0.7184211285862931],)
([-0.21765620075312997, 0.01436077650117068],)
([0.529802098448724, -0.2980663360869661],)
([0.11811237219422727, -0.5270924388346214],)
([-1.0033004645889954, 1.0369564237981046],)
([-0.6387891971861386, 0.6617567920524946],)
([-0.010075207468817182, 0.38321779739786466],)
... |
Should I just make a PR with this solution? Seems like this is something that ought to be fixed asap... |
Will also add some tests, so this doesn't happen in the future |
Maybe it would be safer to use string_vn = string(vn)
string_vn_indexing = string_vn * "["
findall(keys) do x
string_x = string(x)
return string_x == string_vn || startswith(string_x, string_vn_indexing)
end |
Nice, that indeed seems safer 👍 |
This PR adds `generated_quantities` as discussed in TuringLang/Turing.jl#1335 + adds a fix for #167.
Fixed by #168. |
So I'm currently making a PR for
generated_quantities
, and ran into the following:In contrast, the following works just fine:
So the in first example
setval!
fails.The text was updated successfully, but these errors were encountered: