পাঠ ২৫ · ৩০-এর মধ্যে · মডিউল ৩
Home / AI Courses / AI Foundations / মন্টে কার্লো

মন্টে কার্লো — দৈবচয়নে অনুমান

Monte Carlo methods — estimation by random sampling
১০ মিনিট পড়া মাঝারি · Intermediate Python কোডসহ

এই পাঠে যা শিখবেন

  • মন্টে কার্লো পদ্ধতির মূল ধারণা — কেন এটি কাজ করে
  • π-এর মান random sampling-এ বের করা
  • Law of Large Numbers — মন্টে কার্লো-র গাণিতিক ভিত্তি
  • AI-তে কোথায় ব্যবহার — RL, Bayesian inference, Diffusion
  • সীমাবদ্ধতা ও variance reduction

১ · নাম এসেছে কোথা থেকে?

১৯৪০-এর দশকে — Manhattan Project (পরমাণু বোমা গবেষণা)-এ Stanislaw Ulam ও John von Neumann এই পদ্ধতি ব্যবহার করেন। Ulam-এর কাকা মন্টে কার্লোমন্টে কার্লোমোনাকোর বিখ্যাত casino শহর। Ulam তার solitaire game-এর সম্ভাবনা গাণিতিকভাবে বের না করে — random simulate করে বের করেন। এই থেকেই পদ্ধতির নাম। (মোনাকো)-র ক্যাসিনোতে জুয়া খেলতেন — এই থেকেই নামকরণ। মূল ধারণা: কঠিন গণিত র‍্যান্ডম sampling দিয়ে আনুমানিক করা যায়।

১৯৪৭-এ ENIAC কম্পিউটার-এ neutron diffusion-এর প্রথম মন্টে কার্লো simulation. আজকের AI-এর সবচেয়ে exciting অংশ — diffusion model, MCTS — এই ১৯৪০-এর insight-এর descendant.

২ · কেন এটি কাজ করে — Law of Large Numbers

গাণিতিক ভিত্তি

একটি random variable থেকে $n$টি স্বাধীন sample-এর গড় — $n \to \infty$-তে — সঠিক গড়ের কাছে পৌঁছাবে।
$$\dfrac{1}{n}\sum_{i=1}^{n} X_i \;\to\; E[X]$$

মুদ্রা ১০ বার ছুড়লে — Heads ৫ এর কাছে কোনো নিশ্চয়তা নেই। ১০,০০,০০০ বার ছুড়লে — গড় ০.৫-এর খুব কাছে। এটাই LLN.

Central Limit Theorem (CLT)Central Limit Theorem · কেন্দ্রীয় সীমা উপপাদ্যপ্রায় যেকোনো বিতরণ থেকে অনেক sample-এর গড় Gaussian-এ পরিণত হয়। MC-র convergence rate $\sigma/\sqrt{n}$ এর ভিত্তি। পরের ধাপ: গড়ের distribution Gaussian — তাই error $\sim \sigma/\sqrt{n}$। এই মৌলিক sqrt-decay-ই Monte Carlo-র convergence rate.

৩ · π হিসাব — মন্টে কার্লো ক্লাসিক

একটি বর্গের ভেতরে একটি বৃত্ত আঁকুন — বর্গের বাহু ২, বৃত্তের ব্যাসার্ধ ১।

  • বর্গের ক্ষেত্রফল: $4$
  • বৃত্তের ক্ষেত্রফল: $\pi r^2 = \pi$
  • অনুপাত: $\dfrac{\pi}{4}$

এখন বর্গে এলোমেলো বিন্দু ছুঁড়ুন। কতগুলো বৃত্তের ভেতরে পড়ছে গণনা করুন। অনুপাত $\approx \dfrac{\pi}{4}$।

$$\pi \approx 4 \cdot \dfrac{\text{বৃত্তে পড়া বিন্দু}}{\text{মোট বিন্দু}}$$

Python · π estimation
import numpy as np

np.random.seed(42)

# বিভিন্ন sample size-এ pi-র অনুমান
for n in [100, 1_000, 10_000, 100_000, 1_000_000]:
    # [-1, 1]-এ এলোমেলো বিন্দু
    x = np.random.uniform(-1, 1, size=n)
    y = np.random.uniform(-1, 1, size=n)
    inside = (x**2 + y**2) <= 1
    pi_estimate = 4 * inside.mean()
    error = abs(pi_estimate - np.pi)
    print(f"n = {n:>9,} → π ≈ {pi_estimate:.6f}, error = {error:.6f}")

    
