সম্ভাবনা বিতরণ — Gaussian ও অন্যান্য
এই পাঠে যা শিখবেন
- Discrete বনাম Continuous distribution
- ৪টি জরুরি বিতরণ — Bernoulli, Binomial, Uniform, Gaussian
- Gaussian (Normal) কেন AI-এর সবচেয়ে গুরুত্বপূর্ণ বিতরণ
- Python-এ random sampling ও visualization
১ · বিতরণ কী?
একটি random variableRandom Variableএকটি random পরীক্ষার ফলাফলকে সংখ্যায় ম্যাপ করে। যেমন — মুদ্রা ছোঁড়ায় H=1, T=0. (যেমন আগামীকালের তাপমাত্রা) — কোন কোন মান পেতে পারে এবং প্রতিটি মান কতটা সম্ভাব্য, তার পূর্ণ চিত্রকে বলে সম্ভাবনা বিতরণ।
DiscreteDiscrete Distributionসীমিত বা গণনাযোগ্য outcome-এর বিতরণ। PMF (Probability Mass Function) দিয়ে describe হয়।: ফলাফল গণনাযোগ্য (যেমন ছক্কার পাশ ১,২,...,৬)।
ContinuousContinuous Distributionঅসীম সম্ভাব্য মান — যেকোনো real number. PDF (Probability Density Function) দিয়ে describe হয়।: ফলাফল যেকোনো সংখ্যা হতে পারে (যেমন তাপমাত্রা ২৭.৩৫°C)।
২ · BernoulliBernoulli Distributionএকটি single trial — ফলাফল ০ বা ১। প্যারামিটার $p$ = সফলতার সম্ভাবনা। সবচেয়ে সরল discrete distribution. — একক চেষ্টায় হ্যাঁ/না
একটি একক ঘটনা: ঘটে বা ঘটে না। সম্ভাবনা $p$ ঘটার, $1-p$ না-ঘটার।
- মুদ্রা ছোঁড়া (ভারসাম্যপূর্ণ): $p = 0.5$
- ই-মেইল spam কি না: $p$ নির্ভর করে কী ই-মেইল আসছে তার উপর
- পরীক্ষায় পাস কি ফেল: $p = $ পাসের সম্ভাবনা
গাণিতিক রূপ
$P(X = 1) = p$, $P(X = 0) = 1 - p$
৩ · BinomialBinomial Distribution$n$ স্বাধীন Bernoulli trial-এ মোট কতটি সফল — তার বিতরণ। দু'টি প্যারামিটার $n$ ও $p$। গড় $np$। — অনেক বার Bernoulli
$n$ বার একই Bernoulli চেষ্টা — কতবার "সফল" হলো? এটিই Binomial বিতরণ। প্যারামিটার দুটি — $n$ ও $p$।
উদাহরণ
- ১০টি মুদ্রা ছুড়লেন — Heads কতবার আসবে?
- ১০০ ই-মেইল পরীক্ষা — কয়টি spam?
- ১০০০ গ্রাহক — কতজন ক্লিক করবে একটি বিজ্ঞাপনে?
সূত্র (জানার দরকার নেই, শুধু ধারণা): $P(X = k) = \binom{n}{k} p^k (1-p)^{n-k}$
৪ · UniformUniform Distributionএকটি পরিসরে সব মান সমান-সম্ভাব্য। Continuous বা discrete হতে পারে। সবচেয়ে "ন্যায্য" বিতরণ। — সব মান সমান-সম্ভাব্য
একটি নির্দিষ্ট পরিসরে ($a$ থেকে $b$) প্রতিটি মান সমানভাবে সম্ভাব্য। সবচেয়ে সরল continuous বিতরণ।
- একটি ছক্কা — discrete uniform (১ থেকে ৬)।
np.random.rand()— continuous uniform ০ থেকে ১।- Random initialization — neural network-এর শুরুর ওজন প্রায়ই uniform-এ বাছা হয়।
৫ · Gaussian (Normal) — AI-এর রাজা
প্রকৃতির বহু পরিমাপ — উচ্চতা, ওজন, পরীক্ষার নম্বর, পরিমাপের ভুল — Gaussian-এর মতো বিতরণ মানে। এই কারণেই একে "Normal distribution"-ও বলে।
GaussianGaussian / Normal DistributionCarl Friedrich Gauss-এর নামে। PDF: $\frac{1}{\sigma\sqrt{2\pi}}e^{-(x-\mu)^2/(2\sigma^2)}$। দু'টি parameter (μ, σ) সম্পূর্ণ describe. ৬৮-৯৫-৯৯.৭ rule. CLT-এর কারণে natural phenomena-তে সর্বত্র। AI-তে — DL initialization, VAE prior, diffusion noise, regression assumption, regularization.-এর আকৃতি — প্রসিদ্ধ "ঘণ্টার বক্ররেখা" (bell curve)। দুটি প্যারামিটার:
- MeanMean (μ)একটি distribution-এর গড় মান — বিতরণের কেন্দ্র। Gaussian-এ এটি সর্বোচ্চ ঘনত্বের point. ($\mu$): ঘণ্টার শীর্ষ কোথায় — গড় মান।
- Standard deviationStandard Deviation (σ)মানগুলো গড় থেকে কতটা ছড়িয়ে আছে তার পরিমাপ। variance-এর বর্গমূল। ($\sigma$): ঘণ্টা কতটা চওড়া — মানগুলো গড় থেকে কত বিস্তৃত।
কয়েকটি বৈশিষ্ট্য
- প্রায় ৬৮% মান $\mu \pm \sigma$-এর মধ্যে।
- প্রায় ৯৫% মান $\mu \pm 2\sigma$-এর মধ্যে।
- প্রায় ৯৯.৭% মান $\mu \pm 3\sigma$-এর মধ্যে।
একে বলা হয় ৬৮-৯৫-৯৯.৭ নিয়ম। AI-এর প্রায় সব ক্ষেত্রে এই বিতরণ লুকিয়ে আছে।
৬ · Python-এ বিতরণগুলো — হাতে দেখা
import numpy as np
np.random.seed(42)
# Bernoulli — ১টি Heads/Tails ছোঁড়া (p=0.5)
flips = np.random.binomial(n=1, p=0.5, size=20)
print("২০ বার মুদ্রা:", flips)
print(f"Heads অনুপাত: {flips.mean():.3f}")
# Binomial — ১০টি মুদ্রা একসাথে, ১০০০ বার
trials = np.random.binomial(n=10, p=0.5, size=1000)
print(f"\n১০০০টি ১০-ছোঁড়া trial-এর গড় Heads: {trials.mean():.3f}")
print(f"তত্ত্ব: n*p = 10 * 0.5 = 5")
Gaussian — Bell Curve জেনারেট
import numpy as np
np.random.seed(42)
# ১০,০০০ Gaussian sample — মানুষের উচ্চতা সিমুলেট
heights = np.random.normal(loc=165, scale=7, size=10000)
print(f"গড় (μ): {heights.mean():.2f}")
print(f"স্ট্যান্ডার্ড ডেভিয়েশন (σ): {heights.std():.2f}")
print(f"সর্বনিম্ন: {heights.min():.2f}")
print(f"সর্বোচ্চ: {heights.max():.2f}")
# 68-95-99.7 নিয়ম যাচাই
within_1 = ((heights > 158) & (heights < 172)).mean()
within_2 = ((heights > 151) & (heights < 179)).mean()
within_3 = ((heights > 144) & (heights < 186)).mean()
print(f"\nμ ± 1σ-এ: {within_1:.3f} (তত্ত্ব: 0.68)")
print(f"μ ± 2σ-এ: {within_2:.3f} (তত্ত্ব: 0.95)")
print(f"μ ± 3σ-এ: {within_3:.3f} (তত্ত্ব: 0.997)")
Histogram-এ দেখা — bell curve
import numpy as np
np.random.seed(42)
data = np.random.normal(loc=0, scale=1, size=10000)
# bin-এ ভাগ করে গণনা
counts, bins = np.histogram(data, bins=20)
print("Gaussian-এর ascii histogram:\n")
max_count = counts.max()
for c, b in zip(counts, bins):
bar = '█' * int(40 * c / max_count)
print(f"{b:6.2f} | {bar}")
৭ · AI-তে কোন বিতরণ কোথায়?
- Bernoulli/Binomial: বাইনারি classification — spam/not-spam, সফল/বিফল।
- CategoricalCategorical Distribution$k$ সম্ভাব্য discrete outcome-এর উপর বিতরণ — প্রতিটির আলাদা probability. Bernoulli-র multi-class generalization. (Multinomial): Multi-class classification — Softmax আউটপুট।
- Uniform: Random initialization, exploration in RL.
- Gaussian: Regression-এ residuals, weight initialization, VAE-এর latent space, diffusion noise — সর্বত্র।
- PoissonPoisson Distributionএকটি নির্দিষ্ট সময়ে বিরল ঘটনা কতবার ঘটবে — তার বিতরণ। প্যারামিটার $\lambda$ = গড় rate.: বিরল ঘটনা গণনা — গ্রাহক আগমন, লাইনের ফোন কল।
- Beta/Dirichlet: Bayesian inference, Latent Dirichlet Allocation (topic modeling)।
৮ · Central Limit Theorem — কেন Gaussian সর্বত্র
আপনি যেকোনো বিতরণ থেকে অনেক sample নিয়ে গড় হিসাব করুন — সেই গড়গুলোর বিতরণ Gaussian হবে। বিতরণ যাই হোক!
এই উপপাদ্যকে বলে Central Limit TheoremCentral Limit Theorem (CLT)De Moivre (১৭৩৩) থেকে শুরু, Laplace (১৮১০) generalize. অনেক independent random variables-এর গড় (বা যোগ) — original distribution যাই হোক — Gaussian distribution মানে। এ কারণেই বিজ্ঞানে Gaussian "ubiquitous"। CLT-এর জন্য মাত্র দু'টি condition: independent + finite variance. (CLT)। এর কারণেই — যত ভিন্ন কারণ একসাথে কাজ করে কোনো পরিমাপে (যেমন উচ্চতা — জিন, পুষ্টি, পরিবেশ), ফলাফল প্রায় সবসময়ই Gaussian হয়।
ভাবনার প্রশ্ন
প্রতিটি প্রশ্ন নিজে কিছুক্ষণ ভাবুন — তারপর "→ উত্তর" চাপুন।
প্র ০১ "মানুষের আয়ের distribution Gaussian" — এই দাবি কেন ভুল? কোন distribution বেশি appropriate? AI/economics-এ এটি কেন গুরুত্বপূর্ণ?
এটি একটি classic ভুল। আয় Gaussian না — এটি একটি heavy-tailed distribution.
কেন Gaussian না:
- Gaussian symmetric — গড়ের চারপাশে balanced. কিন্তু আয়ে — কেউ ০, কেউ multi-millionaire.
- Gaussian-এ ৩σ-এর বাইরে rare (০.৩%)। কিন্তু কোটিপতি bangladesh-এ rare হলেও existential.
- Gaussian negative value allow করে। আয় নেই।
- Empirical fact: বাস্তব income data — right-skewed.
সঠিক distributions:
- Log-normal: $\log(\text{income})$ Gaussian. অর্থাৎ income exponential-এ Gaussian. Multiplicative effects (career growth, compound returns) এর কারণ।
- Power law / Pareto: $P(X > x) \propto x^{-\alpha}$। "৮০-২০ rule" — ২০% মানুষের ৮০% সম্পদ। Pareto (১৮৯৬) এই pattern প্রথম document.
- Mixture distributions: মাঝারি income lognormal + super-rich power-law tail.
Heavy tail-এর প্রভাব:
- গড় misleading: Bangladesh average income ৳৫০,০০০ — কিন্তু median ৳২৫,০০০। কারণ — কয়েকজন অতি-ধনী গড়কে টানে।
- Variance huge: standard deviation দিয়ে summary unhelpful.
- Inequality measures: Gini coefficient, P90/P10 ratio — Gaussian-এ অর্থহীন, heavy-tail-এ critical.
AI/ML-এ practical implications:
- Loan default prediction: Income feature directly use করলে — outliers-এ মডেল distorted. Log-transform প্রায়ই করা হয়।
- E-commerce LTV prediction: Customer lifetime value — heavy-tailed. মডেল ৯০%+ customers underestimate; "whales" এর জন্য আলাদা treatment.
- Recommendation systems: Item popularity power-law. Long-tail recommendations specifically targeted.
- Risk modeling: Black Swan events. 2008 financial crisis — Gaussian assumption massively underestimated tail risk.
সাধারণ পরামর্শ:
- "Real-world distribution Gaussian" — default assumption ভুল হতে পারে।
- Always plot histogram first. Visual check.
- Log-transform skewed data.
- Median, percentiles — mean-এর চেয়ে robust.
মূল উপলব্ধি: প্রকৃতি — natural processes Gaussian হয়। মানুষের সমাজে — power, wealth, fame — heavy-tailed. এই পার্থক্য AI design-এ critical.
প্র ০২ Diffusion models (Stable Diffusion, DALL-E 3) — Gaussian noise থেকে ছবি তৈরি করে। কীভাবে এই magic কাজ করে? noise → coherent image কোন গণিতে?
Diffusion models — ২০২১ থেকে generative AI-র dominant paradigm. ভিতরে Gaussian distribution everything.
Forward process — destruction:
- Real image $x_0$ → ধাপে ধাপে Gaussian noise add.
- Each step: $x_t = \sqrt{1-\beta_t} x_{t-1} + \sqrt{\beta_t} \epsilon$, where $\epsilon \sim \mathcal{N}(0, I)$।
- $T = 1000$ steps পরে — pure noise, original image সম্পূর্ণ destroyed.
- এই process deterministic and well-defined (Markov chain)।
Reverse process — generation:
- $x_T \sim \mathcal{N}(0, I)$ — pure noise থেকে শুরু।
- প্রতিটি step-এ — neural network predict করে কোন noise add হয়েছিল।
- Predict-deduct করে $x_t \to x_{t-1}$ — slightly less noisy image.
- $T$ steps পরে — coherent image.
Training objective:
- মডেল $\epsilon_\theta(x_t, t)$ predict করে — noise component.
- Loss: $\mathbb{E}[\|\epsilon - \epsilon_\theta(x_t, t)\|^2]$ — simple MSE!
- Forward process easy (just add noise)। Reverse আইসিতে train.
- U-Net architecture (CNN with skip connections) — image-এ noise predict.
কেন কাজ করে — গভীর কারণ:
- Manifold hypothesis: Real images lie on low-dim manifold high-D pixel space-এ। Noise-এ যোগ করলে — image manifold থেকে দূরে যায়।
- Score function: $\nabla_x \log p(x)$ — manifold-এর দিকে point করে। Diffusion model এই estimate করে। Score-based generative modeling (Song & Ermon, 2019)।
- Stochastic Differential Equations (SDE): Continuous time-এ — diffusion = SDE. Reverse SDE solve করে generate.
- Variational lower bound: Likelihood maximize করার একটি tractable bound. ELBO.
Conditional generation (text-to-image):
- Text encoding (CLIP/T5) → diffusion model conditioning.
- Classifier-free guidance — conditional + unconditional combine, sharper outputs.
- Cross-attention layers — text tokens প্রতিটি image patch-কে guide করে।
সফলতার কারণ:
- Stable training: GAN-এর adversarial dynamics নেই। Simple MSE loss.
- Mode coverage: GAN mode collapse-এ ভোগে। Diffusion সব mode capture.
- Quality: ২০২২+ diffusion models GAN-কে quality-এ overtake.
- Steerability: Inpainting, outpainting, image-to-image — সবই same model থেকে।
Practical models:
- DDPM (Ho et al., 2020) — foundational paper.
- Stable Diffusion (Stability AI, 2022) — latent diffusion.
- DALL-E 3 (OpenAI, 2023) — better text alignment.
- FLUX (Black Forest Labs, 2024) — open, state-of-art.
মূল উপলব্ধি: Image generation = "noise থেকে structure"। প্রতিটি step-এ Gaussian removal. AI-এর সবচেয়ে chic process — pure Gaussian থেকে কোটি-পিক্সেল সৌন্দর্য।
প্র ০৩ Neural network weight initialization — কেন Gaussian বা Uniform-এ random init দরকার? সব weight ০ দিলে কী হয়?
এই simple-সাইট প্রশ্নের ভেতরে DL-এর গভীর symmetry-breaking philosophy লুকিয়ে।
সব weight ০ দিলে — disaster:
- একই layer-এর সব neurons identical output produce.
- Gradient সব neurons-এ identical.
- Updates identical — symmetry break হয় না।
- Effectively — পুরো layer একটি neuron-এর equivalent.
- Network capacity ১/n × actual. শেখা impossible.
সব same value (e.g., 0.5)-ও same problem:
- একই symmetry — neurons distinguishable না।
- Deeper layers-এ outputs identical.
Random init — কেন কাজ করে:
- প্রতিটি neuron-এর initial weights ভিন্ন।
- Outputs ভিন্ন → gradients ভিন্ন → updates ভিন্ন।
- প্রতিটি neuron different feature শেখা শুরু করে।
- Symmetry breaking → expressiveness.
কোন distribution — কেন:
- Standard Gaussian (μ=0, σ=1): Naive choice. কিন্তু — deep network-এ outputs explode/vanish.
- Xavier/Glorot init (২০১০): $\sigma = \sqrt{1/n_{in}}$ বা $\sqrt{2/(n_{in}+n_{out})}$। Forward + backward variance preserve করে। sigmoid/tanh-এ কাজ করে।
- He init (২০১৫): $\sigma = \sqrt{2/n_{in}}$। ReLU-এ — half neurons inactive, double variance compensate.
- Uniform variants: Same scaling principle. কিছু framework default.
Why scaling matters:
- Layer output $y = Wx + b$। If $W$ values too large — $y$ huge, sigmoid saturates.
- If too small — $y \approx 0$, deeper layers see no signal.
- Goal: $\text{Var}(y) \approx \text{Var}(x)$ — variance preserve.
- Math: $\text{Var}(y) = n \cdot \text{Var}(W) \cdot \text{Var}(x)$ → $\text{Var}(W) = 1/n$।
Modern alternatives:
- Orthogonal init: Weight matrix orthogonal — preserve gradient magnitude exactly. RNN-এ helpful.
- Identity init: Skip-connection like behavior.
- μP (Maximal Update Parametrization, 2022): hyperparameter scaling-এ better. small model-এ tune, large-এ apply.
- Pretrained init: Foundation models থেকে। transfer learning.
Practical lessons:
- Modern frameworks (PyTorch, TF) — He/Xavier default, depending on activation.
- Wrong init → training fail. হাজার-ঘণ্টার GPU waste.
- Gradient explosion/vanishing problems → init check first.
- Bias usually 0 init (or small constant)। Symmetry not an issue for biases.
মূল উপলব্ধি: "Random init" একটি engineering art. Math-এ symmetry breaking; practice-এ training stability. এই সরল step-এ DL-এর সফলতা দাঁড়িয়ে।
প্র ০৪ Softmax output distribution probabilities — কিন্তু "softmax temperature" কী? T পরিবর্তনে output distribution কীভাবে বদলায়?
Temperature — generative AI-র সবচেয়ে important sampling control. সঠিক বুঝলে — output diversity, hallucination control, creative writing.
Softmax formula:
$\text{softmax}(z_i; T) = \frac{e^{z_i / T}}{\sum_j e^{z_j / T}}$
T = 1 (default):
- Standard softmax.
- Output = original distribution as trained.
T < 1 (sharper, more confident):
- Logits ($z_i$) effectively scaled up.
- Differences amplified — top tokens dominate more.
- T = 0.1 — almost greedy, very deterministic.
- T → 0 — exact greedy (highest logit chosen)।
- Use case: Factual QA, code completion — accuracy critical.
T > 1 (smoother, more random):
- Logits compressed.
- Differences reduced — distribution flatter.
- Lower-probability tokens get a chance.
- T = 2 — much more random.
- T → ∞ — uniform distribution.
- Use case: Creative writing, brainstorming.
Numerical example:
Logits: $[2, 1, 0]$
- T = 1: $[0.665, 0.244, 0.090]$ — moderate skew.
- T = 0.5: $[0.844, 0.114, 0.015]$ — top dominates.
- T = 2: $[0.506, 0.307, 0.186]$ — flatter.
- T = 10: $[0.351, 0.331, 0.318]$ — almost uniform.
Practical use in LLM:
- OpenAI/Anthropic API: "temperature" parameter (0-2 typically)।
- T = 0: Maximum reproducibility. Same input → same output (almost)।
- T = 0.7 (default): Balanced — natural-sounding, varied.
- T = 1.0: Original training distribution.
- T = 1.5+: Creative, sometimes nonsense.
Combination with top-p (nucleus sampling):
- Temperature scales distribution.
- Top-p truncates tail (cumulative probability ≤ p)।
- Best practice: T=1, top-p=0.9 — quality + diversity.
Knowledge distillation use:
- Hinton et al. (২০১৫) — large model "soft targets" with high T.
- Small model train করতে — high-T softmax থেকে nuanced gradient.
- "Dark knowledge" — non-top-class probabilities-এও information.
RL/RLHF context:
- Exploration vs exploitation — T-এ tune.
- Boltzmann/Gibbs distribution physics-এ এই formula — temperature literal!
মূল উপলব্ধি: Temperature — single number, dramatic effect. Production AI-তে user experience tune করার একটি critical knob. T = 0.7 কেন প্রায়ই default — sweet spot accuracy ও diversity-এ।
অনুশীলন
-
সিমুলেট করুন: $\mu = 100$, $\sigma = 15$ Gaussian থেকে ১০,০০০ sample নিন (IQ স্কোরের মতো)। কতজনের IQ ১৩০-এর বেশি?
import numpy as np np.random.seed(42) iq = np.random.normal(100, 15, 10000) above130 = (iq > 130).mean() print(f"IQ > 130: {above130:.4f} ({above130*100:.2f}%)")প্রত্যাশিত: ~২.৩% (২σ-এর বাইরে high tail)। তত্ত্ব: Gaussian-এ ২σ-এর বাইরে ২.৫% (each tail)।
-
তুলনা করুন: ১০টি মুদ্রা ১০০০ বার ছুড়ুন। Heads সংখ্যার histogram আঁকুন — এটি কোন বিতরণের আকৃতি?
Binomial (n=10, p=0.5)। Peak ~৫-এ। আকৃতি bell-curve-এর কাছাকাছি — কারণ binomial large n-এ Gaussian approximate করে (CLT-এর special case)।
import numpy as np trials = np.random.binomial(10, 0.5, 1000) counts, bins = np.histogram(trials, bins=range(12)) for c in counts: print('█' * c) -
চিন্তা করুন: আপনার এলাকায় ১০০ গ্রাহকের আয়ের distribution কেমন হবে? Gaussian? কেন/কেন না?
প্র ০১-এ বিস্তারিত আছে। সংক্ষেপে:
- না, Gaussian হবে না।
- আয় right-skewed — কয়েকজন high-income গড়কে টানে।
- Log-normal বা Pareto বেশি appropriate.
- Median < Mean — heavy-tailed-এর signature.
AI-তে practical: Income feature directly use করার আগে log-transform করুন।
আরও পড়ুন · ABCL TECH-এ আপনার পরবর্তী পদক্ষেপ
- পাঠ ১৮ · প্রত্যাশা ও ভেরিয়েন্স পরবর্তী পাঠ Distribution-এর summary statistics — mean, variance. AI-তে loss-এর math.
- পাঠ ১৬ · সম্ভাবনার মূল আগের পাঠ Distribution-এর ভিত্তি — sample space, event.
- পাঠ ১৯ · Bayes' Theorem এই পাঠের সাথে সম্পর্কিত Distribution + conditional = Bayes-এর শক্তিশালী framework.
- সব AI Courses দেখুন ABCL TECH Python, ML, DL, NLP, CV, GenAI, RL, MLOps — সব AI কোর্স একসাথে।