Skip to content
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

GSA BoundsError when the range of the first parameter is a single value #125

Open
natema opened this issue Sep 16, 2023 · 0 comments
Open

Comments

@natema
Copy link

natema commented Sep 16, 2023

Let's consider the example for using Morris method in the tutorial :

using GlobalSensitivity, Statistics, OrdinaryDiffEq, QuasiMonteCarlo

function f(du,u,p,t)
  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,:])]
end

m = gsa(f1,Morris(total_num_trajectory=1000,num_trajectory=150),[[1,5],[1,5],[1,5],[1,5]]

The example works fine if we change the range of some parameters to consist of a single point (e.g. [[1,5],[1,1],[1,1],[1,5]] for the second and third parameters), but raises an error if we do that for the first parameter:

julia> m = gsa(f1,Morris(total_num_trajectory=1000,num_trajectory=150),[[1,1],[1,5],[1,5],[1,5]])
ERROR: BoundsError: attempt to access 0-element Vector{Vector{Float64}} at index [1]
Stacktrace:
 [1] getindex(A::Vector{Vector{Float64}}, i1::Int64)
   @ Base ./essentials.jl:13
 [2] gsa(f::var"#9#10", method::Morris, p_range::Vector{Vector{…}}; batch::Bool, rng::Random.TaskLocalRNG, kwargs::@Kwargs{})
   @ GlobalSensitivity ~/.julia/packages/GlobalSensitivity/SJGNh/src/morris_sensitivity.jl:213
 [3] gsa(f::Function, method::Morris, p_range::Vector{Vector{Int64}})
   @ GlobalSensitivity ~/.julia/packages/GlobalSensitivity/SJGNh/src/morris_sensitivity.jl:135
 [4] top-level scope
   @ REPL[2]:1
Some type information was truncated. Use `show(err)` to see complete types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant