পাঠ ৪ · ২৮-এর মধ্যে · মডিউল ১
Home / AI Courses / জেনারেটিভ AI / Latent Variable Models

Latent Variable Models — হিডেন কারণ

Latent variable models — the hidden cause structure
৭ মিনিট পড়া উচ্চ · Advanced z → x · graphical

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

  • Latent variable-এর ধারণা — hidden cause হিসেবে
  • Graphical model: $z \to x$ — generative process visualize
  • সরল থেকে জটিল: GMM → PCA → Factor Analysis → VAE
  • ELBO-র preview — latent variable model-এর training-এর মূল objective

১ · Latent variable কী

Latent variableLatent / Hidden Variableযে variable directly observe হয় না — কিন্তু observed data-র underlying cause হিসেবে কাজ করে। GMM-এ "cluster id"; VAE-তে neural code; topic modeling-এ "topic"। মানে — যা সরাসরি দেখা যায় না, কিন্তু observation-কে নিয়ন্ত্রণ করে। "Latent" = "lurking, hidden"।

একটি ছবিকে ভাবুন। আমরা দেখি ৩,০৭২টি pixel value (৩২×৩২×৩)। কিন্তু "ভিতরে" কী আছে — content, style, lighting, pose — এগুলোই আসল cause। এই hidden factors — latent variable।

Generative process

১) প্রথমে নাবালক একটি $z \sim p(z)$ sample হয় (latent prior)।
২) তারপর $z$-এর কন্ডিশনে $x \sim p(x|z)$ generate হয়।
৩) আমরা শুধু $x$ দেখি; $z$ infer করতে হয়।

২ · Graphical model — $z \to x$

Latent variable model-এর সবচেয়ে সরল graphical representation:

$$p(x, z) = p(z) \cdot p(x | z)$$

Marginal data distribution হলো:

$$p(x) = \int p(x | z) \cdot p(z) \, dz \quad \text{(continuous)}$$

বা discrete $z$-এর জন্য:

$$p(x) = \sum_{k} p(x | z=k) \cdot p(z=k)$$

একটি Daraz শপারের কথা ভাবুন। তিনি কিনেছেন: লিপস্টিক, শ্যাম্পু, শাড়ি, ফেসমাস্ক। আমরা শুধু ক্রয় ($x$) দেখি। কিন্তু latent কারণ ($z$) — "তিনি একজন ফ্যাশন-সচেতন মহিলা।" এই $z$ জানা থাকলে — পরবর্তী কেনাকাটা predict সহজ। Latent variable model এই hidden $z$ infer করে।

৩ · কেন latent variable

  • Compression: ১,০০,০০০ ছবি $\to$ ১০০-D latent code। Storage, computation save।
  • Structure discovery: Hidden factor — "lighting, pose, expression" — disentangle।
  • Manifold modeling: Real data low-D manifold-এ; latent space সেই manifold parametrize করে।
  • Sampling: Low-D $z \sim \mathcal{N}(0, I)$ থেকে sample, decoder চালিয়ে high-D $x$।
  • Interpolation: দু'টি ছবির latent-এ midpoint = "morphed" image।
  • Conditional generation: $z$-এ control inject — style, attribute manipulate।

৪ · সবচেয়ে সরল উদাহরণ — Mixture Model

Gaussian Mixture Model-এ latent variable $z \in \{1, 2, \ldots, K\}$ — discrete cluster ID।

$$p(z = k) = \pi_k, \qquad p(x | z = k) = \mathcal{N}(x; \mu_k, \Sigma_k)$$

$$p(x) = \sum_{k=1}^{K} \pi_k \cdot \mathcal{N}(x; \mu_k, \Sigma_k)$$

Generative process: প্রথমে dice ফেলে cluster বাছো ($z$), তারপর সেই cluster-এর Gaussian থেকে point ($x$)। Inference: data point দেখে কোন cluster-এর সম্ভাবনা কত।

