Implementing inference algorithm for SPN