Urn-ball Model with Poisson Prior

Urn-ball model from http://www.eecs.berkeley.edu/Pubs/TechRpts/2015/EECS-2015-12.pdf. In this model, there is a urn with balls of two colors, green and blue. The number of balls is a priori unknown and modelled using a uniform distribution. After two times drawing a ball and observing that it is green, the query is to infer the amount of balls that are present in the urn.

:- use_module(library(lists)). num_balls(X) :- findall(N, between(1,4,N), L), select_uniform(nb, L, X, _). 0.9::color(Ball, blue); 0.1::color(Ball, green). draw_ball(D, C) :- num_balls(TBs), findall(Bs, between(1,TBs,Bs), L), select_uniform(D, L, B, _), color(B, C). evidence(draw_ball(0, green)). evidence(draw_ball(1, green)). query(num_balls(_)).

The original example uses a Poission distribution as the prior. If you want to use another distribution than the uniform distribution, you can use ProbLog’s Python integration to link with any other distribution. For example, the Poisson distribution from SciPy:

"""mypoisson.py"""
from scipy.stats import poisson
from problog.extern import problog_export

@problog_export('+list', '+int', '-list')
def poisson_probs(values, k):
    probs = poisson.pmf(values, k)
    total = sum(probs)
    # Translate np.float to Python native floats
    return [float(prob/total) for prob in probs]
% urnball_poisson.pl
:- use_module('mypoisson.py').
:- use_module(library(lists)).

num_balls(X) :-
    findall(N, between(1,3,N), L),
    poisson_probs(L, 2, Probs),
    select_weighted(0, Probs, L, X, _).

0.9::color(Ball, blue); 0.1::color(Ball, green).

draw_ball(D, C) :-
    num_balls(TBs),
    findall(Bs, between(1,TBs,Bs), L),
    select_uniform(D, L, B, _),
    color(B, C).

    query(num_balls(_)).
    evidence(draw_ball(0, green)).
    query(draw_ball(1, green)).