Linear and parallel learning of Markov random fields