clear all;
close all;
num_samples=[100,100];
num_clusters=[3,4];
num_genes=100;
num_indicators=20;
ind_strength = (10)*num_genes;

[data,labels] = gmm(num_samples,num_clusters,num_genes,num_indicators,ind_strength);

n=8;
[inf_genes,vals] = get_max_fisher_genes(data,labels(:,1),n);

new_data = data(:,inf_genes);

figure;
hold on;
for i=1:size(new_data,1),
    if(labels(i)==1) plot3(new_data(i,1),new_data(i,2),new_data(i,3),'r+','MarkerSize',2);
    else plot3(new_data(i,1),new_data(i,2),new_data(i,3),'g+','MarkerSize',2);    
    end
end


[h1, mu1, sigmas1, P1] = em(num_clusters(1), new_data(1:num_samples(1),:));
[h2, mu2, sigmas2, P2] = em(num_clusters(2), new_data(num_samples(1)+1:size(data,1),:));

for i=1:size(mu1,1),
     plot3(mu1(i,1),mu1(i,2),mu1(i,3),'r+','MarkerSize',10);
end

for i=1:size(mu2,1),
     plot3(mu2(i,1),mu2(i,2),mu2(i,3),'g+','MarkerSize',10);
end

for i=1:size(h1,1),
    [v,ind]=max(h1(i,:));
    cluster_labels(i,1) = ind;
end

for i=1:size(h2,1),
    [v,ind]=max(h2(i,:));
    cluster_labels(i+num_samples(1),1) = ind;
end

index=1;
vals=[];
for i=1:num_samples(1),
      if(length(vals) == 0 | length(find(vals(:,2) == cluster_labels(i,1))) == 0) 
        vals = [vals; index, cluster_labels(i,1)];
        cluster_labels(i,1) = index;
        index=index+1;
      else
          [a,b]=find(vals(:,2) == cluster_labels(i,1));
          cluster_labels(i,1) = vals(a,1);
      end
end

index=1;
vals=[];
offset=num_samples(1);
for i=1:num_samples(2),
      if(length(vals) == 0 |  length(find(vals(:,2) == cluster_labels(i+offset,1))) == 0) 
        vals = [vals; index, cluster_labels(i+offset,1)];
        cluster_labels(i+offset,1) = index;
        index=index+1;
      else
          [a,b]=find(vals(:,2) == cluster_labels(i+offset,1));
          cluster_labels(i+offset,1) = vals(a,1);
      end
end


[sep_measure,peak_order,transformation,decision_threshold] = train_fisher(new_data,labels(:,1),length(inf_genes));
[sep_measure,peak_order,transformation,decision_threshold] = cw_fisher(new_data,[labels(:,1),cluster_labels(:,1)],length(inf_genes));
