feat: prettify normal prediction
This commit is contained in:
parent
22eb848911
commit
599340fd45
BIN
src/jit_bayes
BIN
src/jit_bayes
Binary file not shown.
|
@ -2,6 +2,7 @@ import print
|
||||||
import strutils
|
import strutils
|
||||||
import sequtils
|
import sequtils
|
||||||
import std/sugar
|
import std/sugar
|
||||||
|
import std/algorithm
|
||||||
|
|
||||||
## Get sequences
|
## Get sequences
|
||||||
let file_path = "../data/stripped"
|
let file_path = "../data/stripped"
|
||||||
|
@ -54,7 +55,14 @@ proc findIndex(xs: seq[string], y: string): int =
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
## Do simple predictions
|
## Do simple predictions
|
||||||
proc predictContinuation(seqs: seq[seq[string]], start: seq[string]): int =
|
proc compareTuple (x: (string, float), y: (string, float)): int =
|
||||||
|
let (_, p1) = x
|
||||||
|
let (_, p2) = y
|
||||||
|
if p1 < p2: return -1
|
||||||
|
elif p2 > p2: return 1
|
||||||
|
else: return 0
|
||||||
|
|
||||||
|
proc predictContinuation(seqs: seq[seq[string]], start: seq[string]): seq[(string, float)] =
|
||||||
let continuations = getSequencesWithStart(seqs, start)
|
let continuations = getSequencesWithStart(seqs, start)
|
||||||
let l = start.len
|
let l = start.len
|
||||||
var nexts: seq[string]
|
var nexts: seq[string]
|
||||||
|
@ -68,11 +76,15 @@ proc predictContinuation(seqs: seq[seq[string]], start: seq[string]): int =
|
||||||
else:
|
else:
|
||||||
ps[i] = ps[i] + 1.0
|
ps[i] = ps[i] + 1.0
|
||||||
let sum = foldl(ps, a + b, 0.0)
|
let sum = foldl(ps, a + b, 0.0)
|
||||||
echo nexts
|
ps = ps.map( p => p/sum)
|
||||||
echo ps
|
var next_and_ps = zip(nexts, ps)
|
||||||
echo ps.map(p=> p/sum)
|
# next_and_ps = sort(next_and_ps, compareTuple)
|
||||||
return 1
|
sort(next_and_ps, compareTuple)
|
||||||
# to do: wrangle this in some kind of sequence of tuples, e.g., using some zip type of thing.
|
# ^ sorts in place
|
||||||
|
# also, openArray refers to both arrays and sequences.
|
||||||
|
return next_and_ps
|
||||||
|
|
||||||
var start = @["1", "2", "3", "4", "5", "6"]
|
var start = @["1", "2", "3", "4", "5", "6"]
|
||||||
echo predictContinuation(seqs, start)
|
|
||||||
|
print "Full prediction with access to all hypotheses:"
|
||||||
|
print predictContinuation(seqs, start)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user