I am Trying to model some temperature curves with a physically informed NN (PINN).
I the physical model I am trying to apply is an FOPDT.
NN = Chain(
Dense(1 => 32, tanh),
Dense(32 => 32, tanh),
Dense(32 => 1) |> gpu)
function lossₚ(i, y)
run = floor(Int, i / 130)
i₀ = run * 130
iᵣ = i - i₀
U = (iᵣ < 60) ? 100 : 0
# currently from scipy.optimize fsolve
Κ = 66.3
τ = 145.7
θ = 73.4
yₑ = grad.(y)
yₘ = (.-y .+ Κ .* U .*(i₀ .- θ)) ./ τ
return sum((yₑ .- yₘ) .^2)
end
lossₘ(y_hat, y) = sum((y_hat .- y).^2)
loss_ratio = 1.0 / 5.0
lossₜ(y_hat, y) = (1 - loss_ratio) * lossₘ(y_hat, y)+ loss_ratio * lossₚ(enumerate(y))
train_mask = 1: trunc(Int, length(static_df.T1)//2)
X_train = static_df[train_mask, :Q1]
y_train = static_df[train_mask, :T1]
train_set = [(x, y) for x in X_train, y in y_train]
η = 0.001
opt = Flux.setup(Adam(η), NN)
for epoch in 1:100
Flux.train!(NN, train_set, opt) do m, x, y
lossₜ(m.(x) .+ y_train[1], y)
end
end
beside the normal loss of the MSE I am trying to add a term for the ODE. But I am not so sure how to add the time depened term, that is why I used enumerate. In the training I also add the start condition to the NN.
Current problem is something with the type of the tanh activation function, but I don’t get it.
MethodError: no method matching (::Flux.Dense{typeof(tanh), Matrix{Float32}, Vector{Float32}})(::Float64)
So my detailed questions is how to solve this bug, but I addition I want whether I am god on track, or whether you have any other tip.