step: add second infrabayesianism step.
This commit is contained in:
parent
00619aa0fb
commit
ef34fb34fa
|
@ -192,11 +192,53 @@ proc miniInfraBayes(
|
|||
echo "And hence a loss of ", new_loss
|
||||
echo "Total loss is: ", foldl(losses, a + b, 0.0)
|
||||
|
||||
proc getEvens(xs: seq[string]): seq[string] =
|
||||
var evens: seq[string]
|
||||
for i,x in xs:
|
||||
if i%2 == 0:
|
||||
evens.add(x)
|
||||
return evens
|
||||
|
||||
## Infrabayesianism. Part 1: Have hypotheses over just part of the world.
|
||||
proc getOdds(xs: seq[string]): seq[string] =
|
||||
var odds: seq[string]
|
||||
for i,x in xs:
|
||||
if i%2 == 1:
|
||||
odds.add(x)
|
||||
return odds
|
||||
|
||||
proc miniInfraBayes2(
|
||||
seqs: seq[seq[string]],
|
||||
observations: seq[string],
|
||||
n_observations_seen: int,
|
||||
utility_function: string
|
||||
) =
|
||||
if utility_function != "logloss":
|
||||
echo "miniInfraBayes function only programmed for the logloss utility function"
|
||||
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. This time with a twist: You don't have hypotheses over the sequences you observe, but rather over their odd and even position, i.e., you think that you observe interleaved OEIS sequences, (a1, b1, a2, b2, a3, b3). See the README.md for more."
|
||||
|
||||
## Infrabayesianism. Part 2: Take the infimum over the possible loss.
|
||||
var losses: seq[float]g
|
||||
for i in n_observations_seen..<observations.len:
|
||||
var parity_subsequence: seq[string]
|
||||
if i % 2 == 0:
|
||||
parity_subsequence = getEvens(observations[0..<i])
|
||||
else:
|
||||
parity_subsequence = getOdds(observations[0..<i])
|
||||
let predictions = predictContinuation(seqs, parity_subsequence)
|
||||
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)
|
||||
|
||||
## Display outputs
|
||||
echo ""
|
||||
|
|
Loading…
Reference in New Issue
Block a user