From 140cc2e619ed37cada36d2b495e74df2e94463c1 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Fri, 29 May 2020 23:18:16 -0400 Subject: [PATCH] end of concrete_solve --- Project.toml | 2 +- src/abc_inference.jl | 2 +- src/dynamichmc_inference.jl | 10 +++++----- src/turing_inference.jl | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Project.toml b/Project.toml index 5296b730..e1fd6dff 100644 --- a/Project.toml +++ b/Project.toml @@ -32,7 +32,7 @@ Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" [compat] ApproxBayes = "0.3" -DiffEqBase = "6.5" +DiffEqBase = "6.36" DiffResults = "0.0.4, 1.0" Distances = "0.8, 0.9" Distributions = "0.21, 0.22, 0.23" diff --git a/src/abc_inference.jl b/src/abc_inference.jl index 7c95e714..4d331f30 100644 --- a/src/abc_inference.jl +++ b/src/abc_inference.jl @@ -11,7 +11,7 @@ function createabcfunction(prob, t, distancefunction, alg; save_idxs = nothing, else u0 = prob.u0 end - sol = concrete_solve(STANDARD_PROB_GENERATOR(prob, params), alg, u0; saveat = t, save_idxs = save_idxs, kwargs...) + sol = solve(prob, alg, u0=u0, p=params, saveat = t, save_idxs = save_idxs, kwargs...) if size(sol, 2) < length(t) return Inf,nothing else diff --git a/src/dynamichmc_inference.jl b/src/dynamichmc_inference.jl index 9978265e..d206a26b 100644 --- a/src/dynamichmc_inference.jl +++ b/src/dynamichmc_inference.jl @@ -40,13 +40,13 @@ function (P::DynamicHMCPosterior)(θ) u0 = convert.(T, sample_u0 ? parameters[1:nu] : problem.u0) p = convert.(T, sample_u0 ? parameters[(nu + 1):end] : parameters) if length(u0) < length(problem.u0) - # assumes u is ordered such that the observed variables are in the begining, consistent with ordered theta + # assumes u is ordered such that the observed variables are in the begining, consistent with ordered theta for i in length(u0):length(problem.u0) push!(u0, convert(T,problem.u0[i])) end end _saveat = t === nothing ? Float64[] : t - sol = concrete_solve(problem, algorithm, u0, p; saveat = _saveat, save_idxs = save_idxs, solve_kwargs...) + sol = solve(problem, algorithm; u0=u0, p=p, saveat = _saveat, save_idxs = save_idxs, solve_kwargs...) failure = size(sol, 2) < length(_saveat) failure && return T(0) * sum(σ) + T(-Inf) log_likelihood = sum(sum(map(logpdf, Normal.(0.0, σ), sol[:, i] .- data[:, i])) for (i, t) in enumerate(t)) @@ -93,10 +93,10 @@ posterior values (transformed from `ℝⁿ`). function dynamichmc_inference(problem::DiffEqBase.DEProblem, algorithm, t, data, parameter_priors, parameter_transformations=as(Vector, asℝ₊, length(parameter_priors)); σ_priors = fill(Normal(0, 5), size(data, 1)),sample_u0 = false, rng = Random.GLOBAL_RNG, - num_samples = 1000, AD_gradient_kind = Val(:ForwardDiff), save_idxs = nothing,solve_kwargs = (), + num_samples = 1000, AD_gradient_kind = Val(:ForwardDiff), save_idxs = nothing,solve_kwargs = (), mcmc_kwargs = (initialization = (q = zeros(length(parameter_priors) + (save_idxs === nothing ? length(data[:,1]) : length(save_idxs))),),)) P = DynamicHMCPosterior(; algorithm = algorithm, problem = problem, t = t, data = data, - parameter_priors = parameter_priors, σ_priors = σ_priors, + parameter_priors = parameter_priors, σ_priors = σ_priors, solve_kwargs = solve_kwargs, sample_u0 = sample_u0, save_idxs = save_idxs) trans = as((parameters = parameter_transformations, σ = as(Vector, asℝ₊, length(σ_priors)))) @@ -104,4 +104,4 @@ function dynamichmc_inference(problem::DiffEqBase.DEProblem, algorithm, t, data, ∇ℓ = LogDensityProblems.ADgradient(AD_gradient_kind, ℓ) results = mcmc_with_warmup(rng, ∇ℓ, num_samples; mcmc_kwargs...) merge((posterior = transform.(Ref(trans), results.chain), ), results) -end \ No newline at end of file +end diff --git a/src/turing_inference.jl b/src/turing_inference.jl index 37ca814c..6caaae10 100644 --- a/src/turing_inference.jl +++ b/src/turing_inference.jl @@ -11,8 +11,8 @@ function turing_inference( num_samples=1000, sampler = Turing.NUTS(0.65), syms = [Turing.@varname(theta[i]) for i in 1:length(priors)], sample_u0 = false, - save_idxs = nothing, - progress = false, + save_idxs = nothing, + progress = false, kwargs..., ) N = length(priors) @@ -29,13 +29,13 @@ function turing_inference( u0 = convert.(T, sample_u0 ? theta[1:nu] : prob.u0) p = convert.(T, sample_u0 ? theta[(nu + 1):end] : theta) if length(u0) < length(prob.u0) - # assumes u is ordered such that the observed variables are in the begining, consistent with ordered theta + # assumes u is ordered such that the observed variables are in the begining, consistent with ordered theta for i in length(u0):length(prob.u0) push!(u0, convert(T,prob.u0[i])) end end _saveat = t === nothing ? Float64[] : t - sol = concrete_solve(prob, alg, u0, p; saveat = _saveat, progress = progress, save_idxs = save_idxs, kwargs...) + sol = solve(prob, alg; u0=u0, p=p, saveat = _saveat, progress = progress, save_idxs = save_idxs, kwargs...) failure = size(sol, 2) < length(_saveat) if failure