function [gain, pos_side, neg_side, theta] = SplitData(X, label, pos, neg, p, n)
    % X - Nx2 of points
    % label - labels for X
    % pos - index to positive sample
    % neg - index to negative sample
    % p - positive point
    % n - negative point

    total_entropy = Entropy(length(pos), length(neg));
        
     % find the parameters tangent to the line
    v = p - n;
    v /= norm(v);

    % go through all the points
    centre = (p+n)/2;
    bias = -v*centre';

    theta = [v bias];
    direction = [X ones(length(X),1)]*theta';

    % calculate information gain
    pos_side = find(direction >= 0);
    neg_side = find(direction < 0);
    
    % gain on the pos_side
    pos_count = length(find(label(pos_side) == 1));
    neg_count = length(find(label(pos_side) == 0));
    entropy_pos = Entropy(pos_count, neg_count);

    % gain on the pos_side
    pos_count = length(find(label(neg_side) == 1));
    neg_count = length(find(label(neg_side) == 0));
    entropy_neg = Entropy(pos_count, neg_count);

    pos_frac = length(pos_side)/length(X);
    neg_frac = length(neg_side)/length(X);

    gain = total_entropy - pos_frac*entropy_pos - neg_frac*entropy_neg;
