CS230 — Original on-site preparation
Independent written study. All essential explanations and optional model reasoning for this chapter are on this page. References are optional further study. No degree, professional approval or observed competence is conferred.
Information measures require actual probability distributions
For a discrete outcome of positive probability p, self-information is −log₂p bits. A probability-one outcome carries zero surprise under that model; an outcome assigned probability 1/8 carries three bits. Entropy averages this quantity over outcomes: H(P)=−Σpᵢlog₂pᵢ. Define a zero-probability contribution as zero by continuity, rather than discarding arbitrary invalid numbers. A finite k-category distribution has entropy between zero and log₂k, with the upper bound attained by equal probabilities. This measures modeled uncertainty, not truth, usefulness or human understanding.
A fictional job-type distribution P=[1/2,1/4,1/4] has entropy (1/2)×1+(1/4)×2+(1/4)×2=1.5 bits. Under an equal three-category coding model Q=[1/3,1/3,1/3], cross-entropy CE(P,Q)=−Σpᵢlog₂qᵢ=log₂3≈1.584963 bits. It is the average log penalty when observations follow P and predictions use Q. Its excess over H(P) is approximately .084963 bits. Entropy can be understood as an idealized asymptotic coding limit; it need not be an integer length assigned to each individual symbol.
Kullback–Leibler divergence D(P||Q)=Σpᵢlog₂(pᵢ/qᵢ) equals CE(P,Q)−H(P). It is nonnegative for valid normalized distributions on the same outcome space, and zero precisely when the distributions agree. It is generally asymmetric and is not a metric satisfying all ordinary distance axioms. If pᵢ>0 but qᵢ=0, the divergence and cross-entropy are infinite. A numerical implementation must handle that support mismatch explicitly. Taking an absolute value does not repair an invalid negative result, and skipping NaNs can conceal negative inputs or malformed probabilities.
For P=[.75,.25] and Q=[.5,.5], D(P||Q)=.75log₂1.5+.25log₂.5≈.188722 bits. In reverse, D(Q||P)=.5log₂(2/3)+.5log₂2≈.207519 bits. These different values illustrate directionality using genuine distributions. A list of sampled normal observations contains measurements, potentially negative ones; it is not a list of category probabilities. Sorting those observations and inserting them into a discrete KL formula does not estimate divergence between normal distributions. Construct justified densities, probabilities or a suitable estimator instead.
Joint, conditional and mutual information
A joint probability table describes paired outcomes. Derive each marginal by summing the appropriate rows or columns; do not supply unrelated vectors. Joint entropy averages −log₂p(x,y). Conditional entropy H(Y|X) averages the entropy of Y's conditional distributions using the actual probabilities of X. For discrete variables, H(X,Y)=H(X)+H(Y|X). Mutual information I(X;Y)=Σx,y p(x,y)log₂[p(x,y)/(p(x)p(y))] equals H(X)+H(Y)−H(X,Y). It is nonnegative and vanishes for independence. A pointwise log ratio can be negative; nonnegativity applies to its correctly weighted average.
If X is a fair binary variable and Y is an exact copy, the joint table has .5 at (0,0) and .5 at (1,1). Both marginal entropies are one bit, joint entropy is one, conditional entropy is zero and mutual information is one. If Y is an independent fair bit, all four joint cells are .25: joint entropy is two, conditional entropy is one and mutual information is zero. A duplicate field therefore contributes no new information despite occupying another column. Mutual information concerns dependence, including nonlinear dependence; it does not identify a causal direction.
Relate the measure to learning and its limits
For a categorical label y and predicted probability vector q, one-example cross-entropy in natural units is −ln q[y]. Average it over a declared evaluation sample to obtain empirical mean negative log-likelihood. For target labels [0,1] and predictions [.8,.2] and [.4,.6], the mean is −ln(.8×.6)/2≈.366985 nats. State whether a report uses a sum or mean, and natural or base-two logarithms. Perplexity is exp(mean loss) for natural logs, or 2 raised to mean loss in bits. Comparisons require the same outcomes, tokenization, weighting and test population; lower loss is not a guarantee that every decision improved.
Differential entropy h(X)=−∫f(x)log f(x)dx describes densities and differs from discrete entropy. It can be negative and changes with coordinates: for nonzero a, h(aX)=h(X)+log|a| when defined. For a uniform density on an interval of length 1/4, differential entropy in bits is log₂(1/4)=−2. Discrete joint-entropy lower bounds cannot be transplanted without checking their continuous hypotheses. KL divergence compares corresponding distributions under a common change of coordinates; individual differential entropies need not be invariant.
Optional changed record: verify the inputs before interpreting a number
Change the job-type distribution to P=[1/2,1/2,0], retaining uniform Q. Calculate entropy, cross-entropy and KL. Then replace Q with [.5,.5,0]. Finally suppose Y=X for a biased binary X with probability .25 of one. Determine mutual information.
The changed P has entropy one bit. Against uniform Q, cross-entropy remains log₂3, so KL is log₂3−1≈.584963 bits. Against Q=P, only the two positive-support outcomes contribute, giving cross-entropy one and KL zero. The shared zero category contributes zero; it is not an infinite mismatch. If instead P assigned positive mass there while Q stayed zero, the divergence would be infinite. For the copied biased bit, H(X)=−.25log₂.25−.75log₂.75≈.811278 bits, joint entropy equals that value and conditional entropy is zero. Mutual information is therefore .811278, not one: a perfect copy shares all of the available uncertainty, which need not be one bit.
Optional criteria: validate support and normalization; retain the chosen logarithm units; derive marginals and distinguish pointwise from average information; explain why a computed loss or dependence measure does not establish truth or causality. Award one point for each fully explained criterion.
Optional source references
These sources support the explanations; reading them is optional. Original Academy examples are fictional. Historical attributed readings remain preserved.