% {R_u} is the set of unknown ratings
%
% V(P({R_u})) = max_{R_i \in {R_u}} <R_i>
%   where <R_i> = \sum_r P(R_i=r) r
%
%   Note that inferredRatings contains the model's expected
%     rating for each item, which equals <R_i>
%
% EVOI(Q(j)) = sum_{ratings r} V(P({R_u}|R_j = r)) * P(R_j=r)
%
%   This is the expected query value
%

function evoi = compVoi(heldOutIndices, knownRatings, heldOutPdf)

D = length(knownRatings);
queryValue = zeros(1,D);
for i = heldOutIndices
  curHeldOut = heldOutIndices(find(heldOutIndices~=i));
  for rate=1:5
    knownRatings(i) = rate;
    % inferredRatings = MCVQ_infer(knownRatings,numVQs,numCompsPerVQ,A,G,M,W);
    inferredRatings = 5 * rand(1,D);
    inferredHeldOut = zeros(1,D);
    for j=curHeldOut inferredHeldOut(j) = inferredRatings(j); end;
    % find value 
    newValue = max(inferredHeldOut);
    queryValue(i) = queryValue(i) + heldOutPdf(rate,i) * newValue;
    %fprintf('q %d rate %d: prob %.2f newValue %.2f : qval %.2f\n',...
    %         i,rate,heldOutPdf(rate,i),newValue,queryValue(i));
  end
end

evoi = queryValue;

