finalize jit-bayes
This commit is contained in:
parent
218df1179f
commit
90739ce4a8
BIN
src/jit_bayes
BIN
src/jit_bayes
Binary file not shown.
|
@ -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..<xs.len], ys[1..<ys.len])
|
||||
elif subseq[0] == xs[0]:
|
||||
return startsWithSubsequence(subseq[1..<subseq.len], xs[1..<xs.len])
|
||||
else:
|
||||
return false
|
||||
|
||||
|
@ -120,9 +120,6 @@ proc jitBayesLoop(
|
|||
num_hypotheses_step: int,
|
||||
) =
|
||||
print "## Prediction with limited number of hypotheses (~JIT-Bayes)"
|
||||
if n_observations_seen < 1:
|
||||
echo "in jitBayesLoop function, n_observations_seen must be 1 or greater"
|
||||
return
|
||||
|
||||
var num_hypotheses = initial_num_hypotheses
|
||||
var hypotheses = seqs[0..<num_hypotheses]
|
||||
|
@ -143,12 +140,12 @@ proc jitBayesLoop(
|
|||
var concordant_hypotheses: seq[seq[string]]
|
||||
|
||||
while (not found_concordant_hypothesis) and ( num_hypotheses < seqs.len ):
|
||||
echo "Correct continuation not found in set of hypotheses of size ", num_hypotheses, "/", seqs.len, ". Increasing size of the set of hypotheses."
|
||||
echo "Correct continuation, " , correct_continuation, " not found in set of hypotheses of size ", num_hypotheses, "/", seqs.len, ". Increasing size of the set of hypotheses."
|
||||
num_hypotheses = num_hypotheses + num_hypotheses_step
|
||||
if num_hypotheses > seqs.len:
|
||||
num_hypotheses = seqs.len
|
||||
hypotheses = seqs[0..<num_hypotheses]
|
||||
concordant_hypotheses = filter(hypotheses, proc(h: seq[string]): bool = (h.len > 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 ""
|
||||
|
|
Loading…
Reference in New Issue
Block a user