-
-
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
Problem in using turing_inference() for Lorenz equation. #30
Comments
turing_inference
for Lorenz equation.
@xukai92 could you please take a look at this. Thanks! |
Seems like it could be HMC errors. Can you try manually transforming the parameters to use an exponential? Is there a way to set this in Turing.jl? |
I think it should be the step size of HMC is set to a too large value. |
Emmm but your priors seem to be fine. |
Using a smaller step size, i.e. |
When using that it still throws
for me, though it runs (but gets the incorrect result). |
It might caused by a bug I solved in TuringLang/Turing.jl@170c2af about initialization. BTW how should I check the results? I can play with it to make sure it works. |
using DiffEqBayes, OrdinaryDiffEq, ParameterizedFunctions, RecursiveArrayTools
g1 = @ode_def_bare LorenzExample begin
dx = σ*(y-x)
dy = x*(ρ-z) - y
dz = x*y - β*z
end σ ρ β
r0 = [1.0; 0.0; 0.0]
tspan = (0.0, 30.0)
p = [10.0,28.0,2.66]
prob = ODEProblem(g1,r0,tspan,p)
@time sol = solve(prob,Vern9(),abstol=1e-12,reltol=1e-12)
t = collect(linspace(1,30,30))
sig = 0.49
data = convert(Array, VectorOfArray([(sol(t[i]) + sig*randn(3)) for i in 1:length(t)]))
priors = [Truncated(Normal(10,2),0,15),Truncated(Normal(30,5),0,45),Truncated(Normal(2.5,0.5),0,4)]
@time bayesian_result = turing_inference(prob,Tsit5(),t,data,priors;num_samples=500,epsilon = 0.001) works well for me now. I don't know why it's different from before. @Vaibhavdixit02 try it? |
The warning still appears for me despite multiple efforts, @xukai92 can you try with a version of Turing.jl before the mentioned PR? |
@Vaibhavdixit02 I tried it with current release Turing.jl and it works with randomness. Just do multiple runs will always give some successful ones, and the inference results for It's actually no related to the bug fixed in that PR but the it's mainly because the choice of priors. Truncated distributions are very sensitive to intializations. In Turing.jl the intializations is done by draw a number from I don't think there is a universal good intialization mechanism for truncated distributions. If they are commonly used in this package, I guess it's better for us to provide an interface for customized initializations for the priors. I can do this and make a PR if it is something wanted. |
That would be very useful. DynamicHMC.jl has a way to specify continuous domain transformations for this purpose. It would be helpful if Turing could read the domain of the prior and directly do a good transformation. |
@xukai I also think it would be a great addition to Turing if it could be done and would be very useful in our case. Also please inform me if I can lend any support, I'll be very glad to be of any help. |
Turing.jl has such a transformation process for variables with constraints, e.g. for I think here the thing is that when the variables following the truncated Normal are initialized in some region, there are some numerical issue of AD when differentiating some I further investigate where the
A minimum case for the numerical problem is: using ForwardDiff: Dual
@inline invlogit{T<:Real}(x::T) = one(T) ./ (one(T) + exp(-x))
d = Dual(-1000, 1)
invlogit(d) # => Dual{Void}(0.0,NaN) Any idea to improve the stability of the related functions? |
Can't the AD step be done before the transformation and transformation applied at some point later in the algorithm? I am not very familiar with the details of how HMC is implemented yet so I apologize if this is a bit obtuse on my part. |
I don't think it's possible to do that. We plan to improve this stability of Turing.jl - let me put this issue in mind when resolving related issues in Turing.jl (TuringLang/Turing.jl#324). |
Fixed by #48 |
When using
turing_inference
for Lorenz equation the priors seem to be causing some problems, in case of a model likeThe
turing_inference
callGives the following error repeatedly
@xukai92 can you shed some light on why this is happening? Not using Truncated priors does not give this error but the result is really bad in that case.
The text was updated successfully, but these errors were encountered: