implemented dynamic programming for integrating over the path likelihood