$n$ বাড়ানোর সাথে error কমে — মোটামুটি $1/\sqrt{n}$ অনুপাতে। ১০ লক্ষ sample-এ ৩ ডিজিট নির্ভুলতা পাবেন। ১০ ডিজিট চাইলে — $10^{20}$ sample!

৪ · মন্টে কার্লো-র মূল কাঠামো

যেকোনো মন্টে কার্লো পদ্ধতিতে ৩টি ধাপ —

  1. সমস্যাকে প্রত্যাশা (expectation) হিসেবে লিখুন: "এই মান চাই" → "এটি কোন random variable-এর গড়?"
  2. Sample সংগ্রহ করুন: সেই বিতরণ থেকে অনেক random sample.
  3. গড় হিসাব: Sample-এর গড় = প্রত্যাশার আনুমানিক।

৫ · ব্যবহারিক উদাহরণ — জটিল integral

$\int_0^1 x^2 \sin(x) \, dx$ — গাণিতিকভাবে কঠিন (integration by parts × ২)। কিন্তু মন্টে কার্লো সহজে করে।

$\int_0^1 f(x) \, dx = E_{x \sim U(0,1)}[f(x)]$ — uniform বিতরণ থেকে $x$ নিয়ে $f(x)$-এর গড় বের করুন।

Python · Integral estimate
import numpy as np

np.random.seed(42)

# ∫₀¹ x² sin(x) dx
n = 1_000_000
x = np.random.uniform(0, 1, size=n)
fx = x ** 2 * np.sin(x)
estimate = fx.mean()

# তুলনা — সঠিক উত্তর প্রায় 0.2233
print(f"Monte Carlo অনুমান: {estimate:.6f}")
print(f"সঠিক উত্তর প্রায়:    0.223244")
print(f"Error:               {abs(estimate - 0.223244):.6f}")

    

৬ · কেন উচ্চ-মাত্রায় মন্টে কার্লো অপরিহার্য?

১-মাত্রিক integral সাধারণ পদ্ধতিতে (গ্রিড, Simpson rule) করা যায়। কিন্তু ১০০-মাত্রিক integral?

  • প্রতিটি মাত্রায় ১০টি বিন্দু লাগলে — ১০০-মাত্রিক গ্রিডে $10^{100}$ বিন্দু লাগবে। অসম্ভব!
  • মন্টে কার্লো ১০ লক্ষ sample-এ মোটামুটি কাজ চালিয়ে দেয়।

একে বলে "Curse of Dimensionality" — গ্রিড পদ্ধতি ভেঙে পড়ে। মন্টে কার্লো জ্বলে ওঠে। AI-এর প্রায় সব কিছু উচ্চ-মাত্রিক — তাই MC ছাড়া modern AI অসম্ভব।

Monte Carlo — workflow ও AI-তে প্রয়োগ "Hard math? Random sample!" ৩-ধাপ workflow ১. Express as E[X] "target as expectation" ∫f(x)dx → E[f(X)] ২. Sample N times draw X₁, X₂, ..., X_N independent ৩. Average (1/N) Σ f(Xᵢ) → E[f(X)] error ~ 1/√N Law of Large Numbers: (1/N) Σ Xᵢ → E[X] 🤖 AI-তে প্রয়োগ RL · MCTS AlphaGo, AlphaZero Diffusion Models Stable Diffusion, DALL·E Bayesian Inference MCMC, Gibbs sampling VAE · ELBO latent reparameterization RLHF rollouts PPO, reward sampling MC Dropout epistemic uncertainty Curse of Dimensionality: grid fails in 100-D, Monte Carlo survives. Modern AI = 10⁹-D.
৩-ধাপ workflow: expectation, sample, average. Law of Large Numbers ভিত্তি। আজকের AI-তে — RL থেকে Diffusion পর্যন্ত — সর্বত্র।

