@@ -6,24 +6,27 @@ using Random
66using LuxCore
77using CSV, DataFrames
88using EasyHybrid. MLUtils
9-
9+ using EasyHybrid. AxisKeys
10+ using Zygote
1011# data
11- df = CSV. read (" /Users/lalonso/Documents/HybridML/data/Rh_AliceHolt_forcing_filled.csv" , DataFrame)
12+ df_o = CSV. read (" /Users/lalonso/Documents/HybridML/data/Rh_AliceHolt_forcing_filled.csv" , DataFrame)
1213
14+ df = copy (df_o)
1315df[! , :Temp ] = df[! , :Temp ] .- 273.15 # convert to Celsius
14- df_forcing = filter (:Respiration_heterotrophic => ! isnan, df)
16+ # df = filter(:Respiration_heterotrophic => !isnan, df)
17+ rename! (df, :Respiration_heterotrophic => :Rh ) # rename as in hybrid model
1518df_forcing = df
16- ds_k = to_keyedArray (Float32 .(df_forcing))
17- yobs = ds_k (:Respiration_heterotrophic )' [:,:]
19+
20+ ds_p_f = to_keyedArray (Float32 .(df_forcing)) # predictors + forcing
21+ ds_t = ds_p_f ([:Rh ]) # do the array so that you conserve the name
1822
1923NN = Lux. Chain (Dense (2 , 15 , Lux. relu), Dense (15 , 15 , Lux. relu), Dense (15 , 1 ));
2024# ? do different initial Q10s
21- RbQ10 = RespirationRbQ10 (NN, (:Rgpot , :Moist ), (:Temp ,), 2.5f0 )
25+ RbQ10 = RespirationRbQ10 (NN, (:Rgpot , :Moist ), (:Rh , ), ( : Temp ,), 2.5f0 )
2226
2327# ? play with :Temp as predictors in NN, temperature sensitivity!
2428# TODO : variance effect due to LSTM vs NN
25-
26- out = train (RbQ10, (ds_k ([:Rgpot , :Moist , :Temp ]), yobs), (:Q10 , ); nepochs= 1000 , batchsize= 512 , opt= Adam (0.01 ));
29+ out = train (RbQ10, (ds_p_f, ds_t), (:Q10 , ); nepochs= 1000 , batchsize= 512 , opt= Adam (0.01 ));
2730
2831
2932with_theme (theme_light ()) do
@@ -39,10 +42,10 @@ with_theme(theme_light()) do
3942 fig = Figure (; size = (1200 , 600 ))
4043 ax_train = Makie. Axis (fig[1 , 1 ], title = " training" )
4144 ax_val = Makie. Axis (fig[2 , 1 ], title = " validation" )
42- lines! (ax_train, out. ŷ_train[:], color= :orangered , label = " prediction" )
45+ lines! (ax_train, out. ŷ_train. Rh [:], color= :orangered , label = " prediction" )
4346 lines! (ax_train, out. y_train[:], color= :dodgerblue , label = " observation" )
4447 # validation
45- lines! (ax_val, out. ŷ_val[:], color= :orangered , label = " prediction" )
48+ lines! (ax_val, out. ŷ_val. Rh [:], color= :orangered , label = " prediction" )
4649 lines! (ax_val, out. y_val[:], color= :dodgerblue , label = " observation" )
4750 axislegend (; position= :lt )
4851 Label (fig[0 ,1 ], " Observations vs predictions" , tellwidth= false )
@@ -62,22 +65,20 @@ with_theme(theme_light()) do
6265end
6366
6467
65- ds_k = to_keyedArray (Float32 .(df))
66- yobs_all = ds_k (:Respiration_heterotrophic )' [:,:]
68+ yobs_all = ds_p_f (:Rh )
6769
68- ŷ, RbQ10_st = LuxCore. apply (RbQ10, ds_k , out. ps, out. st)
70+ ŷ, RbQ10_st = LuxCore. apply (RbQ10, ds_p_f , out. ps, out. st)
6971
7072with_theme (theme_light ()) do
7173 fig = Figure (; size = (1200 , 600 ))
7274 ax_train = Makie. Axis (fig[1 , 1 ], title = " full time series" )
73- lines! (ax_train, ŷ[:], color= :orangered , label = " prediction" )
75+ lines! (ax_train, ŷ. Rh [:], color= :orangered , label = " prediction" )
7476 lines! (ax_train, yobs_all[:], color= :dodgerblue , label = " observation" )
7577 axislegend (ax_train; position= :lt )
7678 Label (fig[0 ,1 ], " Observations vs predictions" , tellwidth= false )
7779 fig
7880end
7981
80-
8182# ? Rb
8283lines (out. αst_train. Rb[:])
83- lines! (ds_k (:Moist )[:])
84+ lines! (ds_p_f (:Moist )[:])
0 commit comments