load joke.csv
Y = joke';
Y(abs(Y) > 10) = NaN;

% cofilter with knn

p = find(~isnan(Y));
i = randperm(length(p)); 
i = p(i(1:floor(length(p)*0.01)));
z = Y(i);
Y(i) = NaN;

K  = correlation(Y);
Y2 = cofilter(K,Y);

knn_err = mean(abs(z - Y2(i)));
fprintf('cofilter:         mean absolut error is %f\n', knn_err);

% baseline: mean imputation

n  = size(Y,2);
mu = zeros(n,1);
for j = 1:n
    mu(j) = mean(Y(~isnan(Y(:,j)),j));
end

mean_err = mean(abs(z - mu(floor((i-1)/100)+1)));
fprintf('mean imputation:  mean absolut error is %f\n', mean_err);
