Like Humans, Artificial Minds can ‘Learn by Thinking’