

function varargout = ThresholdGram(gram, delta) 
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % This is a simple function that threshold the gram matrix
  % 
  % INPUT:
  %   gram: the original gram matrix
  %   delta: the elementwise threshold
  % 
  % OUTPUT:
  %   gram: the gram matrix after thresholding
  %   gram.bias: the bias that the thresholding makes
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%
  [p,pp] = size(gram);
  if nargin == 1
    delta = 1/log(p);
  end
  %% Threshold the gram matrix
  gramBias = gram.*(abs(gram) < delta);
  gramSD = gram-gramBias;

  %% define the output with various length
 varargout = cell(nargout, 1);
if nargout == 1
  varargout = {gramSD};
elseif nargout == 2
   varargout = {gramSD, gramBias};
end
end