function [trn_data,tst_data] = load_filled_mean(parms, trn_orig, tst_orig)
%
% Fill missing values using the mean of each feature
%
% (C) Gal Chechik 2005
  
  % Init
  [parms,do_force]   = take_from_struct(parms,'do_force', 0);
  n_trn = size(trn_orig,1);
  
  % Try to load from file 
  if strcmp(parms.fill_mode(1:4),'mean')==0
    error('Inconsistent fill_mode = %s',parms.fill_mode);
  end    
  filename = set_filenames('fild',parms);
  vars = {'trn_data','tst_data'};
  [do_calc, trn_data, tst_data] = cond_load(filename, do_force, vars{1:end});
  if(do_calc<1)
    return
  end
  
  data = [trn_orig;tst_orig];
  mmm = mean_nonan(data);
  n = size(data,1);
  
  filled=data;
  for i=1:n
    inds = find(isnan(data(i,:)));
    filled(i,inds) = mmm(inds);
  end
    
  trn_data = filled(1:n_trn,:);
  tst_data = filled(n_trn+1:end,:);
    
  % Check if useful to sparsify
  sparse_ratio = nnz(filled) / numel(filled);
  if(sparse_ratio<0.7)
    trn_data = sparse(trn_data);
    tst_data = sparse(tst_data);    
  end
    
  % Save to disk
  fprintf('Save file "%s".\n',filename);
  save(filename,'trn_data','tst_data');
  
  return


