Abstract Our work aims at developing a robust discriminant controller for robot programming by demonstration. It addresses two core issues of imitation learning, namely what to imitate and how to imitate. This paper presents a method by which a robot extracts the goals of a demonstrated task and determines the imitation strategy that satis es best these goals. The method is validated in a humanoid platform, taking inspiration of an in uential experiment from developmental psychology.