function T = prune_points(T,A,B,min_points,node_class,position)
% PRUNE_POINTS prunes the decision tree T by determining if the number of
%	misclassified points at a node is below a minimum (min_points).
%
%	T = prune_points(T,A,B,min_points,node_class,position)
%
%	T: matrix representing the decision tree T, generated by MSM-T.
%	A: matrix representing the points set A
%	B: matrix representing the points set B
%	min_points: the miminum allowable number of misclassified points
%		in a node
%	node_class: flag telling whether the current node is correctly
%		classifying set A or set B.
%		If current node is a left child: correctly classifying A.
%		If current node is a right child: correclty classifying B.
%		node_class = 0: correctly classifying A
%		node_class = 1: correctly classifying B
%	position: vector representing the order in which we are recursing
%		thru tree T.

% n is the dimension of the points in sets A,B.
global n;
n = size(A,2);

% generate Tb
Tb = [];
Tb = msmt_tree_breakdown(Tb,T,A,B,1);

% the current node is the last element in the position vector:
cur_index = size(position,2);
cur_position = position(cur_index);

% if cur_position is not a leaf node, then we check to see if it needs to be
% pruned:

if (cur_position ~= -1) 

	% determine which set we are trying to correctly classify
	% here:

	if (node_class == 0) % we are correctly classifying A
			     % points of B are misclassified
		
		if (Tb(2,cur_position) < min_points) % then kill the kids

			T = prune_kill_kids(T,position);
			return
		end

	else	% we are correctly classifying B
		% points of A are misclassified

		
		if (Tb(1,cur_position) < min_points) % then kill the kids
		
			T = prune_kill_kids(T,position);
			return
		end

	end

	% prune to the left and then to the right:

	T = prune_points(T,A,B,min_points,0,[position, T(n+2,cur_position)]);
	T = prune_points(T,A,B,min_points,1,[position, T(n+3,cur_position)]);

end
			
return


