{
 "library": "brainference",
 "version": "1.0.0",
 "root": "8d7193fc97804cdc3aa9080728d8094732206c114f34d36b8ca2b89b943b3990",
 "license": null,
 "slug": "JensenShannonDivergence",
 "ref": "JensenShannonDivergence#b3b4",
 "hash": "sema:JensenShannonDivergence#mh:SHA-256:b3b4314fee746b1e97b133372bcdb1d9dd1a3a98f90fd19ca19bb47dfef04a6b",
 "stub": "b3b4",
 "layer": "Infrastructure",
 "type": "Primitives",
 "summary": "A symmetric, bounded distance between two distributions, built from their mixture",
 "mechanism": "The Kullback-Leibler divergence D_KL(P||Q) = sum_i p_i log(p_i/q_i) measures the information lost when Q approximates P, but it is asymmetric and infinite wherever q_i = 0 and p_i > 0, which empirical histograms with unseen states often produce. The Jensen-Shannon divergence fixes this by comparing both distributions to their mixture M = (P+Q)/2: D_JS = 1/2 D_KL(P||M) + 1/2 D_KL(Q||M). Equivalently D_JS = ShannonEntropy#a177(M) - (H(P)+H(Q))/2. With log base 2 it is symmetric, always finite and bounded in [0, 1], and zero only when P = Q. Typical use: compare an empirical distribution with a null-model distribution over the same state space, so the value reads as distance from the baseline.",
 "invariants": [
  "D_JS(P,Q) = D_JS(Q,P)",
  "0 <= D_JS <= 1 with log base 2",
  "D_JS = 0 if and only if P = Q",
  "Both distributions are defined over the same state space"
 ],
 "parameters": {},
 "signature": [],
 "preconditions": [],
 "postconditions": [],
 "failure_modes": [
  "Comparing distributions built on different state spaces or binnings",
  "A non-monotonic response: distance from a central reference rises for deviations in either direction (e.g. attraction and repulsion both raise D_JS from a uniform baseline), so the value alone does not say which way the system deviates",
  "Small samples inflate D_JS between two draws of the same process"
 ],
 "domain": "",
 "caution": "",
 "sources": [
  {
   "kind": "thesis",
   "id": "do_2026_ant_collective_behavior",
   "note": "Ch. 1.3.3, Eqs. 1.10-1.11; Ch. 3.1.1, Eqs. 3.2-3.3, Fig. 3.3"
  }
 ],
 "name": "JensenShannonDivergence",
 "builds_on": [
  {
   "alias": "shannon_entropy",
   "relation": "references",
   "library": "brainference",
   "slug": "ShannonEntropy",
   "ref": "ShannonEntropy#a177",
   "url": "https://semahash.org/vocabularies/brainference/patterns/ShannonEntropy"
  }
 ],
 "related": [],
 "used_by": [
  {
   "slug": "LocalSpatialStateDivergence",
   "relation": "composes_with",
   "url": "https://semahash.org/vocabularies/brainference/patterns/LocalSpatialStateDivergence"
  },
  {
   "slug": "NullModelBaseline",
   "relation": "composes_with",
   "url": "https://semahash.org/vocabularies/brainference/patterns/NullModelBaseline"
  }
 ],
 "url": "https://semahash.org/vocabularies/brainference/patterns/JensenShannonDivergence",
 "md_url": "https://semahash.org/vocabularies/brainference/patterns/JensenShannonDivergence.md",
 "library_url": "https://semahash.org/vocabularies/brainference"
}
