Algorithms for Learning the Structure of Monotone and Nonmonotone Sum-Product Networks