Generalizing to unseen domains via distribution matching