Created
February 22, 2016 22:18
-
-
Save clbarnes/63d733bdeeaa56e09444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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