Skip to main content

Table 2 Algorithm for updating model parameters

From: Meta-learning prediction of physical and chemical properties of magnetized water and fertilizer based on LSTM

Algorithm 1 Meta-Learning Regression Model

Input: MAML with parameters \(\theta\), Base-Learner with step size hyperparameter \(\alpha\), Meta-Learner with step size hyperparameter \(\beta\)

\(\theta_{0}\)\(\leftarrow\) random initialization #Randomly initialize model parameters

while not done do

\(D_{train}\), \(D_{test}\)\(\leftarrow\) random datasets

for all \({\text{T}}_{{\text{i}}}\) do

\(x_{j}\), \(y_{j}\)\(\leftarrow\) random batch from support set

\(L \leftarrow L_{{T_{i} }} \left( {f_{\theta } } \right)\)#Get loss using Eq. (3)

\(g \leftarrow \nabla_{\theta } L_{{T_{i} }} \left( {f_{\theta } } \right)\)#Evaluate gradient with respect to parameters \(\theta\)

\(\theta_{i}^{{\prime}} \leftarrow \theta - \alpha \nabla_{\theta } L_{{T_{i} }} \left( {f_{\theta } } \right)\)#Update Meta-Learner parameters

end for

\(X\), \(Y\)← random batch from quest set

Update \(\theta \leftarrow \theta - \theta_{i}^{{\prime}} \leftarrow \beta \nabla_{\theta } \sum\limits_{{T_{i} \sim P(T)}} {L_{{T_{i} }} \left( {f_{{\theta_{i}^{{\prime}} }} } \right)}\) #Update Base-Learner parameters

end while