function CellAnalysis(ximage, yimage, cmap, minv, maxv)
% compute linear predictors for different cell sizes, displays info
% about how the predictor does on training and test set

% ximage is the desired output
% yimage is the input
% cmap is a contour map for the cells
% minv and maxv are the bounds of the cell sizes to experiment

n = 1;
X = imageVectors(ximage,0);
Y1 = imageVectors(yimage,n,1);
%Ymax = max(Y1, [], 1);
%Ymin = min(Y1, [], 1);
%Ymed = median(Y1, 1);

%Y = [ones([1 length(X)]); imageVectors(yimage,n,1), Ymax, Ymin, Ymed];
Y = Y1;
size(Y)

for i=minv:maxv
   mask = imageVectors([cmap >= i], 0);
   r = [rand([1 length(mask)]) > 0.2];
   mask1 = r.*mask;
   [v, ind] = find(mask1);
   if(length(ind) > 20)
      Ypart = Y(:,ind);
      Xpart = X(ind);
      
      [M, err1] = optimalLinearPredictor(Xpart, Ypart);
      
      
      mask2 = (1-r).*mask;
      [v, ind] = find(mask2);
      Ypart = Y(:,ind);
      Xpart = X(ind);
      
      err2 = sum(sum(Xpart - M'*Ypart).^2)/length(ind);
      
      disp(sprintf('%d => cell size : %d pixels : err1 = %.3f err2(%d px) = %.3f ',...
         i, sum(sum(mask1)), err1, length(ind), err2));
      
      
   end
end


