1.3.18 · D4 · HinglishProbability & Statistics

ExercisesEntropy and KL divergence

2,027 words9 min read↑ Read in English

1.3.18 · D4 · AI-ML › Probability & Statistics › Entropy aur KL divergence

Yeh page Entropy and KL divergence ki self-testing ke liye hai. Har problem ek complete worked solution chhupati hai — pehle khud try karo, phir reveal karo. Levels L1 Recognition se L5 Mastery tak charhte hain. Har level ke end mein ek trap hai jismein aasaani se fas sakte ho — usse is tarah explain kiya gaya hai ki galat raasta kyun sahi lagta hai.

Figure — Entropy and KL divergence

Level 1 — Recognition

Exercise 1.1 (L1)

Ek coin fair hai: . Bits mein kya hai?

Recall Solution

Kya karte hain: mein plug in karo. Kyun: kyunki . Answer: bit. Ek binary sawaal ("heads?") sab settle kar deta hai.

Exercise 1.2 (L1)

Ek variable deterministic hai: aur baaki har outcome ki probability hai. kya hai?

Recall Solution

Sirf wala term bachta hai (baaki ke liye convention use hoti hai): Answer: bits. Koi surprise nahi — tum pehle se outcome jaante ho.

Exercise 1.3 (L1)

Kaun sa sach hai, aur kyun? (a) hamesha. (b) hamesha.

Recall Solution

(a) galat hai — KL asymmetric hai; dono arguments alag roles play karte hain (kaun "truth" hai aur kaun "model"). (b) sach hai — Gibbs' inequality se, KL kabhi negative nahi hoti, aur equals sirf tab jab . Answer: (b).


Level 2 — Application

Exercise 2.1 (L2)

Ek biased coin mein hai. Bits mein compute karo.

Recall Solution

, . Answer: bits. Fair coin ke bit se kam uncertainty — zyada tar heads aata hai, toh seekhne ko kam hai.

Exercise 2.2 (L2)

Ek fair 8-sided die: for . aath terms sum kiye bina nikalo.

Recall Solution

Kya karte hain: maximum-entropy shortcut use karo. outcomes par uniform distribution ke liye, Kyun: har term hai, aur terms hain, toh sab mein collapse ho jaate hain. Answer: bits. Teen haan/nahi sawaal (binary search) aath faces mein se ek identify kar dete hain.

Exercise 2.3 (L2)

True label (class 2); model prediction . Nats mein cross-entropy compute karo.

Recall Solution

Kyun zeros gayab hote hain: ek one-hot label saara weight class 2 par daalta hai, toh sirf uska term bachta hai. Answer: nats. Yeh is ek example ke liye bilkul classification loss hai.


Level 3 — Analysis

Exercise 3.1 (L3)

True coin , model . Bits mein compute karo.

Recall Solution

, . Answer: bits. Model use karne ka extra cost per flip jab sach hai.

Exercise 3.2 (L3)

Wohi do coins, lekin reverse compute karo. Exercise 3.1 se compare karo.

Recall Solution

, . Answer: bits. se alag hai — yeh seedha proof hai ki KL asymmetric hai. Ab truth hai aur model hai; aage ka weighting badal gaya.

Exercise 3.3 (L3)

, ke liye identity numerically verify karo (bits use karo).

Recall Solution

bit (fair coin, Ex 1.1). Phir bits — Exercise 3.1 se match karta hai. ✓ Answer: identity confirmed; bits dono taraf se.


Level 4 — Synthesis

Exercise 4.1 (L4)

Do-outcome distribution ke liye, entropy binary entropy hai. Dikhao ki yeh par maximize hoti hai, derivative zero kahan hai yeh nikaal ke.

Recall Solution

Kya karte hain: ke saath differentiate karo. Natural log use karke phir convert karke, . Kyun derivative: ek smooth concave curve ka maximum wahan hota hai jahan uski slope ho. Set karo . Kaisa dikhta hai: neeche figure mein -shaped curve bilkul center mein par peak karti hai, height bit, aur dono ends par tak girti hai. Answer: , jisse bit milta hai — maximum.

Figure — Entropy and KL divergence

Exercise 4.2 (L4)

True label class 2 wale ek training example ke liye cross-entropy loss, . Model ke logits dete hain. Nats mein loss compute karo. Phir batao kya hota hai loss ko jab model improve hota hai aur .

Recall Solution

Limiting behaviour: jab , — loss gayab ho jaata hai. Jab , — infinitely confident galat prediction infinitely penalize hoti hai (KL convention se match karta hai: ). Answer: nats; loss jab model sahi class certain ho jaata hai, agar yeh true class ko zero drive kar de.


Level 5 — Mastery

Exercise 5.1 (L5)

Ek source symbols emit karta hai true probabilities ke saath. (a) Bits mein nikalo. (b) Tum uniform model ke liye bane code se compress karte ho. Average bits used, , nikalo. (c) Wasted bits nikalo aur confirm karo ki .

Recall Solution

(a) Probabilities ki powers hain, toh surprisals clean integers hain: (b) ke under, har symbol bits cost karta hai, toh average bits regardless of : (c) Wasted: Identity check: . ✓ Answer: , , bits. Uniform code quarter bit per symbol waste karta hai kyunki yeh ignore karta hai ki common hai.

Exercise 5.2 (L5)

Mixture / connective reasoning. Mixture define karo aur Jensen–Shannon quantity . aur ke liye bits mein JSD compute karo.

Recall Solution

Mixture: . Pehla KL: bit (-side term mein weight hai → ). Doosra KL: symmetry se bit. Answer: bit — maximum, correctly finite even though yahan hai (kyunki jahan wahan hai). Yahi exactly wajah hai ki Jensen-Shannon Divergence ek symmetric, hamesha-finite alternative ke roop mein prefer ki jaati hai, aur KL Evidence Lower Bound (ELBO) aur Variational Autoencoders mein kaise enter karta hai.


Recall Quick self-check (cloze)

outcomes par Uniform entropy ::: KL zero exactly tab hota hai jab ::: har jagah Cross-entropy minus entropy equal hai ::: Binary entropy peak karta hai par ::: , giving bit Ek confident wrong prediction ( jahan ) loss ko banata hai :::

Dekho bhi: Mutual Information, Maximum Entropy Principle, Cross-Entropy Loss, Information Gain, F-divergences.