Phase diagram of restricted Boltzmann machines and generalized Hopfield networks with arbitrary priors