৫ · Linear latent — PCA ও Factor Analysis

PCAPrincipal Component AnalysisLinear dimensionality reduction। Largest variance direction-এ data project। Pearson (১৯০১) — historically প্রথম latent variable model। Eigendecomposition-এ solved। (Pearson, ১৯০১) — সবচেয়ে পুরোনো latent model:

$$z \sim \mathcal{N}(0, I), \qquad x = W z + \mu + \epsilon$$

যেখানে $W$ একটি $d \times k$ matrix ($k \ll d$), $\epsilon$ small noise। PCA-এর latent space — high-D data-র "principal direction" বরাবর।

Factor Analysis PCA-র cousin — noise structure আরো flexible। Psychology, finance, marketing-এ "personality factor" আবিষ্কারের জন্য ১৯০৪ থেকে ব্যবহৃত (Spearman)।

৬ · Non-linear latent — VAE preview

Variational AutoencoderVAEKingma & Welling (২০১৪)-এর landmark paper। Neural network দিয়ে latent variable model — encoder $q(z|x)$ ও decoder $p(x|z)$। Generative AI-র modern era-র সূচনা। (Kingma & Welling, ২০১৪) — neural network দিয়ে latent variable model:

$$z \sim \mathcal{N}(0, I), \qquad x \sim p_\theta(x | z) = \mathcal{N}(x; \mu_\theta(z), \sigma_\theta(z))$$

$\mu_\theta, \sigma_\theta$ — neural network। Decoder $z$ থেকে $x$ generate। Encoder $q_\phi(z|x)$ — inference-এর জন্য — approximation।

Training objective — ELBOEvidence Lower BoundLog-likelihood-এর lower bound। Latent variable model-এ exact log-likelihood intractable, তাই ELBO maximize। VAE, Diffusion — সব ELBO-based।:

$$\log p(x) \geq \mathbb{E}_{q(z|x)}[\log p(x|z)] - \text{KL}(q(z|x) \| p(z))$$

ELBO-র দু'টি অংশ: (১) reconstruction term — $z$ থেকে $x$ ভালো recover; (২) KL regularizer — $q(z|x)$ prior $p(z)$-র কাছাকাছি। এই balance VAE-র creativity-র মূল।

৭ · Sequential latent — Diffusion

Diffusion model-এ latent ১টি না — $T$টি ($z_1, z_2, \ldots, z_T$)। প্রতিটি step-এ একটু noise যোগ। Reverse process — noise থেকে data।

$$x = z_0, \quad z_t = z_{t-1} + \text{noise}_t, \quad p(z_T) \approx \mathcal{N}(0, I)$$

Stable Diffusion, DALL-E 3, Sora — সব এই principle-এ। অনেকগুলো ছোট latent step বড় চমৎকার generation দেয়। বিস্তারিত পাঠ ১৩-তে।

Latent Variable Model — সরল থেকে জটিল z (hidden) → x (observed) z latent (hidden) p(x|z) x observed z ~ p(z) [prior] q(z|x) inference কোথায় কী z GMM: z = cluster ID (discrete) PCA: z = linear coords VAE: z = neural code Diffusion: z₁..zₜ sequential — সরলতা থেকে সক্ষমতা — GMM PCA FA VAE Diffusion discrete linear + noise non-linear sequential সব একই principle: z → x, কেবল জটিলতা ভিন্ন।
Latent variable model-এর spectrum: GMM-এর discrete $z$ থেকে Diffusion-এর sequential $z_t$ পর্যন্ত — মূল idea একই।

৮ · Python-এ latent variable — PCA-র উদাহরণ

সবচেয়ে সরল latent variable model — PCA। MNIST digit-এর latent space visualize করি।

Python · NumPy + sklearn
import numpy as np
from sklearn.datasets import load_digits
from sklearn.decomposition import PCA

# 8x8 digit images = 64-D
digits = load_digits()
X = digits.data        # shape (1797, 64)
y = digits.target      # 0-9 labels

