I tested the example in https://docs.juliadiffeq.org/stable/analysis/global_sensitivity/#GSA-examples-1.
As expected it all went well.
This example, calculates sensitivity with regard to the mean over time on u1 and the maximum over time on u2.
I am interesting on looking how sensitivities change over time - to do this I made a simple change:
using DiffEqSensitivity, Statistics, OrdinaryDiffEq #load packages
function f(du,u,p,td
du[1] = p[1]*u[1] - p[2]*u[1]*u[2] #prey
du[2] = -p[3]*u[2] + p[4]*u[1]*u[2] #predator
end
u0 = [1.0;1.0]
tspan = (0.0,10.0)
p = [1.5,1.0,3.0,1.0]
prob = ODEProblem(f,u0,tspan,p)
t = collect(range(0, stop=10, length=200))
f1 = function (p)
prob1 = remake(prob;p=p)
sol = solve(prob1,Tsit5();saveat=t)
#[mean(sol[1,:]), maximum(sol[2,:])] ---> just use sol as function result
end
I was expecting this would allow to follow the time course of sensitivities.
it does not work and returns the error at the bottom.
If I change the function to include sensitivities only fro u1 or u2 (below) it works,
f1 = function (p)
prob1 = remake(prob;p=p)
sol = solve(prob1,Tsit5();saveat=t)
#[mean(sol[1,:]), maximum(sol[2,:])] ---> just use sol as function result
sol[1,:]# or sol[2,:] as output will work but not together (not just sol)
end
I don’t mind running f1 once for sol[1,:] and then sol[2,:], but then they will be visiting different sections of the parameter space (2 independent runs) so I was hoping to run all sensitivities at once. I remember this was doable and documented in old versions of the package - is this a bug or some intended change.
(old code - where senstivities over time where returned for all states/parameters.
m = DiffEqSensitivity.morris_sensitivity(Problem,solver,t,p_ranges,p_steps;len_trajectory=150,total_num_trajectory=100,num_trajectory=15, relative_scale=rel_scale)
Thanks,
A
This is the error of running code as is:
DimensionMismatch(“tried to assign 2×200 array to 2×200 destination”)
Stacktrace:
[1] throw_setindex_mismatch(::ODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats}, ::Tuple{Int64,Int64}) at .\indices.jl:169
[2] setindex_shape_check at .\indices.jl:226 [inlined]
[3] macro expansion at .\multidimensional.jl:722 [inlined]
[4] _unsafe_setindex!(::IndexLinear, ::Array{Float64,2}, ::ODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats}, ::Base.Slice{Base.OneTo{Int64}}, ::UnitRange{Int64}) at .\multidimensional.jl:717
[5] _setindex! at .\multidimensional.jl:712 [inlined]
[6] setindex! at .\abstractarray.jl:1074 [inlined]
[7] _typed_hcat(::Type{Float64}, ::Array{ODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats},1}) at .\abstractarray.jl:1343
[8] reduce(::typeof(hcat), ::Array{ODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{,Tuple{}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats},1}) at .\abstractarray.jl:1378
[9] #gsa#103(::Bool, ::typeof(gsa), ::getfield(Main, Symbol(“##35#36”)), ::Morris, ::Array{Array{Int64,1},1}) at C:\Users\awolf-yadlin.juliapro\JuliaPro_v1.2.0-2\packages\DiffEqSensitivity\9ybQN\src\global_sensitivity\morris_sensitivity.jl:87
[10] gsa(::Function, ::Morris, ::Array{Array{Int64,1},1}) at C:\Users\awolf-yadlin.juliapro\JuliaPro_v1.2.0-2\packages\DiffEqSensitivity\9ybQN\src\global_sensitivity\morris_sensitivity.jl:69
[11] top-level scope at In[74]:1