৭ · AI-তে মন্টে কার্লো

  • Reinforcement Learning: Monte Carlo Tree Search (MCTS)MCTSgame tree-এ random simulation দিয়ে best move বের করা। AlphaGo (২০১৬) Lee Sedol-কে হারায় — MCTS + neural networks. AlphaZero (২০১৭) — Go, chess, shogi সব superhuman. (AlphaGo!) — সম্ভাব্য পদক্ষেপ random simulate.
  • Bayesian Inference: জটিল posterior থেকে sampling — MCMCMCMC · Markov Chain Monte Carloএকটি Markov chain তৈরি যার stationary distribution হবে target posterior — তারপর সেই chain থেকে sample সংগ্রহ। Bayesian inference-এর workhorse., GibbsGibbs Samplingএকটি multivariate বিতরণ থেকে নমুনা নেওয়ার MCMC কৌশল — প্রতিটি variable পালাক্রমে অন্যগুলো fixed রেখে sample., Hamiltonian MC.
  • Variational Autoencoders (VAE): ELBO হিসাবে sampling — reparameterization trickReparameterization Trick$z \sim N(\mu,\sigma^2)$-কে $z = \mu + \sigma \cdot \epsilon$ হিসেবে লেখা ($\epsilon \sim N(0,1)$) — যাতে gradient sampling-এর মধ্য দিয়ে flow করতে পারে। VAE-এর মূল কৌশল।.
  • Diffusion Models: noise sampling — Stable Diffusion, DALL·E-এর মূল।
  • Dropout: Monte Carlo Dropout — মডেলের অনিশ্চয়তা পরিমাপ।
  • RLHF: Policy rollouts — PPO-তে batch trajectories.
  • Risk simulation: Finance, supply chain ঝুঁকি অনুমান।
  • Bagging: Random Forest — bootstrap sample-ই MC-র একটি রূপ।

৮ · মন্টে কার্লো-র সুবিধা ও সীমা

সুবিধা

  • সরল ও অনুধাবনীয় — সমস্যার গণিত জটিল হলেও।
  • উচ্চ-মাত্রায় কার্যকর — dimension-এর সাথে scale ভাল।
  • সমান্তরালীকরণ সহজ — প্রতিটি sample স্বাধীন। GPU-friendly.
  • যেকোনো বিতরণে কাজ করে।
  • Anytime algorithm — যত sample, তত accurate. যেকোনো সময় থামানো যায়।

সীমা

  • Convergence ধীর — error $\sim 1/\sqrt{n}$ (১০x error কমাতে ১০০x sample দরকার)।
  • Variance বেশি — অনেক sample না হলে ফল উঠানামা করে।
  • "Bad" বিতরণে — গুরুত্বপূর্ণ অঞ্চল (rare events) মিস হতে পারে।
  • Random seed দিয়ে নির্ভরযোগ্যতা — শিরোনাম-পদ্ধতি সঠিক করে দেওয়া দরকার।
Variance reduction — মন্টে কার্লো-র একটি গবেষণা ক্ষেত্র। Importance samplingImportance Sampling"গুরুত্বপূর্ণ" অঞ্চল থেকে বেশি sample নিয়ে variance কমানো — $E_p[f] = E_q[f \cdot p/q]$, যেখানে $q$ proposal বিতরণ।, antithetic variates, control variates, Quasi-Monte CarloQuasi-Monte Carlo (QMC)সম্পূর্ণ random-এর বদলে low-discrepancy sequences (Sobol, Halton) ব্যবহার — convergence rate $1/\sqrt{n}$-এর চেয়ে দ্রুত হতে পারে। — কম sample-এ ভালো ফল আনার কৌশল। আধুনিক AI সিস্টেমে অপরিহার্য।

৯ · সরল উপলব্ধি

"কঠিন গণিত? অনেক random sample নাও — গড় বের করো। এটাই মন্টে কার্লো — ১৯৪৭ থেকে আজকের AGI পর্যন্ত।"

ভাবনার প্রশ্ন

প্রতিটি প্রশ্ন নিজে কিছুক্ষণ ভাবুন — তারপর "→ উত্তর" চাপুন।

প্র ০১ Stable Diffusion, DALL·E, Midjourney — সব diffusion model. Image generation-এ Monte Carlo কীভাবে কাজ করে? Noise থেকে image — এই magic-এর গণিত কী?

Diffusion model — ২০২২-এর AI revolution-এর প্রধান চালক। গণিত surprisingly elegant — সব মন্টে কার্লো-ভিত্তিক। Sohl-Dickstein (২০১৫), Ho et al. (২০২০, DDPM), Song et al. (২০২১, score-based) — ইতিহাস।

