-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlosses.jl
34 lines (28 loc) · 890 Bytes
/
losses.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
function loss_seq(p, re, x, y)
m = re(p)
LTC.reset_state!(m, p) # use initial conditions from current params
ŷb = Flux.Zygote.Buffer([y[1]], size(y,1))
for i in 1:size(x,1)
xi = x[i]
ŷi = m(xi)
Inf32 ∈ ŷi && return Inf32, copy(ŷb), y # TODO: what if a layer after MTKRecur can handle Infs?
ŷb[i] = ŷi
end
ŷ = copy(ŷb)
# mean(sum.(abs2, (ŷ .- y))), ŷ, y
return mean(Flux.Losses.mse.(ŷ,y, agg=mean)), ŷ, y
end
function loss_seq(p, m::FastChain, x, y)
# ŷ = m.(x, [p])
LTC.reset_state!(m, p)
ŷb = Flux.Zygote.Buffer([y[1]], size(y,1))
for i in 1:size(x,1)
xi = x[i]
ŷi = m(xi, p)
Inf32 ∈ ŷi && return Inf32, copy(ŷb), y # TODO: what if a layer after MTKRecur can handle Infs?
ŷb[i] = ŷi
end
ŷ = copy(ŷb)
# mean(sum.(abs2, (ŷ .- y))), ŷ, y
return mean(Flux.Losses.mse.(ŷ,y, agg=mean)), ŷ, y
end