Information

Entropy and expected information gain in micro-bits (1_000_000 is one bit). Every figure is an integer: log2 is exact for powers of two and otherwise within 2 micro-bits of the true value (the error of FixedPoint.ln plus one division rounded to nearest), and each entropy term is rounded to nearest, ties up.

Functions

Link copied to clipboard
fun branches(prior: Belief, table: OutcomeTable): List<Branch>

One branch per outcome with its probability and the posterior after seeing it. Bayes over integers: joint = prior times likelihood, then largest-remainder normalization, so both the probabilities and each posterior sum to exactly 1_000_000. An outcome no hypothesis can produce has probability 0 and leaves the prior unchanged.

Link copied to clipboard
fun entropy(probabilities: List<Long>): Long

-sum p log2 p over probabilities (micro-units); zero masses add nothing.

Link copied to clipboard
fun gain(prior: Belief, table: OutcomeTable): Long

fun gain(prior: Belief, branches: List<Branch>): Long

Prior entropy minus the expected posterior entropy over branches; never negative.

Link copied to clipboard
fun log2(p: Long): Long

log2(p / 1_000_000) in micro-bits for 0 < p <= 1_000_000; zero or negative.