package multinomad.tools.kmeans;

import multinomad.algorithms.EFCL;
import multinomad.config.Configuration;
import multinomad.config.LoadProperties;
import multinomad.individuals.DoubleIndividual;
import multinomad.individuals.Population;
import net.sf.javaml.clustering.KMeans;
import net.sf.javaml.core.Dataset;
import net.sf.javaml.core.DefaultDataset;
import net.sf.javaml.core.DenseInstance;
import net.sf.javaml.core.Instance;

public class SimpleKmeansJavaML {
	
	private KMeans kmeans;
	
	public SimpleKmeansJavaML(int k) {
		kmeans = new KMeans(k,100);
	}
	
	public Dataset [] clustering(Dataset data) {
		Dataset [] output = kmeans.cluster(data);

		return output;
	}
	
	public static void main(String[] args) {
		LoadProperties lp = new LoadProperties(args,null);
		Configuration.setConfiguration(lp);
		EFCL efcl = new EFCL();
		Thread t1 =new Thread(efcl);  
		t1.start();		
		try {
			t1.join();
		} catch (InterruptedException e) {}
		
		Population solutions = efcl.getFilteredPop();
		
		Dataset dataset = new DefaultDataset();
		for(DoubleIndividual ind : solutions) {
			Instance inst = new DenseInstance(ind.getChr().asdouble());
			dataset.add(inst);
		}
		
		KMeans kmean = new KMeans(6,100);
		
		Dataset[] clusters = kmean.cluster(dataset);
		
		for(int i=0;i<clusters.length;i++) {
			for (Instance inst : clusters[i]) {
				System.out.print("Cluster "+i+": ");
				for(Double attribute : inst) {
					System.out.print(attribute.doubleValue()+" ");
				}
				System.out.println();
			}
		}
		
		
		
	}
}
