𝐈𝐧𝐟𝐢𝐧𝐢𝐭𝐲 𝐂𝐒
201 subscribers
122 photos
1 video
3 files
34 links
Your daily source for Artificial Intelligence (AI), Machine Learning (ML), Deep Learning, and Computer Science trends. We share coding resources, projects, tech news, and updates.

#Infinitycs
Download Telegram
Article 20: PCA (Principal Component Analysis) – Let's extract the data 📉


PCA කියන්නේ Unsupervised Learning වල ඉතාමත් තීරණාත්මක කොටසක්. කලින් ආටිකල් වලින් අපි data clusters වලට බෙදන හැටි ඉගෙන ගත්තා. හැබැයි ප්‍රායෝගිකව අපිට ලැබෙන data වල Features සිය ගණනක් හෝ දහස් ගණනක් තියෙන්න පුළුවන්. මේ වගේ ලොකු data ප්‍රමාණයක් Process කරන එක මාරම අමාරු වැඩක් වගේම ඒවා Visualize කරන එකත් කළ නොහැක්කක්. මෙන්න මේ ප්‍රශ්නේ විසඳන්න තමයි Dimensionality Reduction පාවිච්චි කරන්නේ. PCA එහෙමත් නැත්තම් Principal Component Analysis කියන්නේ ඒකෙ alsorithm එකක්. තවත් පැහැදිලි කරොත් PCA කියන්නෙ දත්තවල තියෙන variance හැකිතාක් ආරක්ෂා කරගනිමින් ඒවගෙ තියෙන Features ගණන අඩු කරන Linear technology එකක්. ⚙️✂️

01. Foundation Level 🏛

හිතන්න ඔයා මල් පෝච්චියක පොටෝ එකක් ගන්නවා කියලා. මල් පෝච්චිය කියන්නේ 3D object එකක්. හැබැයි පොටෝ 2D තලයක්. ඔයා හොඳම Angle එකකින් ෆොටෝ එක ගත්තොත් ඒ 2D පින්තූරය බැලුවම වුණත් මල් පෝච්චියේ හැඩය ගැන හොඳ අවබෝධයක් ගන්න පුළුවන්. PCA එකෙන් කරන්නේ අන්න ඒ වගේ වැඩි මානයන් ගණනක තියෙන දත්ත වැදගත්ම තොරතුරු ටික විතරක් ඉතිරි කරගෙන අඩු මානයන් ගණනකට Project කරන එක.

02. The mathematics behind PCA 🧬🧮

PCA වැඩ කරන්නේ කොහොමද කියලා තේරුම් ගන්නනම් Linear Algebra වල තියෙන සංකීර්ණ සංකල්ප කිහිපයක් දැනගන්නම ඕනේ.

I. Standardization
PCA algorithm එක Variance එක මත පදනම් වෙන නිසා සෑම Feature එකකම Mean එක 0 සහ Standard Deviation එක 1 විදියට සකස් කරන්න ඕනි.

II. Covariance Matrix
Data වල තියෙන විවිධ Features එකිනෙකට සම්බන්ධ වෙන්නේ කොහොමද කියලා බලන්න තමා මේක පාවිච්චි කරන්නේ. n පරාසයක features වලට මේක n by n matrix එකක්.

Cov(X,Y) = ((∑(Xᵢ −X̄)(Yᵢ −Ȳ)) / (n − 1))
(
සමීකරණේ පැහැදිලි නැත්නම් මෙතනින් බලන්න)

III. Eigenvectors සහ Eigenvalues
මේක තමයි PCA වල වැදගත්ම කොටස. Covariance matrix ැකෙන් අපි Eigenvectors සහ Eigenvalues ගණනය කරනවා.

● Eigenvectors - දත්ත විසිරිලා තියෙන ප්‍රධාන දිශාවන් (Principal Components) පෙන්වනවා.

