DEV Community

shakti tiwari
shakti tiwari

Posted on

Information Theory in AI — Entropy, KL Divergence & Why Cross-Entropy Is the Default Loss

Information Theory in AI — Entropy, KL Divergence & Why Cross-Entropy Is the Default Loss

By Shakti Tiwari — Nifty Option Trader, Research Analyst & XGBoost Expert. I build ML models for Nifty options on ordinary hardware, and I write these notes so an Indian retail trader can understand AI math without a PhD.

Articles 1–4 covered calculus (steering), linear algebra (language), probability (trust), and optimization (the driver). This one covers information theory — the math of how much a signal is worth. And for a trader, that question — "is this feature even carrying useful information?" — is the entire game.

Information theory, invented by Claude Shannon in 1948, measures uncertainty and surprise. In AI it shows up everywhere: the loss function that trains almost every classifier (cross-entropy), the way models compress data, the way they decide which features matter, and even how they generate text (perplexity). If probability tells you how likely something is, information theory tells you how much you learned by observing it.

This is article 5 of the AI Components series. The index and articles 1–4 live on optiontradingwithai.in.

Direct Answer: What Is Information Theory in AI?

Information theory quantifies information as reduction in uncertainty. A highly surprising event carries a lot of information; a predictable event carries little. In AI this gives us the tools to:

  • Measure impurity in a dataset (entropy) — used by decision trees and XGBoost.
  • Define the standard classification loss (cross-entropy) — what almost every classifier minimizes.
  • Compare two distributions (KL divergence) — used in variational autoencoders, distillation, and calibration.
  • Compress data (the "minimum description length" principle) — why good models are short models.

So: probability tells you the odds; information theory tells you how many bits of insight those odds give you. For a trader, it is the lens that separates a noisy feature from an informative one.

Why a Trader Should Care

If you have ever added a "new signal" that did nothing for your P&L, information theory explains why: the signal carried no new information — it was redundant with what you already had. Three trader-relevant facts:

  1. Mutual information finds real edges. It measures how much one variable tells you about another, ignoring linear correlation. Two assets can have zero correlation but high mutual information (non-linear linkage) — that is where hidden edges live.
  2. Entropy exposes worthless features. A feature with near-equal distribution across outcomes adds little; a feature that sharply splits up/down carries signal. XGBoost's split criterion is literally information gain.
  3. Cross-entropy = honest error. It penalizes confident wrong answers far more than soft ones — exactly the calibration discipline from article 3.

For a retail trader, information theory is the microscope that tells you which of your 50 indicators actually earn their keep.

The Core Ideas

1. Entropy — The Amount of Uncertainty

Entropy H(X) measures the average surprise (information) of a random variable:

H(X) = − Σ P(x) × log₂ P(x)
Enter fullscreen mode Exit fullscreen mode
  • A coin that is always heads (P=1,0) has entropy 0 — no surprise, no information.
  • A fair coin (0.5, 0.5) has entropy 1 bit — maximum uncertainty.
  • A market that closes green 53% / red 47% has low entropy — slightly predictable, slightly informative.

High entropy = hard to predict = more information needed to describe it. Low entropy = predictable = compressible. This is why "predict Nifty" is hard: daily direction has entropy close to 1 bit (near a fair coin), so most of the signal is noise.

2. Information Gain — What a Split Buys You

A decision tree (and XGBoost) asks: which feature reduces entropy the most? Information gain = entropy before − weighted entropy after the split. The feature with the highest gain is chosen. This is pure information theory, running inside every tree I train on Nifty data. When a feature gives near-zero gain, the model ignores it — and so should you.

3. Cross-Entropy — The Default Loss

Cross-entropy measures how well a predicted probability distribution matches the true one:

CE = − Σ true_label × log(predicted_probability)
Enter fullscreen mode Exit fullscreen mode

For binary Nifty-up/down: if true = "up" (1) but model predicts P(up)=0.1, CE = −log(0.1) ≈ 2.3 (high penalty). If model predicts 0.9, CE = −log(0.9) ≈ 0.11 (low penalty). Confident and wrong is punished hardest — exactly what calibration needs (article 3).