(১) মৌলিক ধারণা:

  • Forward process: image-এ ধীরে ধীরে noise add — শেষে pure Gaussian noise.
  • Reverse process: pure noise থেকে শুরু, ধাপে ধাপে noise remove — image.
  • Network শেখে: "এই noisy image-এ কতটা noise আছে?"

(২) Monte Carlo sampling-এ কী?

  • প্রতিটি step-এ random Gaussian noise sample.
  • $x_{t-1} = \mu_\theta(x_t, t) + \sigma_t \cdot \epsilon$, $\epsilon \sim N(0, I)$।
  • এই Gaussian sample-ই "creativity" — same prompt থেকে different images.
  • Total sampling: $T = 50-1000$ steps.

(৩) Score-based view:

  • Network শেখে $\nabla_x \log p(x)$ — score function.
  • Langevin dynamics — score follow করে probable image-এ পৌঁছানো।
  • Stochastic Differential Equation (SDE) interpretation.

(৪) DDPM-এর সরল algorithm:

def sample_image(model, T=1000, shape=(3,256,256)):
    x = torch.randn(shape)  # pure noise
    for t in reversed(range(T)):
        z = torch.randn_like(x) if t > 0 else 0
        x = (1/sqrt(alpha[t])) * (x - (1-alpha[t])/sqrt(1-alpha_bar[t]) * model(x, t))
        x = x + sigma[t] * z  # MC sampling step
    return x

(৫) Sampler choice — Monte Carlo variants:

  • DDPM (১০০০ steps): ধীর, কিন্তু high quality.
  • DDIM (Song ২০২১): Deterministic-ish, ৫০ steps.
  • DPM-Solver: ১০-২০ steps, fast.
  • Euler, Heun: ODE solvers.

(৬) Why so much sampling?

  • Direct image generation high-D distribution থেকে — intractable.
  • Iterative refinement = MC chain.
  • প্রতিটি step ছোট, controllable.

(৭) Conditioning:

  • Text-to-image: classifier-free guidance — text-conditioned vs unconditional sample combine.
  • Inpainting: masked region-এ MC, rest fixed.
  • ControlNet: pose, depth-conditioned sampling.

(৮) Computational cost:

  • SDXL: ৫০ steps × ৩.৫B params = ~৫ seconds A100-এ।
  • Each step: full forward pass!
  • Distillation (LCM): ১-৪ steps possible.
  • Future: 1-step distilled diffusion.

(৯) Why MC works here:

  • High-D image space — grid impossible.
  • Manifold structure — MC explore efficiently.
  • Stochasticity = creativity.

(১০) Bangladesh use cases:

  • Bangla calligraphy generation.
  • Local content creation — fashion, food, festival imagery.
  • Educational content — historical Bengal scenes.
  • Privacy: local diffusion, no cloud upload.

মূল উপলব্ধি: Stable Diffusion-এর "magic" আসলে clever Monte Carlo. ১৯৪৭-এর random sampling idea + ২০২২-এর neural network = $20B industry. Beautiful continuity in mathematics.

প্র ০২ AlphaGo Monte Carlo Tree Search-এ Lee Sedol-কে হারায়। MCTS কীভাবে কাজ করে? Vanilla minimax-এর থেকে কেন better? Modern game AI-এ এর ভূমিকা?

MCTS (Coulom ২০০৬, Kocsis-Szepesvári ২০০৬) — game AI-এর একটি landmark. AlphaGo (২০১৬) এই algorithm-এর masterpiece. আজকের AlphaZero, MuZero, OpenAI Five — সবেই MCTS-ভিত্তিক।

(১) Game tree problem:

  • Chess: ~$10^{120}$ game states.
  • Go: ~$10^{170}$ — observable universe-এর atom-এর চেয়ে বেশি।
  • Brute force impossible.

(২) Vanilla minimax:

  • সব move evaluate, best বাছ — depth-limited.
  • Alpha-beta pruning helps, কিন্তু branching factor বড় হলে সমস্যা।
  • Heuristic evaluation function — domain expertise.

(৩) MCTS — ৪ ধাপ:

  1. Selection: Root থেকে leaf, UCB1 score-এ।
  2. Expansion: Leaf-এ নতুন child.
  3. Simulation (rollout): Random play to game end.
  4. Backpropagation: Result tree-এ update.

(৪) UCB1 — exploration vs exploitation:

