function [sep_measure,peak_order,transformation,decision_threshold] = train_fisher(data,label,num_peaks)

dimPC = 3;
number = size (data, 1);
dimgene = size(data, 2);
dimsel = dimgene;
dimPeak = num_peaks;

%normgene = mean(abs(data), 1);

%[temp, normorder] = sort(normgene);
%idgene = normorder(dimgene - dimsel + 1 : dimgene);
%newdata = data(:, idgene);

newdata = data;
id1 = (label == 1);
id2 = (label == 2);
data1 = newdata(id1, :);
data2 = newdata(id2, :);
stdcluster = (size(data1, 1) - 1) * std(data1, 0, 1).^2 + (size(data2, 1) - 1) * std(data2, 0, 1).^2;
distance = (mean(data1, 1) - mean(data2, 1)).^2;
fisher = distance ./ stdcluster;

[temp, Peakorder] = sort(fisher);
Peakorder(length(Peakorder):-1:1)
Peakdata1 = data1(:, Peakorder(dimsel - dimPeak + 1 : dimsel));
Peakdata2 = data2(:, Peakorder(dimsel - dimPeak + 1 : dimsel));
Sw = (cov(Peakdata1) + cov(Peakdata2)) / number;
Sb = (mean(Peakdata1, 1) - mean(Peakdata2, 1))' * (mean(Peakdata1, 1) - mean(Peakdata2, 1));
[V, D] = eig(Sb, Sw);
[temp, PCorder] = sort(abs(diag(D)));
PCdata1 = Peakdata1 * V(:, PCorder(dimPeak - dimPC + 1 : dimPeak));
PCdata2 = Peakdata2 * V(:, PCorder(dimPeak - dimPC + 1 : dimPeak));

IOdisplay(number, PCdata1, PCdata2, label);


class1_mean = sum(PCdata1(:,3))/size(PCdata1,1);
class2_mean = sum(PCdata2(:,3))/size(PCdata2,1);
class1_std = std(PCdata1(:,3));
class2_std = std(PCdata2(:,3));
decision_threshold.val = (class1_mean*class2_std+class2_mean*class1_std)/(class1_std+class2_std);
%decision_threshold.val = (class1_mean+class2_mean)*.5;
if(class1_mean > decision_threshold.val) decision_threshold.label =1;
else decision_threshold.label=2;
end

sep_measure = (mean(Peakdata1, 1) - mean(Peakdata2, 1)) * inv(Sw) * (mean(Peakdata1, 1) - mean(Peakdata2, 1))';
peak_order = Peakorder(dimsel - dimPeak + 1 : dimsel);
transformation = V(:, PCorder(dimPeak - dimPC + 1 : dimPeak));