● Eigenvalues - ඒ ඒ දිශාවලට දත්ත කොච්චර ප්‍රමාණයක් විසිරිලා තියෙනවද (Variance) කියලා පෙන්නන විශාලත්වය.

Av = λv


A = Matrix එක
v = Eigenvector
λ = Eigenvalue

03. The Process: SVD (Singular Value Decomposition) 🏎💨

නූතන ML Libraries (Scikit-learn වගේ) PCA ගණනය කරන්න ගොඩක් වෙලාවට පාවිච්චි කරන්නෙ SVD. මේක Covariance matrix එකක් හදනවට වඩා ගණිතමය වශයෙන් Stable ක්‍රමයක්. මේකෙදි ඕනම M by N matrix එකක් matrices 3ක ගුණිතයක් විදියට දක්වනවා.

A = UΣVᵀ

04. Explained Variance Ratio 📊📈

PCA වලින් පස්සේ අපි බලන්න ඕනේ මුල් දත්තවල තිබුණු තොරතුරු එහෙමත් නැත්නම් Variance වලින් කොච්චර ප්‍රමාණයක් අලුත් Principal Components වල තියෙනවද කියලා. උදාහරණයක් විදිහට පළමු Principal Components දෙකෙන් (PC1 & PC2) මුළු දත්තවලින් 95% ක තොරතුරු පෙන්වනවා නම් අපිට පුළුවන් ඉතිරි 5% අතහැරලා මානයන් ගණන 2කට අඩු කරන්න. 📉

05. Limitations of PCA 🚧🛑

● Linear Assumption - PCA උපකල්පනය කරන්නේ data අතර තියෙන්නේ linear සම්බන්ධතාවයක් කියලා. Data Non-linear විදියට තියෙනවනම් PCA සාර්ථක වෙන්නෙ නෑ.
● Interpretability - PCA වලින් පස්සේ ලැබෙන අලුත් Features (PC1, PC2) මොනවද කියලා පැහැදිලි කරන්න අමාරුයි (ඒවා මුල් Features වල මිශ්‍රණයක්).

සාරංශයක් විදියට PCA කියන්නේ විශාල දත්ත ගොනුවක තියෙන අනවශ්‍ය දත්ත (Redundancy data) ඉවත් කරලා වැදගත්ම තොරතුරු (Maximum Variance) සහිත නව අක්ෂයන් (Principal Components) සොයා ගන්න mathematical process එකක්. මේක Eigen-decomposition හෝ SVD හරහා සිදු කරන අතර මොඩල් එකක් වේගවත් කරන්න සහ data visualize කරන්න මේක අත්‍යවශ්‍ය මෙවලමක්. ඊලග ආටිකල් එකෙන් (Article 21) අපි කතා කරන්නේ Non-linear දත්ත සඳහා පාවිච්චි කරන t-SNE සහ UMAP ගැන. 🙊😁

✍️ @TheInfinityAI
2🔥1
Cov(X,Y) = ((∑(Xᵢ −X̄)(Yᵢ −Ȳ)) / (n − 1))
A = UΣVᵀ
2🔥1
Article 21: Non-linear Dimensionality Reduction – Mathematical Analysis of t-SNE and UMAP 🌀📉


අපි කලින් ඉගන ගත්ත PCA වලින් දත්ත වල Linear සම්බන්ධතා හඳුනාගත්තත් දත්ත ඉතාමත් සංකීර්ණ වක්‍ර (Manifolds) විදියට විසිරිලා තියෙනකොට PCA අසාර්ථක වෙනවා. එතකොට අපි පාවිච්චි කරන්නේ දත්තවල Local Structure එක ආරක්ෂා කරන ඊට වඩා උසස් algorithms.

01. t-SNE (t-Distributed Stochastic Neighbor Embedding) 🧩

t-SNE කියන්නේ data points අතර තියෙන Probabilities මත පදනම් වෙලා ක්‍රියා කරන algorithm එකක්.

