-
Notifications
You must be signed in to change notification settings - Fork 0
/
20190924_selectedindicesCostfunction.jl
44 lines (36 loc) · 1.42 KB
/
20190924_selectedindicesCostfunction.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Revise; using BenchmarkTools; using DSP
#= test modulus =#
function mod2test(t, params)
return exp.(-t)
end
#= convolution convenience function =#
function boltzconvolve(modulus, time_series, dt, prescribed_dot)
Modulus = modulus(time_series)
β = conv(Modulus, prescribed_dot)
β = β[1:length(time_series)]*dt
end
#= to test =#
function noIndex_objective(params, modulus, time_series, dt, prescribed_dot, measured)
mod = (t->modulus(t,params))
convolved = boltzconvolve(mod, time_series, dt, prescribed_dot)
cost = sum((measured - convolved).^2)
return cost
end
function Index_objective(params, modulus, time_series, dt, prescribed_dot, measured, indices)
mod = (t->modulus(t,params))
convolved = boltzconvolve(mod, time_series, dt, prescribed_dot)
cost = sum((measured - convolved[indices]).^2)
return cost
end
# get signal
dt = 0.01
t = Vector{Float64}(0.0:dt:1000.0)
loading_derivative = -2*(t .- 50)
exact_response = 102 .- 102*exp.(-t) .- 2t
params = ones(5)
# to bench whether function needs to be specialised, use full range of indices
indicestouse = collect(1:length(t))
# in real code, can pass selected indices only
exact_response_indices_only = exact_response[indicestouse]
@btime noIndex_objective($params, $mod2test, $t, $dt, $loading_derivative, $exact_response)
@btime Index_objective($params, $mod2test, $t, $dt, $loading_derivative, $exact_response_indices_only, $indicestouse)