[37] | 1 | function [U, stable] = whole_invert(V, W, INC, r) |
---|
| 2 | %V is the transformation matrix |
---|
| 3 | %W is the data matrix |
---|
| 4 | %INC is the incidence matrix of the same size as W. 1 denotes valid |
---|
| 5 | % data and 0 denotes missing data |
---|
| 6 | %r is the desired rank |
---|
| 7 | |
---|
| 8 | %to compute each row of U, this function removes the rows of V that |
---|
| 9 | %correspond to missing data, then pre-multiplies the corresponding data |
---|
| 10 | %elements from W by the pseudo-inverse of the new transformation |
---|
| 11 | %matrix. |
---|
| 12 | |
---|
| 13 | i = 1; |
---|
| 14 | n = size(W,1); |
---|
| 15 | W = W'; |
---|
| 16 | z = zeros(1,r); |
---|
| 17 | U = zeros(n, r); |
---|
| 18 | stable = 1; |
---|
| 19 | |
---|
| 20 | %for each row column of the original W |
---|
| 21 | while (i <= n) |
---|
| 22 | |
---|
| 23 | %remove the rows of V that correspond to missing data |
---|
| 24 | % sub_mat = V(INC(i,:),:); |
---|
| 25 | % The above line worked in Matlab IV. The line below replaces it in V. |
---|
| 26 | sub_mat = V(logical(INC(i,:)),:); |
---|
| 27 | |
---|
| 28 | %check that there is some valid data |
---|
| 29 | % if (size(sub_mat) > 0) |
---|
| 30 | if (rank(sub_mat) >= r) |
---|
| 31 | |
---|
| 32 | %choose the valid entries in W and find the entries of U |
---|
| 33 | %by pre-multiplying by the pseudo-inverse of V |
---|
| 34 | % t = sub_mat\(W(INC(i,:),i)); % MATLAB IV. |
---|
| 35 | t = sub_mat\(W(logical(INC(i,:)),i)); |
---|
| 36 | else |
---|
| 37 | t = z'; |
---|
| 38 | fprintf(1,'WARNING: Rank deficient in whole_invert.\n'); |
---|
| 39 | stable = 0; |
---|
| 40 | % keyboard |
---|
| 41 | end; |
---|
| 42 | |
---|
| 43 | U(i,:) = t'; |
---|
| 44 | i = i + 1; |
---|
| 45 | end; |
---|
| 46 | |
---|
| 47 | |
---|