I. High-Dimensional Similarity (Gaussian Kernel)
ඉහළ මානවලදි, ලක්ෂ්‍ය xⱼ ලක්ෂ්‍ය xᵢ වල අසල්වැසියෙකු වීමේ සම්භාවිතාව (p₍ⱼ∣ᵢ₎) ගණනය කරන්නේ Gaussian Distribution එකකින්.

p₍ⱼ∣ᵢ₎ = ((exp(− ∥xᵢ − xⱼ∥²/2σᵢ²)) / (∑₍ₖ≠ᵢ₎exp(− ∥xᵢ − xₖ∥²/2σᵢ²)))

II. Low-Dimensional Similarity (Student's t-Distribution)
පහළ මානයේදී (2D), අපි Gaussian වෙනුවට Student's t-distribution (with 1 degree of freedom) පාවිච්චි කරනවා. මේකට හේතුව තමා Crowding Problem (ඉහළ මානයේ සිට පහළට එද්දී දත්ත ලක්ෂ්‍ය එකම තැනක ගොඩ ගැසීම) වළක්වා ගැනීමට t-distribution එකේ ඇති Heavy Tail එක උදව් වීම.

qᵢⱼ = (((1 + ∥yᵢ − yⱼ∥²)⁻¹) / (∑₍ₖ≠ₗ₎(1 + ∥yₖ − yₗ∥²)⁻¹))

III. The Cost Function: Kullback-Leibler (KL) Divergence

t-SNE වල ඉලක්කය වෙන්නෙ P ව්‍යාප්තිය සහ Q ව්‍යාප්තිය අතර ඇති වෙනස අවම කරන එක. මෙහිදී Gradient Descent පාවිච්චි කරන්නේ මේ KL Divergence එක අඩු කරන්න.

C = KL(P∣∣Q) = ∑ᵢ∑ⱼpᵢⱼlog ((pᵢⱼ) / (qᵢⱼ))

02. UMAP (Uniform Manifold Approximation and Projection) 🕸

UMAP කියන්නේ t-SNE වලට වඩා වේගවත් වගේම දත්තවල Global Structure එක වඩා හොඳින් ආරක්ෂා කරන අලුත් තාක්ෂණයක්. මේකේ පදනම වැටෙන්නේ Riemannian Geometry සහ Algebraic Topology මත.

I. Topological Structure Construction
UMAP වලින් දත්ත විසිරිලා තියෙන ආකාරය ඇසුරෙන් Fuzzy Simplicial Complex එකක් නිර්මාණය කරනවා. මේකෙදි එක් එක් ලක්ෂ්‍යය වටා ඇති ප්‍රදේශය (Neighborhood) Locally Uniform බව උපකල්පනය කරනවා.

II. Optimization (Cross Entropy)
t-SNE වලදී KL Divergence පාවිච්චි කරද්දි UMAP විසින් Binary Cross Entropy පාවිච්චි කරමින් ඉහළ මානයේ සහ පහළ මානයේ තියෙන ජ්‍යාමිතික ව්‍යුහයන් අතර සම්බන්ධතාවය ප්‍රශස්ත කරනව.

∑₍ₑ∈E₎wₕ(e)log (((wₕ(e)) / (wₗ(e))))+ (1 − wₕ(e))log (((1 − wₕ(e)) / (1 − wₗ(e))))

මේකේ wₕ සහ wₗ කියන්නේ ඉහළ සහ පහළ මානයන්හි ඇති edge weights.

03. Advanced Implementation Details 🚀

t-SNE සාමාන්‍යයෙන් අහඹු ලෙස (Random) ආරම්භ කරන හින්දා UMAP වලින් Graph Laplacian හරි PCA පාවිච්චි කර වඩා හොඳ ආරම්භයක් ලබා ගන්නවා. t-SNE හි වේගය O(N^2) හෝ O(N log N) (Barnes-Hut) වෙද්දී UMAP හි වේගය O(N^{1.14}) වගේ ඉතා අඩු අගයක්. ඒ හින්දා විශාල දත්ත ගොනු වලට UMAP අතිශය සාර්ථකයි. 🎓

අපි අද කතා කලේ Dimensionality Reduction වල තවත් කොටසක්. ඊලග ආටිකල් එකෙන් (Article 22) Gaussian Mixture Models (GMM) සහ EM Algorithm ගැන කතා කරමු. 🧠⏭️ 🙊😁

✍️ @TheInfinityAI
3
progit.pdf
18 MB
Pro Git (Second Edition) - Everything you need to know about Git 📕🔧

A complete and practical guide to Git version control—from basics to advanced workflows. Ideal for developers at any level.

👨‍💻 Authors: Scott Chacon & Ben Straub
🏢 Publisher: Apress

📚 Online Git Book: Link


📌 Credit:
Shared for educational purposes only. All rights belong to the authors and publisher.

Happy learning & keep growing! 💡📖

✍️ @TheInfinityAI
3🐳1
Gaussian Mixture Models (GMM) and EM Algorithm 🎲
Article 22: Gaussian Mixture Models (GMM) and EM Algorithm 🎲📈

In the last article, we studied K-Means. K-Means is Hard Clustering. Its mean one data point belongs to only one group. But in the real world, data is not always clear. A data point can have two groups at the same time. Gaussian Mixture Models (GMM) help us to solve this. GMM is Soft Clustering. It gives a probability for each group.

1. What is a Gaussian Distribution? 🔔

GMM assumes the data comes from many Gaussian Distributions. We also call it as normal distribution or bell curve. Each group (cluster) has its own shape. To define a Gaussian shape, we need two things. Mean (μ) and Covariance (Σ). The mean is the center of the curve and the covariance is the width and direction of the curve.

𝓝(x∣μ,Σ) = (1 / ((2π)⁽ᴰ/²⁾∣Σ∣⁽¹/²⁾))exp (−½(x − μ)ᵀΣ⁻¹(x − μ))

2. How GMM Works: The EM Algorithm 🔄

We dont know the center (μ) or the width (Σ) of the groups at the start. So we are using the Expectation-Maximization (EM) Algorithm. It works in a loop with two main steps.

Step 1: The E-Step (Expectation) 🧐
In this step, machine calculates the responsibility. It asks, "what is the chance that this data point belongs to group A, group B, or group C?" We are using this formula to find the chance (γ),

γ(zₙₖ) = ((πₖ𝓝(xₙ∣μₖ,Σₖ)) / (∑ⱼᴷ₌₁πⱼ𝓝(xₙ∣μⱼ,Σⱼ)))

Step 2: The M-Step (Maximization) 🛠

Now the machine uses the chances from the E-Step to update the groups. It changes the center and the width to fit the data better. It tries to make the Log-Likelihood (the total fit) as high as possible.

3. Why is GMM better than K-Means? 🤔🏆
● Soft Assignment - we can get a percentage for each group. This is more useful for complex data.
● Flexible Shapes - K-Means only finds circles but GMM can find ellipses (oval shapes) that point in any direction.
● Covariance Types - we can choose different settings for the shape like spherical, diagonal and full.


4. How to find the number of groups? (AIC and BIC) 📊

In K-Means, we are using the Elbow Method but in GMM, we are using AIC (Akaike Information Criterion) or BIC (Bayesian Information Criterion).
● These are scores that tell us if the model is good.
● If we add too many groups, the model becomes too complex (Overfitting).
● AIC and BIC give penalties for complexity.


Therefore, we are choosing the number of groups that gives the lowest BIC score.

Summary 📝

GMM is a powerful tool for finding groups using probability. It uses the EM Algorithm to find the best centers and shapes for the data. Unlike K-Means it is very flexible and works well when groups overlap or have different shapes. In Article 23, we will discuss Hierarchical Clustering (building a tree of data). 🌳⏭️ 🙊😁

✍️ @TheInfinityAI
2