These examples are from the slides of various tutorials on ProbLog, e.g., at IJCAI 2015
The following example illustrates ProbLog’s use of stochastic memoization. We first define a predicate p5 that for a number N given as its first argument, randomly sets its second argument M to either N+5 or N. We then apply this function to every element of a given list of numbers.
The version above reuses the previous, memoized, decision if it encounters the same number again. We can avoid this by adding a third argument to the basic function (sometimes called a “trial identifier”), and making sure that this argument differs at every call (here, by using the rest of the input list as identifier).