$\text{UCB1}(s) = \dfrac{w_s}{n_s} + c\sqrt{\dfrac{\ln N}{n_s}}$

  • প্রথম term: average win rate (exploitation)।
  • দ্বিতীয় term: under-explored nodes-এ visit (exploration)।
  • $c$: balance constant.

(৫) AlphaGo — MCTS + Neural Networks:

  • Policy network: কোন move likely?
  • Value network: এই position-এ winning chance কত?
  • MCTS: NN-এর guidance-এ tree explore.
  • Random rollout-এর বদলে value network — efficient.

(৬) AlphaZero (২০১৭) — পরের generation:

  • No human games — pure self-play.
  • Single network: policy + value combined.
  • Chess, shogi, Go — all superhuman.
  • ৪ ঘণ্টায় Stockfish (chess world champion engine)-কে হারায়।

(৭) MuZero (২০১৯) — without rules:

  • Game rules জানে না — শেখে।
  • Atari games + Go + chess + shogi all handle.
  • Latent space planning.

(৮) Why MCTS > minimax:

  • Adaptive — অনিশ্চিত branches বেশি explore.
  • Anytime — যেকোনো সময় থামানো যায়।
  • Asymmetric — promising paths-এ বেশি depth.
  • Statistical backbone — আসলে multi-armed bandit.

(৯) MCTS-এর চ্যালেঞ্জ:

  • Tactical positions-এ short-term miss.
  • Memory: tree বড়।
  • Hyperparameter tuning ($c$, depth)।
  • Hidden information game (poker)-এ struggle.

(১০) MCTS beyond games:

  • Robot motion planning: Possible paths search.
  • Drug discovery: Molecular space exploration.
  • RL planning: Model-based RL.
  • LLM reasoning: Tree of Thoughts, MCTS-style decomposition.
  • AlphaCode (২০২২): Code generation-এ rollout.

(১১) AGI implications:

  • "Search + learning" — Sutton-এর বিখ্যাত "Bitter Lesson"।
  • MCTS = principled search; NN = learning.
  • একসাথে AGI-র recipe?

মূল উপলব্ধি: AlphaGo-এর সাফল্য — যাদু না, mathematics. MCTS-এর Monte Carlo intuition + deep learning = world-class game playing. আজকের ChatGPT-এর reasoning research-এও MCTS techniques. Old idea, modern application.

প্র ০৩ Monte Carlo-র "$1/\sqrt{n}$ convergence" — ১০x error কমাতে ১০০x sample. Variance reduction techniques — importance sampling, antithetic variates — কীভাবে এটি বাঁচায়?

$1/\sqrt{n}$ — Monte Carlo-র blessing ও curse. Slow convergence সমস্যা। ৭০ বছরের গবেষণায় অনেক variance reduction techniques. Modern AI-তে অপরিহার্য।

(১) কেন slow?

  • CLT: error standard deviation $\sigma/\sqrt{n}$।
  • $\sigma$ ছোট হলে — variance কম।
  • "Direct" $\sigma$ কমাতে পারলে — fewer samples.

(২) Importance Sampling:

  • "Important regions"-এ বেশি sample.
  • $E_p[f] = E_q[f \cdot p/q]$ — proposal distribution $q$।
  • Weights compensate for biased sampling.
  • Optimal $q^* \propto |f| \cdot p$ — variance ০।

উদাহরণ:

import numpy as np

# Naive: f(x) = exp(-x²/2) over [3, ∞)
n = 100000
x = np.random.uniform(3, 10, n)
naive = (10-3) * np.mean(np.exp(-x**2/2))

# Importance: sample from exponential (heavy tail)
x = 3 + np.random.exponential(1.0, n)
weights = np.exp(-(x-3)) * (10-3)  # ratio
better = np.mean(np.exp(-x**2/2) / np.exp(-(x-3)) * 1.0)
print(f"Naive variance: high. Importance: low.")

