X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=expr.py;h=f294d6874451c0ff6101d4a299c9b44c76595dd7;hb=a8f039a9b491b1b4b47f6b9f8123c7261e758661;hp=8690504d81d63820d1f450f3b357302497759df6;hpb=62e273047aee0a1d606fbe0312abc16a74d23906;p=picoclvr.git diff --git a/expr.py b/expr.py index 8690504..f294d68 100755 --- a/expr.py +++ b/expr.py @@ -45,10 +45,6 @@ def generate_program(nb_variables, length): s = "" variables = set() - # We take length itself half of the time, and uniform between 1 - # and length otherwise. The actual length can be slightly greater - - length = min(length, 1 + torch.randint(length * 2, (1,)).item()) while len(s) < length: v = random_var(nb_variables=nb_variables) s += v + "=" + random_expr(variables, budget=20) + ";" @@ -70,10 +66,15 @@ def generate_sequences(nb, nb_variables=5, length=20): assert nb_variables <= 26 sequences = [] result_max = 99 + for n in range(nb): + # We take length itself half of the time, and uniform between + # 1 and length otherwise. The actual length can be slightly + # greater + + l = min(length, 1 + torch.randint(length * 2, (1,)).item()) result = None while result == None or max(result.values()) > result_max: - l = length p, v = generate_program(nb_variables, l) v = ", ".join(['"' + v + '": ' + v for v in v]) ldict = {}