function v = AI_remainder(examples,attributes,a_index)
%
% AI_remainder - compute info remaining after attribute
% Call:
%     v = AI_remainder(ex,atts,2);
% On input:
%     examples (mxn array): examples for training
%     attributes (structure array): attributes
%     a_index (scalar): attribute index for remainder
% On output:
%     v (scalar): info remainder on this attribute
% Custom functions used:
%     none
% Author:
%     T. Henderson, UU, 11/2002
% Method:
%      

n = AI_num_neg_examples(examples,0,0);
p = AI_num_pos_examples(examples,0,0);
t = p+n;
a_values = attributes(a_index).values;
sum = 0;

for val = 0:length(a_values)-1
   ni = AI_num_neg_examples(examples,a_index,val);
   pi = AI_num_pos_examples(examples,a_index,val);
   ti = pi+ni;
   if ti~=0
      info_content = AI_info_content(pi/ti,ni/ti);
      sum = sum + (ti/t)*info_content;
   end
end
v = sum;
