%% 
irDat;
close all;
terms = { 'baby', 'Child', 'Guide', 'Health', 'Home', 'Infant', 'Proofing', ...
 'Safety', 'Toddler'} 
docs = { 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8' } 
%% Normalize columns 
[m, n] = size(A);
d =  sqrt(sum(A .* A,1)); 
d = 1 ./ d;
A = A  .* (ones(m,1)* d) ;

[U, S, V] = svd(A);

y = U(:, 1:2)'*A;
figure(1)
title('Projection of document space') 
plot(y(1,:), y(2,:),'bo','linewidth',3)
hold on
%%
for i=1:length(y)
    text(y(1,i)+0.05, y(2,i)+0.05*randn(1),docs(i),'fontsize',14)
end
axis([0, 1, -1 1]) 
pause 
%%%%

z = A * V(:, 1:2) ;
figure(2) 
title('Projection of term space') 
     plot(z(:,1), z(:,2),'rs','linewidth',3)
hold on
axis([0, 1, -1 1]) 

for i=1:length(z)
    text(z(i,1)+0.02, z(i,2)+0.05*randn(1),terms(i),'fontsize',14)
end

%%doc = [0 0 0 1 0 0 0 0];
%%dp = doc*V;
%% normalize; 
%%plot(dp(1), dp(2),'+r','linewidth', 3) 



