Is it possible to sample a model without having to enumerate all models and then choosing randomly from the set? For instance, suppose the following simple program:
{a; b; c; d; e}.
I'd like to be able to sample k random models from the above program.
I see that parameters --seed=n and --rand-freq=1.0 apparently set some randomness, as the first 5 models are distinct given n, but querying for only one model always returns an empty set.
Further, I can see that the randomness isn't uniform, as some atoms appear significantly more times than others.
More concretely, I guess my question is: is there a way to disable all heuristics and really just return a random model?
Below is what I used to test the uniformity of randomness.
import clingo
import sys
# Number of tries.
n = int(sys.argv[1])
# Number of atoms.
k = int(sys.argv[2])
# Number of samples per try.
s = int(sys.argv[3])
P = "{" + ";".join(f"a{i}" for i in range(k)) + "}."
A = [clingo.parse_term(f"a{i}") for i in range(k)]
N = [0 for _ in range(k)]
print("Program: ", P)
for i in range(n):
C = clingo.Control([f"--seed={i}", "--rand-freq=1.0", sys.argv[3]])
C.add("base", [], P)
C.ground([("base", [])])
with C.solve(yield_ = True) as H:
for M in H:
for i, a in enumerate(A):
if M.contains(a): N[i] += 1
print(N)
Hi,
Is it possible to sample a model without having to enumerate all models and then choosing randomly from the set? For instance, suppose the following simple program:
I'd like to be able to sample
k
random models from the above program.I see that parameters
--seed=n
and--rand-freq=1.0
apparently set some randomness, as the first 5 models are distinct givenn
, but querying for only one model always returns an empty set.Further, I can see that the randomness isn't uniform, as some atoms appear significantly more times than others.
More concretely, I guess my question is: is there a way to disable all heuristics and really just return a random model?
Below is what I used to test the uniformity of randomness.
Running the code above:
Thanks