Goal-directed learning of features and forward models