This is why cross-entropy is the universal classification loss: it is mathematically the negative log-likelihood (article 3's MLE) and it enforces honesty. Minimizing cross-entropy = maximizing the probability the model assigns to the truth.

4. KL Divergence — Distance Between Distributions

K-L divergence KL(P ‖ Q) measures how much information is lost when Q approximates P:

KL(P‖Q) = Σ P(x) × log( P(x) / Q(x) )
Enter fullscreen mode Exit fullscreen mode
  • KL = 0 → P and Q are identical.
  • KL large → Q is a bad approximation of P.

Used in: knowledge distillation (teacher vs student model), variational autoencoders (match a prior), and calibration (compare predicted vs empirical distribution). It is asymmetric: KL(P‖Q) ≠ KL(Q‖P) — direction matters, unlike a distance.

5. Perplexity — A Language Model's Entropy

For text models, perplexity = 2^(average cross-entropy). Lower = better. It asks: "how surprised is the model, on average, by the next word?" A perplexity of 10 means the model is as uncertain as if choosing among 10 equal words. This is entropy applied to language — and it is how we compare chatbots.

Worked Example: Entropy of a Trading Day

Suppose a strategy's signal gives three outcomes: Big Up (20%), Small Up (30%), Down (50%). Entropy:

H = − [0.2·log₂0.2 + 0.3·log₂0.3 + 0.5·log₂0.5]
  = − [0.2·(−2.32) + 0.3·(−1.74) + 0.5·(−1.0)]
  = − [−0.464 − 0.522 − 0.5]
  = 1.486 bits
Enter fullscreen mode Exit fullscreen mode

Max possible (3 equal outcomes) = log₂3 ≈ 1.585 bits. So this signal carries 1.486/1.585 ≈ 94% of the maximum uncertainty — meaning the signal barely narrows the outcomes. Low information. Compare a signal that produces Up 80% / Down 20%: entropy ≈ 0.72 bits — far more informative, because it sharply splits the world. That is the information-theory view of "which signal is actually good."

Information Theory in XGBoost (My Daily Tool)

XGBoost's splits are chosen by information gain (entropy reduction) or by the gradient/Newton approximation (article 1 + 4). Both are information-theoretic at heart:

  • Each split tries to maximize the purity (minimize entropy) of the child nodes.
  • The covering / gain formula balances reduction in loss against tree complexity — a minimum-description-length idea (simpler tree = less information to store = better generalization).
  • When I add a feature (FII flow, OI change, premium skew), I watch its gain. Near-zero gain = redundant feature; high gain = real information. Information theory is literally my feature-selection tool.
  • In classification mode, XGBoost minimizes log-loss (cross-entropy) — the same honest loss as neural nets.

So the "AI" in my Nifty model is, under the hood, Shannon's 1948 math deciding which questions are worth asking about the data.

Common Mistakes (Information-Theory Related)

  • Adding redundant features — they add entropy to train but no mutual information; overfit, no edge.
  • Ignoring entropy of the target — if Nifty direction ~ fair coin, no model beats it much; manage expectations.
  • Using accuracy instead of cross-entropy — accuracy hides confident errors; CE exposes them.
  • Confusing correlation with mutual information — zero correlation ≠ zero information (non-linear links exist).
  • Treating perplexity as the only LLM metric — it measures surprise, not truth. A fluent liar has low perplexity.

How to Verify Your Features Carry Real Information

  1. Mutual information between each feature and the target — drop near-zero ones.
  2. Information gain per split in your tree — XGBoost reports it; low-gain features are dead weight.
  3. Entropy of target — know the ceiling; if it is ~1 bit, don't expect miracles.
  4. Cross-entropy on validation — not just accuracy; watch confident-wrong penalties.
  5. KL between predicted and empirical distribution — calibration check (article 3 bridge).

Information Theory vs the Other Four

  • Linear algebra moves the data.
  • Calculus computes the gradient.
  • Probability gives the odds.
  • Optimization drives to the minimum.
  • Information theory tells you whether the data is even worth modeling — and defines the loss that makes training honest.

A model can have perfect math but learn nothing if the features carry no mutual information. This component is the trader's filter: before optimizing, ask does this signal reduce entropy?

FAQ

Do I need to compute entropy by hand?

No — libraries do. But you should know what low vs high entropy means for your target and features, or you will waste months on noise.

Is cross-entropy the same as log-loss?

Yes — cross-entropy for class labels equals the negative log-likelihood (log-loss). They are the same honest loss viewed two ways.

Why does my "great" feature not help?

Almost always: it has high correlation with an existing feature (zero mutual information gain) or it is just noise with entropy equal to the target. Information theory exposes both.

Can information theory predict the market?

It tells you how much information your data contains — the ceiling on what any model can learn. If the entropy of Nifty direction is near 1 bit, no model beats chance by much. That honesty saves you from chasing impossible edges.

Should I learn this before using AI for trading?

Yes — at least entropy and mutual information. They are the cheapest way to stop adding worthless indicators and start keeping the few that actually reduce uncertainty.

A Trader's 5-Minute Intuition Build

List your last 20 trades and a candidate signal (say "RSI < 30 at open"). Split the 20 days by the signal: group A (signal fired) and group B (didn't). Now compute the outcome distribution (up/down %) in each group. If group A is 80% up and group B is 50% up, the signal reduced entropy — it told you something. If both groups are ~52% up, the signal carried zero information (same as flipping a biased coin either way). That 5-minute split-test is mutual information in disguise, and it is the single most useful habit a quant trader can build.

Bits, Intuition, and the "One Bit Ceiling"

A useful mental model: every yes/no prediction you make about Nifty is worth at most 1 bit of information (the flip of a fair coin). If the market's daily direction truly has ~1 bit of entropy, then the maximum edge any model can extract is the gap between that 1 bit and the entropy after your signal. A signal that takes you from 1.0 bit to 0.7 bits has earned 0.3 bits — that is your real, information-theoretic edge, and it is tiny. This is why profitable Nifty models are hard: you are squeezing fractions of a bit out of a near-random process. Information theory is the honest scoreboard that tells you how many bits you actually captured, before you risk a rupee on them.

What Comes Next in the Series

This was component #5 — the last of the Math Foundations. Next we enter the Core ML Components:

  1. Neurons & Activation Functions — the atomic unit.
  2. Loss Functions — a deeper look beyond cross-entropy.
  3. Backpropagation — the deep dive.
  4. Regularization — L1/L2, dropout, early stopping.

The full index and all published articles are tracked on optiontradingwithai.in so you can read them in order or jump to what you need.

Key Takeaways

  • Information theory measures information as reduction in uncertainty (Shannon, 1948).
  • Entropy = unpredictability; low entropy features/targets are more learnable.
  • Information gain drives tree splits (and XGBoost) — your feature-selection tool.
  • Cross-entropy = the honest default classification loss; punishes confident errors.
  • KL divergence compares distributions; asymmetric, used in distillation/VAE/calibration.
  • Mutual information finds non-linear edges correlation misses.
  • Before optimizing, ask: does this feature reduce entropy? If not, drop it.

This is article 5 of the AI Components series. Article 6 covers Neurons & Activation Functions — the atomic unit of neural networks. Track the full series on optiontradingwithai.in.


About the Author

Shakti Tiwari — Nifty Option Trader, Research Analyst & XGBoost Expert. Publishes daily NSE India research and practical AI for ordinary retail traders.

🌐 Website: optiontradingwithai.in
📕 Option Trading with AIhttps://www.amazon.in/dp/B0H9ZNTBPK
📗 The AI Opportunityhttps://www.amazon.in/dp/B0HBBFKDQF
📢 Daily Nifty analysis on Telegram: https://t.me/shaktitrade
📧 Free help: shaktitiwari715@gmail.com

Research only, not SEBI-registered advice. Verify everything before acting.

ai #machinelearning #informationtheory #entropy #xgboost #nifty #india #datascience #optiontrading

Top comments (0)