function [con_pairs, dis_pairs] = evaluate_rank_prediction(pred_rank, true_rank)
[n_row, n_col, n_lab] = size(pred_rank);
pred_rank = reshape(pred_rank, [(n_row * n_col) n_lab]);
true_rank = reshape(true_rank, [(n_row * n_col) n_lab]);

pair_inds = find(reshape(tril(ones(n_lab), -1), [1 n_lab^2]));

true_pairs = repmat(true_rank, [1 1 n_lab]);
true_pairs = bsxfun(@minus, true_pairs, permute(true_rank, [1 3 2]));
true_pairs = sign(reshape(true_pairs, [(n_row * n_col) n_lab^2]));
true_pairs = true_pairs(:, pair_inds);
valid_pair = true_pairs ~= 0;

pred_pairs = repmat(pred_rank, [1 1 n_lab]);
pred_pairs = bsxfun(@minus, pred_pairs, permute(pred_rank, [1 3 2]));
pred_pairs = sign(reshape(pred_pairs, [(n_row * n_col) n_lab^2]));
pred_pairs = pred_pairs(:, pair_inds);

con_pairs = sum((pred_pairs == true_pairs).*valid_pair);
dis_pairs = sum((pred_pairs ~= true_pairs).*valid_pair);