# Latent dimension = 2 (visualization-এর জন্য)
pca = PCA(n_components=2)
z = pca.fit_transform(X)   # shape (1797, 2)

print(f"Original dimension: {X.shape[1]}")
print(f"Latent dimension: {z.shape[1]}")
print(f"Explained variance: {pca.explained_variance_ratio_.sum():.2%}")

# এখন latent space থেকে নতুন digit generate
z_new = np.random.randn(5, 2) * z.std(axis=0)
x_new = pca.inverse_transform(z_new)
print(f"\n৫টি 'fictional' digit তৈরি: shape {x_new.shape}")
print("(এগুলো 8x8 image-এ reshape করে imshow দিয়ে দেখা যাবে)")

    
৬৪-D digit-কে ২-D latent-এ compress — তারপর random latent থেকে নতুন digit। এটাই latent variable generative model-এর সারমর্ম। PCA linear, তাই output blurry; VAE/Diffusion non-linear, তাই sharp।

৯ · Inference — $z$ infer করা

Latent variable model-এ মূল চ্যালেঞ্জ — given $x$, $z$ কী? অর্থাৎ $p(z|x)$ compute। Bayes-এর সূত্রে:

$$p(z|x) = \frac{p(x|z) p(z)}{p(x)} = \frac{p(x|z) p(z)}{\int p(x|z') p(z') dz'}$$

Denominator-এর integral সাধারণত intractable। তাই tricks:

  • Exact: Conjugate prior থাকলে (e.g., GMM-এ EM)।
  • MCMC: Sample-based — slow but accurate।
  • Variational: Approximate $q(z|x) \approx p(z|x)$ — VAE-র approach।
  • Amortized inference: একটি network সব $x$-এর জন্য $q(z|x)$ predict — fast।

১০ · Disentanglement — কেন matters

Ideal latent space-এ — প্রতিটি dimension একটি independent factor capture করবে। যেমন $z_1$ = "lighting", $z_2$ = "pose", $z_3$ = "expression"।

Why useful:

  • Interpretability — কোন dimension কী represent।
  • Controllable generation — শুধু lighting বদলান, পruba অপরিবর্তিত।
  • Few-shot learning — disentangled feature transfer easier।

β-VAE (Higgins et al., ২০১৭) — disentanglement encourage করে। কিন্তু "perfect disentanglement" অর্জন এখনো open research problem।

Latent variable model শক্তিশালী, কিন্তু training tricky — KL collapse, posterior collapse, mode collapse — সব common। Practical training-এ অভিজ্ঞতা ও hyperparameter tuning critical।

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

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

প্র ০১ Latent variable "really exist" করে — নাকি modeling convenience? Plato-র Cave থেকে শুরু করে modern ML-এ এই দার্শনিক প্রশ্ন কীভাবে এসেছে?

এটা গভীরতম দার্শনিক প্রশ্ন AI-তে। ২,৫০০ বছর আগে Plato-র "Cave" allegory: গুহার দেয়ালে দেখা ছায়া (observation) আসল না — পেছনে আসল object (latent reality)।

"Really exists" view (Realism):

  • মানুষের মুখের ছবিতে — pose, lighting, expression — physically exist করে। Camera সেগুলোকে capture করে।
  • Latent variable হলো এই hidden physical cause-এর mathematical representation।
  • Disentangled VAE যদি "true" pose dimension খুঁজে পায় — সেটা reality discover।
  • Causality framework (Pearl) — latent = unobserved confounder।

"Modeling convenience" view (Instrumentalism):

  • Latent শুধু gibi tool — model fit-এর জন্য numerical trick।
  • Different models-এ different latent — "true" না কোনো একটাও।
  • "Identifiability theorem" — same data-র জন্য infinitely many latent representation। কোনো একটা privileged না।
  • Locatello et al. (২০১৯) — disentanglement theoretically impossible without inductive bias।

মধ্যপন্থী — Pragmatism:

  • "Existence" depends on usefulness — latent যদি interpretation, prediction, intervention-এ কাজে লাগে — তাহলে relevant।
  • Bohr-এর quote: "Everything we call real is made of things that cannot be regarded as real।" — physics-এও same।
  • Latent = "useful fiction" — কিন্তু এই fiction empirically tested।

ML-এ এই debate-এর practical impact:

  • Realist camp: Causal representation learning। "True latent" খোঁজা — interventional data দিয়ে।
  • Pragmatist camp: Foundation model-এ latent uninterpretable — কাজ করলেই হলো। "Black box" approach।
  • Mechanistic interpretability (Anthropic): মাঝের পথ — internal representation reverse-engineer। "Features" আবিষ্কার।

একটা ঐতিহাসিক উদাহরণ:

  • ১৯০৪ — Spearman "g factor" (general intelligence) আবিষ্কার করেন factor analysis-এ।
  • "g exists" — ১২০ বছরের argument।
  • আজও psychology-তে — কেউ realist, কেউ instrumentalist।
  • Same pattern modern AI-তে — "GPT-4-র কি understanding আছে?" — same dispute।

Bangladesh context:

  • "কাস্ট", "শ্রেণি", "ধর্ম" — social science-এ latent variable। Real না measurement convenience?
  • AI-তে যদি এমন latent infer হয় — discrimination risk। Fairness-এর জন্য awareness।

মূল উপলব্ধি: "Latent really exists?" — এই প্রশ্নের universal উত্তর নেই। কিন্তু AI engineer হিসেবে — দু'টি দৃষ্টিভঙ্গি জানা important। Realist হলে — interpretability ও causality-তে বিনিয়োগ। Instrumentalist হলে — performance-অগ্রাধিকার। মধ্যপন্থা — context-dependent। Latent variable AI-র philosophical heart — শুধু math না।

প্র ০২ Latent space-এ "interpolation" — দু'টি ছবির মাঝে morph করা যায়। কিন্তু কেন কিছু interpolation natural-looking, কিছু weird? Latent geometry-র ভূমিকা কী?

Latent interpolation generative AI-র সবচেয়ে striking demo — দু'টি face-এর মধ্যবর্তী "ভাবনার মুখ" আঁকা। কিন্তু geometry-র subtlety জানা না থাকলে — disastrous results।

Linear interpolation — সবচেয়ে সাধারণ:

  • $z_t = (1-t) z_A + t z_B$ for $t \in [0,1]$।
  • Simple, intuitive — কিন্তু ভুল assumption: latent space Euclidean।
  • VAE-এ — $z \sim \mathcal{N}(0, I)$ — high-D Gaussian-এ density বেশি concentric shell-এ।
  • Linear path origin-এর কাছে যায় — যেখানে density কম — "weird" reconstruction।

Spherical interpolation (slerp) — better:

  • White (২০১৬)-এর observation: high-D Gaussian effectively shell-distributed।
  • Slerp shell-এ along great-circle — density preserved।
  • $$z_t = \frac{\sin((1-t)\Omega)}{\sin\Omega} z_A + \frac{\sin(t\Omega)}{\sin\Omega} z_B$$
  • BigGAN, StyleGAN-এ standard practice।

Why geometry matters — five issues:

  • (১) Curvature: Latent manifold flat না — curved। Geodesic interpolation needed (Arvanitidis, Hauberg)।
  • (২) Density holes: Latent space-এ "void" থাকে যেখানে training data point নেই। সেখানে decoder ill-defined।
  • (৩) Non-isotropic: Latent dimension-গুলোর scale ভিন্ন। সবগুলোতে সমানভাবে interpolate ভুল।
  • (৪) Topology: Donuts (mug ছবি) — topology-তে hole। Latent space যদি Euclidean হয়, এই topology mismatch।
  • (৫) Disentanglement: Pose ও lighting মিশে গেলে — interpolation-এ both change → unnatural।

StyleGAN-এর breakthrough:

  • Latent $z$ → mapping network → intermediate $w$ → generator।
  • $w$ space disentangled, smoother — interpolation natural।
  • "Style mixing" — different layer-এ different $w$ — pose ও style separate control।

Diffusion-এর interpolation:

  • DDIM (deterministic) latent space provide।
  • SDEdit — noisy intermediate থেকে edit।
  • Stable Diffusion-এ "img2img" এই principle।

Practical creative use:

  • Movie morphing — A থেকে B-তে smooth transition।
  • Music generation — দু'টি genre-র মধ্যবর্তী মিউজিক।
  • Drug discovery — দু'টি molecule-এর মধ্যবর্তী potential candidate।
  • Protein design — AlphaFold latent-এ interpolation।

Bangladesh context:

  • "নকশী কাঁথা" pattern generation — দু'টি style-এর মধ্যবর্তী নতুন pattern।
  • Bangla calligraphy interpolation — historical style থেকে modern।
  • Music — রবীন্দ্রসঙ্গীত ও আধুনিক ফিউশন।

মূল উপলব্ধি: Latent space-এ geometry — generative AI-র "gravitational field"। Naive Euclidean assumption fail করে। Slerp, geodesic, disentanglement — geometry-aware methods হলে interpolation natural। এটা AI-art ও creative tool-এর মূল technical foundation।

প্র ০৩ Bangladesh-এর e-commerce data-তে customer segmentation-এ latent variable model কীভাবে ব্যবহার হয়? Daraz-এর জন্য একটি practical pipeline ডিজাইন করুন।

Customer segmentation — e-commerce-এ classic problem। Discrete cluster (rule-based) থেকে continuous latent (learned) — এই evolution বাংলাদেশের context-এ রিভিউ করি।

Traditional rule-based segmentation:

  • "High-value customer" = monthly spend > ৫,০০০ taka।
  • "Frequent buyer" = >১০ orders/month।
  • "At-risk" = no order in ৬০ days।
  • সমস্যা: arbitrary threshold, brittle, doesn't capture multi-dimensional behavior।

Latent variable approach — Daraz-এর জন্য pipeline:

Stage 1 — Feature engineering:

  • RFM: Recency, Frequency, Monetary।
  • Behavioral: cart abandonment, search queries, page dwell time।
  • Categorical: top categories, brand affinity।
  • Temporal: day-of-week pattern, seasonality (ঈদ, পূজা)।
  • Geographic: division, urban/rural।
  • Device/channel: mobile vs desktop, app vs web।
  • Result: ৫০-১০০ feature per customer।

Stage 2 — GMM (latent = discrete cluster):

  • $K = 8$-$15$ clusters (BIC criterion-এ)।
  • Each cluster ~"persona": "Bargain hunter", "Premium tech enthusiast", "Beauty-focused", "Eid shopper"।
  • Soft assignment — একই customer multiple cluster-এ partial membership।
  • Output: marketing team-এর জন্য interpretable persona।

Stage 3 — VAE (latent = continuous code):

  • ৫০-D customer → ৮-D latent।
  • Smooth interpolation — "this customer is 60% premium-buyer, 40% price-sensitive"।
  • Anomaly detection — low likelihood = unusual customer (potential fraud বা new segment)।
  • Synthetic customer generation — testing, marketing simulation।

Stage 4 — Downstream tasks:

  • Recommendation: Latent code matrix factorization-এ। "Similar latent → similar product preference।"
  • Churn prediction: Latent trajectory monitoring — gradual change → likely to churn।
  • Lifetime value: Latent থেকে CLV regress।
  • Campaign targeting: Specific latent region-এ customers বাছাই।

Bangladesh-specific considerations:

  • Seasonality: ঈদ-উল-ফিতর (massive spike), পূজা, পহেলা বৈশাখ — latent must encode।
  • Cash on Delivery: ৭০%+ orders COD — different behavioral pattern, must feature।
  • Multilingual: Bangla vs English search query — language preference latent dimension।
  • Network effect: "WhatsApp share" — viral product detection।
  • Regional: Dhaka vs Chittagong vs Sylhet — distinct shopping pattern।
  • Privacy: Religion infer ("ঈদ active") — sensitive। Avoid explicit, regulate use।

Production challenges:

  • Latent drift — customer behavior change over time। Monthly retraining।
  • Cold start — নতুন customer-এর latent কী?
  • A/B testing — latent-based targeting vs rule-based, statistical rigor।
  • Explainability — "Why this product recommended?" regulatory question।

Real-world references:

  • Amazon — DSSTNE (deep sparse net) recommendation।
  • Spotify — collaborative filtering with latent factor।
  • Netflix — Matrix factorization-এ latent personality।
  • Pinterest — graph + latent embedding।

মূল উপলব্ধি: Latent variable model customer segmentation-কে rule-based থেকে continuous, learned, multi-dimensional করেছে। বাংলাদেশের e-commerce ($1B+ market) — এই technique competitive advantage। Daraz, Chaldal, Foodpanda — যারা latent-aware tech build করবে — তারা winner।

প্র ০৪ "Posterior collapse" — VAE training-এর কুখ্যাত সমস্যা। কী, কেন ঘটে, এবং solution কী? Generative AI-র অন্যান্য collapse-এর সাথে এর সম্পর্ক?

Posterior collapse — VAE-র "achilles heel"। Bowman et al. (২০১৬) text VAE-তে প্রথম report।

কী ঘটে:

  • Encoder $q(z|x)$ effectively prior $p(z) = \mathcal{N}(0,I)$ বনে যায়।
  • মানে — $z$ data-র কোনো information carry করে না।
  • Decoder $z$ ignore — prior-মতো random latent থেকেও same output।
  • Latent variable model একটি unconditional generator-এ degrade।

কেন ঘটে — তিনটি কারণ:

  • (১) ELBO-র asymmetric optimization: $$\text{ELBO} = \mathbb{E}[\log p(x|z)] - \beta \cdot \text{KL}(q(z|x) \| p(z))$$ KL term encourage $q$ → $p$। যদি reconstruction term-ই $z$ ছাড়াই satisfy হয় (powerful decoder), KL-ই dominate করে।
  • (২) Strong decoder problem: Autoregressive decoder (PixelCNN, transformer) — $x$-এর pattern নিজেই capture করে; $z$-র দরকার পড়ে না।
  • (৩) Optimization landscape: Local minimum যেখানে $q \approx p$ — easy to reach। Better solution-এ যেতে gradient signal weak।

Solutions — অনেক:

  • KL annealing: Training-এর শুরুতে $\beta = 0$, ধীরে ধীরে বাড়ান। Decoder প্রথমে $z$-নির্ভর হয়, তারপর KL pressure।
  • Free bits: Per-dimension KL minimum — "দরকার নেই latent dimension"-গুলো KL=0-এ বসে যায়, কিন্তু others active থাকে।
  • Skip connections: Decoder-এ $z$-কে multiple layer-এ inject — ignore কঠিন।
  • Weak decoder: Less expressive decoder যাতে $z$-নির্ভর হতে বাধ্য হয়।
  • VQ-VAE: Discrete latent — collapse strict-ভাবে impossible।
  • InfoVAE: KL-এর বদলে MMD — different geometry।

Generative AI-র অন্যান্য collapse:

  • Mode collapse (GAN): Generator only few mode produce করে। Discriminator-কে fool করতে সবচেয়ে easy mode-এ stuck। WGAN, spectral normalization, mini-batch discrimination — solutions।
  • Index collapse (VQ-VAE): Codebook-এর অধিকাংশ entry use না। Codebook reset, EMA update — fix।
  • Attention collapse (Transformer): Attention head একই pattern শিখে — diversity loss। Layer normalization, attention dropout।
  • Model collapse (training on AI data): Shumailov et al. (২০২৪) — recursive AI-trained-on-AI-output → distribution narrowing।
  • Reasoning collapse (RLHF): Reward hacking — model reward function exploit, capability harm।

Common pattern:

  • সব collapse — "easy solution" → "rich solution"-এর মাঝে gap।
  • Optimization কোনো না কোনো দিকে greedy — সব objective satisfy করার জন্য।
  • Solution: regularization, careful schedule, architectural inductive bias।

Theoretical insight:

  • "Information bottleneck" framework (Tishby) — model্কে information bottleneck force করতে হয়।
  • VAE-র latent এই bottleneck — collapse মানে bottleneck closed।
  • Trade-off: compression vs reconstruction — fundamental।

Practical lesson for engineers:

  • VAE train করছেন? — KL annealing default।
  • Validation: "$z$ randomize করলে output change হচ্ছে?" — না হলে collapse।
  • Generation diverse? — Mode collapse check।
  • Latent visualize — meaningful structure থাকতে হবে।

মূল উপলব্ধি: Posterior collapse generative AI-র optimization-এর fragility-র representative। মডেল objective satisfy করতে চায়, কিন্তু "easy way out" নিতে পারে। Engineering = এই shortcut block করা। Mode collapse, attention collapse, model collapse — সব same family-র সমস্যা। Generative AI-র history অনেকটা — "different ways things collapse, and how to prevent each।"

অনুশীলন

  1. চিনুন: নিচের প্রতিটি model-এর latent variable কী?
    • (ক) Hidden Markov Model
    • (খ) Topic model (LDA)
    • (গ) Word2Vec
    • (ঘ) StyleGAN
    • (ক) HMM-এ latent = state sequence $z_1, z_2, \ldots, z_T$ (discrete)।
    • (খ) LDA-তে latent = topic distribution per document, word-topic assignment।
    • (গ) Word2Vec-এ latent = word embedding (continuous vector)।
    • (ঘ) StyleGAN-এ latent = $z \in \mathbb{R}^{512}$ + intermediate $w$।
  2. Code চেষ্টা: sklearn-এর GMM ব্যবহার করে একটি ২-D synthetic dataset-এ K=3 fit করুন। প্রতিটি cluster-এর latent assignment ও probability print করুন।
    import numpy as np
    from sklearn.mixture import GaussianMixture
    from sklearn.datasets import make_blobs
    
    X, _ = make_blobs(n_samples=300, centers=3, random_state=42)
    
    gmm = GaussianMixture(n_components=3, random_state=0).fit(X)
    z_hard = gmm.predict(X)         # hard assignment
    z_soft = gmm.predict_proba(X)   # soft probability
    
    print("First 5 points:")
    for i in range(5):
        print(f"  point={X[i].round(2)}, cluster={z_hard[i]}, prob={z_soft[i].round(2)}")
    
    # Latent থেকে নতুন sample
    new_X, new_z = gmm.sample(5)
    print(f"\n৫টি নতুন (z, x) pair generated")
  3. ভাবুন: Bangladesh-এর হাসপাতালের patient diagnosis-এ latent variable কী হতে পারে? কী ৩টি observed feature, ১টি latent factor — propose করুন।

    Example design:

    Observed features ($x$):

    • Symptoms (jwor, kashi, dehydration ইত্যাদি — vector)।
    • Lab results (CBC, blood sugar, X-ray)।
    • Vital signs (BP, pulse, temperature)।

    Latent factor ($z$):

    • "Disease state" — discrete (dengue, typhoid, COVID, malaria) বা continuous (severity score)।
    • "Patient health profile" — chronic conditions, immune status।

    Use: $p(x|z=\text{dengue})$ — symptom pattern given disease। Bayes-এ — $p(z|x)$ — diagnosis।

    Bangladesh-এ — limited specialist; AI-assisted triage এই latent inference-এ। ICDDR,B-র মতো organization এই pipeline build করতে পারে।

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

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