Learning hierarchical behaviors