A Unified Approach for Learning the Parameters of Sum-Product Networks