# No method matching loss\_multiple\_shooting

**URL:** <https://discourse.julialang.org/t/no-method-matching-loss-multiple-shooting/60445>\
**Category:** General Usage\
**Created:** [May 3, 2021, 2:21am UTC](https://discourse.julialang.org/t/no-method-matching-loss-multiple-shooting/60445 "2021-05-03T02:21:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![raj6798](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raj6798/32/24680_2.png) [@raj6798](https://discourse.julialang.org/u/raj6798)\
**Post date:** [May 3, 2021, 2:21am UTC](https://discourse.julialang.org/t/no-method-matching-loss-multiple-shooting/60445/1 "2021-05-03T02:21:30Z")

</div>

using DataDrivenDiffEq  
using DiffEqFlux, Flux  
using Plots  
path = @ **DIR**  
include(“multipleshooting.jl”)

## Mutliple shoot function

#include(“Multiple\_shooting1.jl”)

## generating possible basis

@variables x[1:ns] # variables used to create polynomial\_basis  
polys = polynomial\_basis(x,2)[2:end]  
f\_polys = build\_function(polys, x, expression = Val{false})[1]  
λ(x,p) = f\_polys(x)

NN = FastChain(λ, FastDense(length(polys), ns;  
initW = Flux.sparse\_init(sparsity=0.8)))

solver = Tsit5();  
prob\_neuralode = NeuralODE(NN, tspan, solver, saveat = tsteps)  
neural\_ode\_f(u,p,t) = NN(u,p)  
prob\_nn = ODEProblem(neural\_ode\_f, u0\_list[1,:], tspan,  
initial\_params(NN))

## training

function plot\_function\_for\_multiple\_shoot(plt, pred, grp\_size)  
step = 1  
if(grp\_size != 1)  
step = grp\_size-1  
end  
if(grp\_size == datasize)  
Plots.scatter!(plt, tsteps, pred[1][1,:], label = “pred”)  
else  
for i in 1:step:datasize-grp\_size  
# The term `trunc(Integer,(i-1)/(grp_size-1)+1)` goes from 1, 2, … , N where N is the total number of groups that can be formed from `ode_data` (In other words, N = trunc(Integer, (datasize-1)/(grp\_size-1)))  
Plots.scatter!(plt, tsteps[i:i+step], pred[trunc(Integer,(i-1)/step+1)][1,:], label = “grp”\*string(trunc(Integer,(i-1)/step+1)))  
end  
end  
end

statesvar = string.(species(rn))  
callback = function (p, l, pred; doplot = true)  
display(l)

```
 if doplot
  	list_plt = []
	for spec in 1:ns
		plt = Plots.scatter(tsteps[1:size(pred,2)],
						ode_data[spec,1:size(pred,2)],
						markercolor=:transparent, label="Data",
						framestyle=:box)
		## plot the different predictions for individual shoot
		# plot_function_for_multiple_shoot(plt, predictions, grp_size_param)
		# plot a single shooting performance of our multiple shooting training (this is what the solver predicts after the training is done)
		plot!(plt, tsteps[1:size(pred,2)], pred[spec,:], lw=3,
								label = "ODENet prediction")
		plot!(xlabel="Time(sec)",
				ylabel="Concentration of " * statesvar[spec])
		if spec == 1
	   		plot!(plt, legend=true, framealpha=0)
   		else
	   		plot!(plt, legend=false)
		end
		push!(list_plt, plt)
    end

	plt_all = plot(list_plt...)
	display(plt_all)

  # png(plt_all, string(path,"/figs/i_exp_", i))
end
return false

```

end

# Define parameters for Multiple Shooting

grp\_size\_param = 3;  
loss\_multiplier\_param = 100

function loss\_function(ode\_data, pred):: Float32  
return sum(abs2, (ode\_data - pred)) #+ μ\*sum(abs, ps)  
end

function loss\_multiple\_shooting(p)  
return multiple\_shoot1(p, ode\_data ,tsteps, prob\_nn,  
loss\_function, solver, grp\_size\_param;  
loss\_multiplier\_param=100)  
end

ps = prob\_neuralode.p

## hyperparameter tuning–

# take one trajectory, ..see how loss decreases for set of

# μ = [0.1, 1, 5, 10,100]

## 

for i in randperm(n\_exp\_train)  
ode\_data = ode\_data\_list\_noise[i,:,:]

```
result_neuralode = DiffEqFlux.sciml_train(loss_multiple_shooting,ps,ADAM(0.01),maxiters = 300)
ps = result_neuralode.minimizer

```

end

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [May 3, 2021, 11:55am UTC](https://discourse.julialang.org/t/no-method-matching-loss-multiple-shooting/60445/2 "2021-05-03T11:55:07Z")

</div>

Welcome to the Julia discourse.

I am not familiar with machine learning libraries, but a quick check of the [docs](https://diffeqflux.sciml.ai/v1.34/examples/augmented_neural_ode/#Loss-Functions-1) suggests that the loss function should take 2 arguments.

A general note: It is easier for others to help you if you follow some [suggestions](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757). In particular, a MWE with a complete error message would be useful.
