Skip to content

Instantly share code, notes, and snippets.

@clbarnes
Created February 22, 2016 22:18
Show Gist options
  • Save clbarnes/63d733bdeeaa56e09444 to your computer and use it in GitHub Desktop.
Save clbarnes/63d733bdeeaa56e09444 to your computer and use it in GitHub Desktop.
from problog.tasks import sample
from problog.program import PrologString
modeltext = """
my_uniform(0,10)::a.
0.5::b.
c :- value(a, A), A >= 3; b.
query(a).
query(b).
query(c).
"""
import random
import math
# Define a function that generates a sample.
def integer_uniform(a, b):
return math.floor(random.uniform(a, b))
model = PrologString(modeltext)
# Pass the mapping between name and function using the distributions parameter.
result = sample.sample(model, n=3, format='dict', distributions={'my_uniform': integer_uniform})
print(list(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment