Sunday, January 20, 2013

MSE of Non-Zero Elements in Matlab


Suppose you have a predicted matrix and a ground truth matrix. You want to find MSE (Mean Squared Error) of only non-zero elements in your prediction. Here is what you do:

[i j k]= find(truth);

f = (sparse(i,j,k)-sparse(i,j,predicted(find(truth)))).^2;

MSE=sum(f,2)./sum(f~=0,2);



The following counts (size of) the nonzero entries in each row of a matrix without loop:

c = sum(f~=0,2);


spconvert does the reverse of full command :)

No comments:

Post a Comment