(৩) Antithetic Variates:

  • Pair $(X, X')$ where $X' = -X$ or symmetric.
  • $f(X) + f(X')$ — variance reduce if negatively correlated.
  • Especially good for symmetric integrands.
  • Half computational cost!

(৪) Control Variates:

  • $\hat{\theta} = \bar{f} - c(\bar{g} - E[g])$।
  • $g$ correlated with $f$, $E[g]$ known.
  • Reduce variance using known relationship.

(৫) Stratified Sampling:

  • Domain into strata, sample from each.
  • Variance always ≤ random sampling.
  • Cube discretization in low-D.

(৬) Quasi-Monte Carlo (QMC):

  • Random এর বদলে low-discrepancy sequences (Sobol, Halton)।
  • Convergence $O(\log^k n / n)$ — much better!
  • Caveat: low-D-এ ভাল, high-D-এ break.

(৭) Markov Chain MC (MCMC):

  • Complex distribution-এ sample সরাসরি কঠিন।
  • Markov chain তৈরি যার stationary distribution = target.
  • Metropolis-Hastings, Gibbs sampling, Hamiltonian MC.

(৮) AI-তে variance reduction:

  • Reparameterization trick (VAE): $z = \mu + \sigma \cdot \epsilon$ — gradient through sampling.
  • Control variates in RL: Advantage = Reward − Value baseline.
  • Generalized Advantage Estimation (GAE): Bias-variance trade.
  • REINFORCE বনাম PPO: Variance reduction-এ baseline.

(৯) Practical guidelines:

  • Always at least try antithetic — free 2x.
  • Importance sampling — domain knowledge থাকলে।
  • QMC — low-D, smooth integrands.
  • Stratified — যেখানে structure আছে।

(১০) Modern research:

  • Multi-level Monte Carlo (MLMC): Different precision levels.
  • Neural importance sampling: NN learns optimal proposal.
  • Sequential MC: Time-evolving distributions.

(১১) Computational reality:

  • GPU-এ vectorization — base MC দ্রুত।
  • Variance reduction ১০x ভাল = ১০x cheaper.
  • Production AI-তে cost matter.

মূল উপলব্ধি: "Just throw more samples" — toy approach. Production-এ variance reduction critical. Diffusion model-এ ৫০ steps vs ১০০০ steps — variance reduction-এর প্রয়োগ। Hidden art of Monte Carlo.

প্র ০৪ Bayesian Deep Learning-এ MC Dropout — model-এর uncertainty বের করতে। কীভাবে কাজ করে? কেন simple training-time dropout test-time uncertainty দেয়? Production-এ কোথায় ব্যবহার?

Gal & Ghahramani (২০১৬) এর মূল paper "Dropout as a Bayesian Approximation" — deep learning-এ uncertainty quantification-এর সবচেয়ে practical method. Theoretical elegance + practical simplicity.

(১) Standard Dropout:

  • Training-এ randomly neurons turn off (probability $p$)।
  • Test-এ all neurons on, scale by $(1-p)$।
  • Regularization — overfitting reduce.

(২) Gal-Ghahramani insight:

  • "Dropout = approximate Bayesian inference"।
  • প্রতিটি dropout mask = different network.
  • Multiple masks = ensemble = posterior approximation.

(৩) MC Dropout — test-time:

  • Dropout test-এও on রাখুন।
  • Same input N বার forward pass — different dropout masks.
  • N predictions-এর mean = prediction.
  • N predictions-এর variance = uncertainty.

(৪) Code:

import torch

def mc_predict(model, x, n_samples=100):
    model.train()  # dropout on!
    preds = []
    for _ in range(n_samples):
        with torch.no_grad():
            preds.append(model(x))
    preds = torch.stack(preds)
    mean = preds.mean(0)
    std = preds.std(0)  # uncertainty
    return mean, std

(৫) Two types of uncertainty:

  • Aleatoric: Data-noise uncertainty — irreducible.
  • Epistemic: Model uncertainty — more data → less.
  • MC Dropout primarily captures epistemic.

(৬) Benefits:

  • No new training — existing dropout model-এ applicable.
  • Theoretical foundation — variational inference.
  • Computationally cheap (relative to full BNN)।

(৭) Limitations:

  • $N$ forward passes — inference slower.
  • Calibration ভাল না — over/underconfident.
  • Dropout rate — hyperparameter sensitive.
  • Out-of-distribution detection limited.

(৮) Production use cases:

  • Medical imaging:
    • Diabetic retinopathy detection — uncertainty triage.
    • "Confident vs uncertain" — radiologist priority.
  • Self-driving cars:
    • Object detection uncertainty.
    • "Don't know what this is" — slow down.
  • Active Learning:
    • Most uncertain samples — label first.
    • Annotation cost reduce.
  • Anomaly detection:
    • High uncertainty = unusual input.

(৯) Alternatives:

  • Deep Ensembles: Multiple models trained independently. Often outperforms MC Dropout.
  • Bayesian NN (BNN): Explicit weight distributions. Computationally expensive.
  • SWAG: SGD trajectory-এ Gaussian fit.
  • Conformal Prediction: Distribution-free guarantees.

(১০) Calibration metrics:

  • Expected Calibration Error (ECE)।
  • Brier score.
  • Reliability diagram.

(১১) Recent advances:

  • Last-layer Bayesian: Just final layer Bayesian — efficient.
  • Functional MC Dropout: Function space.
  • Test-time augmentation: Input perturbations.

(১২) Bangladesh AI ethics:

  • Medical AI deploy — uncertainty critical.
  • "Auto-detected from X-ray" — confidence ছাড়া dangerous.
  • Bangla NLP-এ rare words — model uncertainty.
  • Loan default prediction — explain uncertainty to borrower.

(১৩) The bigger picture:

  • "Confident wrong" worst than "uncertain right"।
  • AI safety — uncertainty quantification critical.
  • Hallucination in LLMs — uncertainty calibration challenge.

মূল উপলব্ধি: MC Dropout — beautiful Monte Carlo application. ১৯৪৭-এর random sampling, ২০১৪-এর dropout, ২০১৬-এর Bayesian interpretation = production-ready uncertainty. Modern AI-এ confident predictions overrated; calibrated uncertainty undervalued.

অনুশীলন

  1. Estimate: মন্টে কার্লো দিয়ে $E[X^2]$ অনুমান করুন যেখানে $X \sim N(0, 1)$ (Gaussian)। তাত্ত্বিক উত্তর = ১। কত sample লাগে ০.০১-এর কম error-এ পৌঁছাতে?
    import numpy as np
    np.random.seed(0)
    for n in [100, 1_000, 10_000, 100_000, 1_000_000]:
        x = np.random.randn(n)
        est = np.mean(x**2)
        print(f"n={n:>9,}  E[X²] ≈ {est:.4f}  err={abs(est-1):.4f}")

    $E[X^2] = \text{Var}(X) + E[X]^2 = 1 + 0 = 1$। সাধারণত ১,০০,০০০ sample-এ error < ০.০১। Error $\sigma/\sqrt{n}$ — $\sigma = \sqrt{2}$ (Var of $X^2$ for Gaussian) → $n \approx 20{,}000$ enough.

  2. সিমুলেট করুন: দু'টি ছক্কা ছোঁড়ার যোগফল ৭ আসার সম্ভাবনা মন্টে কার্লো-তে বের করুন। তাত্ত্বিক উত্তর = $\frac{6}{36} = \frac{1}{6}$।
    import numpy as np
    np.random.seed(42)
    n = 1_000_000
    d1 = np.random.randint(1, 7, n)
    d2 = np.random.randint(1, 7, n)
    prob = np.mean((d1 + d2) == 7)
    print(f"P(sum=7) ≈ {prob:.5f}, theory = {1/6:.5f}")

    প্রায় $0.16667$ — সঠিক $1/6 = 0.16\overline{6}$। ৭ পাওয়ার ৬টি upায় (1+6, 2+5, 3+4, 4+3, 5+2, 6+1) ÷ ৩৬ মোট।

  3. চিন্তা করুন: "Bayesian Deep Learning" — কেন এটি প্রতিটি প্রশ্নে অনেক বার মডেল চালায়? মন্টে কার্লো-র সাথে সম্পর্ক?

    প্র ০৪-এ বিস্তারিত। সংক্ষেপে:

    • Bayesian DL-এ weights-এর posterior distribution থাকে।
    • Posterior থেকে multiple weight samples → multiple predictions.
    • Mean = best prediction. Variance = uncertainty.
    • MC Dropout — practical approximation: dropout-mask sampling.
    • $N$ samples = $N$ MC trials = uncertainty quantification.

    Production-এ medical, autonomous driving — যেখানে "I don't know" বলা জরুরি, সেখানে অপরিহার্য।

আরও পড়ুন · ABCL TECH-এ আপনার পরবর্তী পদক্ষেপ

কোড রানার কাজ না করলে? ব্রাউজারে কাজ না করলে Google Colab ব্যবহার করুন — Google-এর ফ্রি অনলাইন Python পরিবেশ, শুধু Gmail অ্যাকাউন্ট লাগে।
পূর্ববর্তী পাঠ
পাঠ ২৪ · ML-এর জন্য পরিসংখ্যান