Time Series sensitivity analysis for multiple outputs

Hi,

function circ_local_time(x)
    _prob = remake(prob,u0=x[1:3],p=x[4:end])
    sol = solve(_prob,Tsit5(), reltol=1e-6, abstol=1e-6,saveat=savetime)
    sol[LV.p]
end

St = ForwardDiff.jacobian(circ_local_time,[u0;p])
x = LinRange(0,1,100)
plot(x,St[:,12])

When I run the above code I can see how the sensitivity of the parameter changes during a cycle. However, when I add another output eg

function circ_local_time(x)
    _prob = remake(prob,u0=x[1:3],p=x[4:end])
    sol = solve(_prob,Tsit5(), reltol=1e-6, abstol=1e-6,saveat=savetime)
    [sol[LV.p], **sol[LV.V]]**
end

St = ForwardDiff.jacobian(circ_local_time,[u0;p])
x = LinRange(0,1,100)
plot(x,St[:,12])

the output St is
2×12 Matrix{Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(circ_local_time), Float64}, Float64, 12}}}

Which I am not sure I fully understand what this is saying to me.

Any help appreciated :slight_smile:

Cheers,
Harry

The issue is that this is a matrix of vectors, which ForwardDiff doesn’t know how to easily handle. So it just gives you that matrix of vectors of duals (I’m surprised it didn’t error). [sol[LV.p]; sol[LV.V]] is a vector, and that should give a standard matrix Jacobian that would then resize.

For reference:

julia> a = [1.0,2.0]
2-element Vector{Float64}:
 1.0
 2.0

julia> b = [3.0,4.0]
2-element Vector{Float64}:
 3.0
 4.0

julia> [a,b]
2-element Vector{Vector{Float64}}:
 [1.0, 2.0]
 [3.0, 4.0]

julia> [a;b]
4-element Vector{Float64}:
 1.0
 2.0
 3.0
 4.0

julia> [a b]
2×2 Matrix{Float64}:
 1.0  3.0
 2.0  4.0