# Fit ODE parameters with different weights for each variable

Hi! I am trying to optimize parameters for an ODE giving different weights to each entry of the solution `y` inside the `L2Loss` function. That is all `y[1]`s should have some weights `w1` while all `y[3]`s should have some different weights `w3`.
however: 1) I am uncertain on how to pass those weights using the `data_weight` parameter and 2) I am uncertain on how to combine with `save_idx` as I haven’t observed all the entries of `y`. Here is a toy example:

``````using DifferentialEquations, DiffEqParamEstim, RecursiveArrayTools, BlackBoxOptim

#This is a toy example
function f(du,u,p,t)
du[1] = dx = p[1]*u[1] - u[2]
du[2] = dy = -3*u[2] + u[3]
du[3] = dz = -u[3] + u[1]
end

u0 = [1.0;1.0;1.0]
tspan = (0.0,10.0)
p = [1.5]
prob = ODEProblem(f,u0,tspan,p)
sol = solve(prob, Tsit5())
t = collect(range(0,stop=10,length=200))
randomized = VectorOfArray([(sol(t[i]) + .01randn(3)) for i in 1:length(t)])
data = convert(Array,randomized)[[1,3],:] #Keep only 1st and third for example

#Here I am uncertain on whether which way to structure the weights is correct
w1             = 0.5 #weights for u[1]
w3             = 100.0 #weights for u[3]
weights1   = [repeat([w1], size(data)[2]); repeat([w3], size(data)[2])]
weights2   = hcat(repeat([w1], size(data)[2]), repeat([w3], size(data)[2]))'

#This seems to work
loss = build_loss_objective(prob, Tsit5(), L2Loss(t,data; data_weight = weights1),
save_idxs = [1,3])
prob_bb  = bboptimize(loss, SearchRange = (0.0,100.0), NumDimensions = 1)

#This ALSO seems to work however returns a different fitness
loss = build_loss_objective(prob, Tsit5(), L2Loss(t,data; data_weight = weights2),
save_idxs = [1,3])
prob_bb  = bboptimize(loss, SearchRange = (0.0,100.0), NumDimensions = 1)

``````

Just use DiffEqFlux.jl for this. More flexibility in the loss function that way.