Model-agnostic meta-learning (MAML) learns a shared initialisation such that a few gradient steps on a new task's training set give good parameters for that task. Use linear-regression tasks with loss
where is the number of rows of . A task is a tuple (X_tr, y_tr, X_va, y_va).
adapt(xi, X, y, inner_lr, inner_steps): run inner_steps steps of gradient descent on from with step size inner_lr; return .
meta_loss_and_grad(xi, tasks, inner_lr, inner_steps, first_order=False): the meta-loss with adapt(xi, X_tr_j, y_tr_j, ...), and its exact gradient with respect to , differentiating through every inner step. With first_order=True return instead the first-order MAML gradient, which treats as the identity. Return (loss, grad) with loss a Python float.
maml_step(xi, tasks, inner_lr, outer_lr, inner_steps, first_order=False): one outer gradient-descent step on the meta-loss; return the new .