function funcs = showDiscriminantFuncs(cv,bwInvert)
%%% funcs = showDiscriminantFuncs(cv,bwInvert)
%%% Currently only works for windows-based representation

if nargin < 2
  bwInvert = 0;
end

reps = showTestRep(cv);

[nTasks,nTrials] = size(cv.classes);
for ttrial = 1:nTrials
  w = cv.testResults{ttrial}{2}.weights;
  w = w - repmat(mean(w,2),1,nTasks);
  b = cv.testResults{ttrial}{2}.bias;
  funcs{ttrial} = reps{ttrial}' * w + ...
      repmat(b',size(reps{ttrial},2),1);
  if bwInvert
    f = funcs{ttrial};
    funcs{ttrial} = max(f(:)) - f;
  end
end

clf;
for ttrial = 1:nTrials
  subplot(nTrials,1,ttrial);
  imagesc(funcs{ttrial}');
  ylabel('Task Discriminant');
  n = size(funcs{ttrial},1);
  inc = n / nTasks;
  set(gca,'XTick',inc/2:inc:n);
  xlab = {};
  for i = 1:nTasks
    xlab = {xlab{:} ['Task ' num2str(i)]};
  end
  set(gca,'XTickLabel',xlab);
  %plot(funcs{ttrial});
  title(['Test Trial ' num2str(ttrial)]);
end
