Optimal structure and parameter learning of Ising models