Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
165 lines (116 sloc) 6.16 KB
A=[1 0 0 1 0 0 0 0 0;
1 0 1 0 0 0 0 0 0;
1 1 0 0 0 0 0 0 0;
0 1 1 0 1 0 0 0 0;
0 1 1 2 0 0 0 0 0;
0 1 0 0 1 0 0 0 0;
0 1 0 0 1 0 0 0 0;
0 0 1 1 0 0 0 0 0;
0 1 0 0 0 0 0 0 1;
0 0 0 0 0 1 1 1 0;
0 0 0 0 0 0 1 1 1;
0 0 0 0 0 0 0 1 1];
[U,S,V] = svd(A,'econ');
U =
-0.2214 -0.1132 0.2890 -0.4148 -0.1063 -0.3410 -0.5227 0.0605 0.4067
-0.1976 -0.0721 0.1350 -0.5522 0.2818 0.4959 0.0704 0.0099 0.1089
-0.2405 0.0432 -0.1644 -0.5950 -0.1068 -0.2550 0.3022 -0.0623 -0.4924
-0.4036 0.0571 -0.3378 0.0991 0.3317 0.3848 -0.0029 0.0004 -0.0123
-0.6445 -0.1673 0.3611 0.3335 -0.1590 -0.2065 0.1658 -0.0343 -0.2707
-0.2650 0.1072 -0.4260 0.0738 0.0803 -0.1697 -0.2829 0.0161 0.0539
-0.2650 0.1072 -0.4260 0.0738 0.0803 -0.1697 -0.2829 0.0161 0.0539
-0.3008 -0.1413 0.3303 0.1881 0.1148 0.2722 -0.0330 0.0190 0.1653
-0.2059 0.2736 -0.1776 -0.0324 -0.5372 0.0809 0.4669 0.0363 0.5794
-0.0127 0.4902 0.2311 0.0248 0.5942 -0.3921 0.2883 -0.2546 0.2254
-0.0361 0.6228 0.2231 0.0007 -0.0683 0.1149 -0.1596 0.6811 -0.2320
-0.0318 0.4505 0.1411 -0.0087 -0.3005 0.2773 -0.3395 -0.6784 -0.1825
S =
3.3409 0 0 0 0 0 0 0 0
0 2.5417 0 0 0 0 0 0 0
0 0 2.3539 0 0 0 0 0 0
0 0 0 1.6445 0 0 0 0 0
0 0 0 0 1.5048 0 0 0 0
0 0 0 0 0 1.3064 0 0 0
0 0 0 0 0 0 0.8459 0 0
0 0 0 0 0 0 0 0.5601 0
0 0 0 0 0 0 0 0 0.3637
V =
-0.1974 -0.0559 0.1103 -0.9498 0.0457 -0.0766 -0.1773 0.0144 0.0637
-0.6060 0.1656 -0.4973 -0.0286 -0.2063 -0.2565 0.4330 -0.0493 -0.2428
-0.4629 -0.1273 0.2076 0.0416 0.3783 0.7244 0.2369 -0.0088 -0.0241
-0.5421 -0.2318 0.5699 0.2677 -0.2056 -0.3689 -0.2648 0.0195 0.0842
-0.2795 0.1068 -0.5054 0.1500 0.3272 0.0348 -0.6723 0.0583 0.2624
-0.0038 0.1928 0.0982 0.0151 0.3948 -0.3002 0.3408 -0.4545 0.6198
-0.0146 0.4379 0.1930 0.0155 0.3495 -0.2122 0.1522 0.7615 -0.0180
-0.0241 0.6151 0.2529 0.0102 0.1498 0.0001 -0.2491 -0.4496 -0.5199
-0.0820 0.5299 0.0793 -0.0246 -0.6020 0.3622 -0.0380 0.0696 0.4535
>> A-U*S*V'
ans =
1.0e-014 *
0.0111 -0.0340 -0.0839 0.0888 0.0812 -0.0139 0.0161 0.0194 0.0444
-0.0888 -0.0461 0.0999 0.0040 -0.0092 0.0378 0.0186 0.0014 -0.0420
-0.1110 0.0555 -0.0103 -0.0253 0.0222 -0.0319 -0.0487 -0.0444 -0.0347
-0.0001 0.0666 0.0777 -0.0662 0.1332 0.0165 0.0486 0.0211 -0.0008
0.0627 -0.0444 0.0888 0.1332 -0.0333 0.0035 0.0006 0 0.0291
0.0100 0.1554 -0.0665 -0.0690 0.1998 -0.0498 -0.0338 0.0158 0.0075
0.0122 0.1443 -0.0718 -0.0637 0.1998 -0.0215 -0.0038 0.0220 0.0102
0.0532 -0.0765 0.0777 0.0888 -0.0468 0.0451 0.0369 0.0520 0.0291
-0.0359 0.0777 -0.0119 0.0121 -0.0347 0.0389 -0.0271 -0.0625 0.0666
0.0087 -0.0021 0.0771 -0.0529 0.0187 0 -0.0444 -0.1110 0.0153
0.0317 0.0080 0.0244 -0.0292 0.0711 -0.0049 0.0222 -0.0666 0
0.0317 0.0062 -0.0205 0.0223 0.0503 0.0180 -0.0481 -0.0444 0
>> U2=U(:,1:2)
U2 =
-0.2214 -0.1132
-0.1976 -0.0721
-0.2405 0.0432
-0.4036 0.0571
-0.6445 -0.1673
-0.2650 0.1072
-0.2650 0.1072
-0.3008 -0.1413
-0.2059 0.2736
-0.0127 0.4902
-0.0361 0.6228
-0.0318 0.4505
>> S2=S(1:2,1:2)
S2 =
3.3409 0
0 2.5417
>> V2=V(:,1:2)
V2 =
-0.1974 -0.0559
-0.6060 0.1656
-0.4629 -0.1273
-0.5421 -0.2318
-0.2795 0.1068
-0.0038 0.1928
-0.0146 0.4379
-0.0241 0.6151
-0.0820 0.5299
>> A2=U2*S2*V2'
A2 =
0.1621 0.4005 0.3790 0.4676 0.1760 -0.0527 -0.1151 -0.1591 -0.0918
0.1406 0.3698 0.3290 0.4004 0.1650 -0.0328 -0.0706 -0.0968 -0.0430
0.1524 0.5050 0.3579 0.4101 0.2362 0.0242 0.0598 0.0869 0.1240
0.2580 0.8411 0.6057 0.6974 0.3923 0.0331 0.0832 0.1218 0.1874
0.4488 1.2344 1.0509 1.2658 0.5563 -0.0738 -0.1547 -0.2096 -0.0489
0.1596 0.5817 0.3752 0.4169 0.2765 0.0559 0.1322 0.1889 0.2169
0.1596 0.5817 0.3752 0.4169 0.2765 0.0559 0.1322 0.1889 0.2169
0.2185 0.5496 0.5110 0.6281 0.2425 -0.0654 -0.1425 -0.1966 -0.1079
0.0969 0.5321 0.2299 0.2118 0.2665 0.1368 0.3146 0.4444 0.4250
-0.0613 0.2321 -0.1389 -0.2656 0.1449 0.2404 0.5461 0.7674 0.6637
-0.0647 0.3353 -0.1456 -0.3014 0.2028 0.3057 0.6949 0.9766 0.8487
-0.0431 0.2539 -0.0967 -0.2079 0.1519 0.2212 0.5029 0.7069 0.6155
>> dot(A(1,:),A(4,:))/norm(A(1,:))/norm(A(4,:)) % original cosine distance human-user
ans =
0
>> dot(A2(1,:),A2(4,:))/norm(A2(1,:))/norm(A2(4,:)) % new cosine distance human-user
ans =
0.8878
>> dot(A(1,:),A(12,:))/norm(A(1,:))/norm(A(12,:)) % original cosine distance human-minor
ans =
0
>> dot(A2(1,:),A2(12,:))/norm(A2(1,:))/norm(A2(12,:)) % new cosine distance human-minor
ans =
-0.2750