Skip to content

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

@natema

Description

@natema

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions