A Cognitive Framework for Learning by Imitation