Behavior cloning is a fundamental imitation learning approach where an agent learns to replicate expert behavior from demonstration data. Given a dataset of state-action pairs collected from an expert, the goal is to learn a policy that maps states to actions.
Implement a function that performs behavior cloning with a linear policy using gradient descent on mean squared error (MSE) loss.
Setup:
predicted_action = states @ W + bW and bias b are initialized to zerosInputs:
expert_states: numpy array of shape (N, D) containing N expert state observations with D featuresexpert_actions: numpy array of shape (N,) containing the corresponding scalar expert actionstest_states: numpy array of shape (M, D) containing M states to predict actions forlr: learning rate for gradient descent (float)epochs: number of training iterations (int)Output: A dictionary with:
'predicted_actions': a list of M predicted scalar actions for the test states'final_loss': the MSE loss evaluated on the training data after all epochs of training