Heterogeneous Models with Learning and Homoclinic Bifurcations