step: savepoint & README tweaks
This commit is contained in:
parent
32e8a32e4c
commit
824593accc
Binary file not shown.
|
@ -1,6 +1,7 @@
|
|||
import print
|
||||
import strutils
|
||||
import sequtils
|
||||
import std/math
|
||||
import std/sugar
|
||||
import std/algorithm
|
||||
|
||||
|
@ -125,8 +126,7 @@ proc jitBayesLoop(
|
|||
var num_hypotheses = initial_num_hypotheses
|
||||
var hypotheses = seqs[0..<num_hypotheses]
|
||||
|
||||
let l = observations.len
|
||||
for i in n_observations_seen..<l: # to do: make so that this can start at 0.
|
||||
for i in n_observations_seen..<observations.len:
|
||||
let predictions = predictContinuation(hypotheses, observations[0..<i])
|
||||
echo "### Prediction after seeing ", i, " observations: ", observations[0..<i]
|
||||
print predictions
|
||||
|
@ -161,13 +161,12 @@ proc jitBayesLoop(
|
|||
echo "Correct continuation was ", correct_continuation
|
||||
echo "It was assigned a probability of ", getProbability(predictions[correct_continuation_index])
|
||||
|
||||
echo ""
|
||||
|
||||
## Infrabayesianism
|
||||
|
||||
proc miniInfraBayes(
|
||||
seqs: seq[seq[string]],
|
||||
observations: seq[string],
|
||||
n_observations_seen: int,
|
||||
utility_function: string
|
||||
) =
|
||||
if utility_function != "logloss":
|
||||
|
@ -175,10 +174,23 @@ proc miniInfraBayes(
|
|||
return
|
||||
else:
|
||||
echo "## Mini-infra-bayesianism over environments, where your utility in an environment is just the log-loss in the predictions you make until you become certain that you are in that environment."
|
||||
|
||||
let l = observations.len
|
||||
for i in 0..<l: # to do: make so that this can start at 0.
|
||||
|
||||
var losses: seq[float]
|
||||
for i in n_observations_seen..<observations.len:
|
||||
let predictions = predictContinuation(seqs, observations[0..<i]) ## See the README for why this ends up being equivalent.
|
||||
echo "### Prediction after seeing ", i, " observations: ", observations[0..<i]
|
||||
print predictions
|
||||
let correct_continuation = observations[i]
|
||||
let considered_continuations = predictions.map(prediction => getHypothesis(prediction))
|
||||
let correct_continuation_index = findIndex(considered_continuations, correct_continuation)
|
||||
let p_correct_continuation = getProbability(predictions[correct_continuation_index])
|
||||
let new_loss = ln(p_correct_continuation)
|
||||
losses.add(new_loss)
|
||||
|
||||
echo "Correct continuation was ", correct_continuation
|
||||
echo "It was assigned a probability of ", p_correct_continuation
|
||||
echo "And hence a loss of ", new_loss
|
||||
echo "Total loss is: ", foldl(losses, a + b, 0.0)
|
||||
|
||||
|
||||
## Infrabayesianism. Part 1: Have hypotheses over just part of the world.
|
||||
|
@ -205,6 +217,8 @@ echo ""
|
|||
|
||||
observations = @["1", "2", "3", "23", "11", "18", "77", "46", "84"]
|
||||
jitBayesLoop(seqs, observations, 3, 1_000, 30_000)
|
||||
|
||||
echo ""
|
||||
|
||||
observations = @["1", "2", "3", "23", "11", "18", "77", "46", "84"]
|
||||
miniInfraBayes(seqs, observations, 3, "logloss")
|
||||
echo ""
|
||||
|
|
|
@ -18,6 +18,7 @@ fast:
|
|||
|
||||
deps:
|
||||
nimble install print@1.0.2
|
||||
nimble install https://github.com/CosmicToast/pipe ## backup at github.com/NunoSempere/nim-pipe
|
||||
gzip -d ../data/stripped.gz -c > ../data/stripped
|
||||
|
||||
run: compute_constrained_bayes
|
||||
|
|
Loading…
Reference in New Issue
Block a user