Skip to content

Instantly share code, notes, and snippets.

@danbri
Created March 10, 2011 09:22
Show Gist options
  • Save danbri/863808 to your computer and use it in GitHub Desktop.
Save danbri/863808 to your computer and use it in GitHub Desktop.
matlab svd tests
clf
hold on;
grid on;
# item labels
I = {
'Dr Who',
'Eastenders',
'Farmer Seeks Wife',
'Eurovision',
'Newsnight',
'Coronation Street',
'Top of the Pops',
'Big Brother'
}
L = { 'Acracia', 'Libby', 'Michele', 'MS-', 'Nevali','VickyB','Yod', 'Yvesr', 'Laroyo' } # who
# edit as an Items x People matrix (easier to add people)
A = [ 4 1 0 3 4 1 3 4 ; # Acracia
5 2 1 5 5 2 4 1 ; # Libby
4 1 1 4 3 1 3 3 ; # Michele
4 5 2 5 5 4 4 0 ; # MS-
5 2 1 3 3 1 2 0 ; # Nevali
5 2 0 3 3 2 2 4 ; # VickyB
1 0 1 1 1 0 1 0 ; # Yod
3 4 1 4 4 5 3 4 ; # YvesR
5 2 1 4 4 3 3 5 ; # Laroyo
]
A = A' # transpose -> people across the top ...
[U,S,V] = svd(A)
# series first
a = U
X = a(: , 1:1)
Y = a(: , 2:2)
echo on
for K = 1:size(I,1)
text(X(K),Y(K), I(K), 'FontWeight', 'bold' )
end
echo off
# users
a = V
P = a(: , 1:1)
Q = a(: , 2:2)
for K = 1:size(L,2)
text(P(K),Q(K), L(K), 'FontWeight', 'light' )
end
print("notubery2a.png","-dpng")
# Let's add an unseen user, embed him in the 2D space derrived from the others' ratings
# balthasar = [4 1 1 4 3 1 3 3] # like Michele
balthasar = [ 4 5 2 5 5 2 4 1 ] # like MS- and Libby, 50/50
# balthasar = [ 0 0 2 5 5 0 4 0 ] # like MS- and Libby, 50/50 with 4 missing
u2 = U(:,1:2)
eig2inv = inv ( S(:,1:2)(1:2,:) )
embed = balthasar * u2 * eig2inv
text(embed(1), embed(2), "Balthasar")
print("notubery2b.png","-dpng")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment