[Python] U-V Decomposition using Swarm Optimization
Note: This post was originally published on AH’s Blog (WordPress) on May 7, 2016, and has been migrated here.
An implementation of U-V Matrix Decomposition for Recommendation Systems, optimized using Particle Swarm Optimization (PSO).
Problem Setup
U-V Decomposition is a matrix optimization technique. Here the matrix represents user ratings for movies — a classic collaborative filtering scenario.

The matrix has 5 users and 5 movies. Each row is a user’s ratings. Missing values indicate unrated movies — these are the values we want to predict.
Algorithm Summary
Input: A 5×5 matrix M with missing entries.
Intermediate Output: Factor matrices U and V such that U × V approximates M (without missing values).
Output: A complete 5×5 matrix with predicted values for all missing entries.
PSO is used to find the optimal U and V matrices by minimizing the reconstruction error over the known entries.
Source code: GitHub — CS624-ML / U-V Decomposition
(A detailed code walkthrough post is planned as a follow-up.)
References
- Leskovec, Rajaraman, Ullman — Mining of Massive Datasets, Chapter 9 (direct link)
