ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

KL divergence and its missing support case

For normalized distributions, the sum p log(p/q) measures relative entropy in nats with the file’s natural logarithm. A term with positive p and zero q should make the divergence infinite. The code skips such terms when q is below its cutoff, so it can return a finite…

Implementation mathematicsSource recovered; runtime not executed
Learn with the Atlas

Learn to read this model

Start with the symbols, follow the operations, and check what the result means.

Open guided lesson
gh-eq-77bc875845b752fbsource-comment-equation
KLDivergencecomputesDKL(P∣∣Q)=Σp(x)log(p(x)/q(x))KLDivergence computes D_KL(P||Q) = Σ p(x) log(p(x)/q(x))

Read the equation

For normalized distributions, the sum p log(p/q) measures relative entropy in nats with the file’s natural logarithm. A term with positive p and zero q should make the divergence infinite. The code skips such terms when q is below its cutoff, so it can return a finite value where the mathematical divergence is infinite and can lose its usual nonnegativity guarantee after truncation.

Terms & definitions

TermMeaning in this source
p

First probability distribution

q

Reference distribution

D_KL

Relative entropy

How it works

Read the definition from its right-hand expression to the quantity on the left. Its surrounding source records the intended input, state, or parameter context. Where the source leaves an operation unspecified, this page preserves that gap.

Assumptions & limits

Source recovery establishes that the expression appears in this record. Its mathematical validity, implementation behavior, and interpretation must be assessed separately. See the linked source and research notes for the checks available for this version.

Original context

Read the surrounding source passage
		if p > EPSILON_PHI && p < 1.0-EPSILON_PHI {
			h -= p * math.Log2(p)
		}
	}
	return h
}

// KLDivergence computes D_KL(P||Q) = Σ p(x) log(p(x)/q(x))
func KLDivergence(p, q []float64) float64 {
	if len(p) != len(q) {
		return math.Inf(1)
	}

	kl := 0.0
	for i := range p {
		if p[i] > EPSILON_PHI && q[i] > EPSILON_PHI {
			kl += p[i] * math.Log(p[i]/q[i])
		}
Exact original notation
KLDivergence computes D_KL(P||Q) = Σ p(x) log(p(x)/q(x))

Related builds

Sources & provenance

01
Go mathematical helpers
Lines 91–91 · 33aa84f2aa61
02
Go mathematical helpers
Lines 91–91 · 33aa84f2aa61

Search equations, builds, manuscript text, and recovered sources.