diff --git a/src/jit_bayes b/src/jit_bayes index b71bb93..f591f80 100755 Binary files a/src/jit_bayes and b/src/jit_bayes differ diff --git a/src/jit_bayes.nim b/src/jit_bayes.nim index d14ff38..691b3b9 100644 --- a/src/jit_bayes.nim +++ b/src/jit_bayes.nim @@ -51,13 +51,13 @@ proc getOEIS(): seq[seq[string]] = var seqs = getOEIS() ## Sequence helpers -proc startsWithSubsequence(xs: seq[string], ys: seq[string]): bool = - if xs.len == 0: +proc startsWithSubsequence(subseq: seq[string], xs: seq[string]): bool = + if subseq.len == 0: return true - elif ys.len == 0: + elif xs.len == 0: return false - elif xs[0] == ys[0]: - return startsWithSubsequence(xs[1.. seqs.len: num_hypotheses = seqs.len hypotheses = seqs[0.. i) and h[i] == observations[i]) + concordant_hypotheses = filter(hypotheses, proc(h: seq[string]): bool = (h.len > i) and startsWithSubsequence(observations[0..i], h)) if concordant_hypotheses.len > 0: found_concordant_hypothesis = true @@ -157,6 +154,7 @@ proc jitBayesLoop( return else: echo "Increased number of hypotheses to ", num_hypotheses, ", and found ", concordant_hypotheses.len, " concordant hypotheses. Continuing" + ## print concordant_hypotheses else: echo "Correct continuation was ", correct_continuation @@ -168,13 +166,15 @@ proc jitBayesLoop( echo "" ## var observations = @["1", "2", "3", "4", "5", "6"] -var observations = @["1", "2", "3", "23"] + echo "## Full prediction with access to all hypotheses (~Solomonoff)" +var observations = @["1", "2", "3"] echo "## Initial sequence: ", observations let continuation_probabilities = predictContinuation(seqs, observations) print continuation_probabilities echo "" +observations = @["1", "2", "3", "23", "11", "18", "77", "46", "84"] jitBayesLoop(seqs, observations, 3, 1_000, 2_000) echo ""