All Downloads are FREE. Search and download functionalities are using the official Maven repository.

es.ucm.fdi.gaia.jcolibri.extensions.visualization.CasesVisualization Maven / Gradle / Ivy

Go to download

jCOLIBRI is a java framework for the development of Case-Based Reasoning systems.

There is a newer version: 3.2
Show newest version
/**
 * CasesVisualization.java
 * jCOLIBRI2 framework. 
 * @author Juan A. Recio-Garc�a.
 * GAIA - Group for Artificial Intelligence Applications
 * http://gaia.fdi.ucm.es
 * 23/05/2007
 */
package es.ucm.fdi.gaia.jcolibri.extensions.visualization;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;

import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase;
import es.ucm.fdi.gaia.jcolibri.extensions.classification.ClassificationSolution;
import es.ucm.fdi.gaia.jcolibri.extensions.visualization.infovisual.CBGraph;
import es.ucm.fdi.gaia.jcolibri.extensions.visualization.infovisual.CaseBaseVis;
import es.ucm.fdi.gaia.jcolibri.extensions.visualization.infovisual.InfoVisual;
import es.ucm.fdi.gaia.jcolibri.method.retrieve.RetrievalResult;
import es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.NNConfig;
import es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.NNScoringMethod;
import es.ucm.fdi.gaia.jcolibri.util.ProgressController;

/**
 * Wrapper to the InfoVisual library develped by Josep Lluis Arcos (IIIA-CSIC) that visualizes cases.
 * @author Juan A. Recio-Garcia
 * @version 2.0
 */
public class CasesVisualization {

	/**
	 * Visualizes a collection of cases using a given NN similarity configuration.
	 */
	public static void visualize(Collection cases, NNConfig knnConfig)
	{
		CBGraph graph = new CBGraph();
		
		// First add all the nodes saving IDs in a table
		Hashtable case2id = new Hashtable();
		for(CBRCase c : cases)
		{
			ClassificationSolution sol = (ClassificationSolution)c.getSolution();
			int id = graph.addCase(c.getID().toString(), sol.getClassification().toString());
			case2id.put(c, id);
		}
		
		
		
		// Now calculate edges distances
		List copy = new ArrayList(cases);
		
		//Compute total cycles
		int total = cases.size() * (cases.size()-1) / 2;
		ProgressController.init(CasesVisualization.class, "Computing distances", total);

		for(CBRCase c : cases)
		{
			copy.remove(c);
			List result = NNScoringMethod.evaluateSimilarity(copy, c, knnConfig);
			int currentcaseId = case2id.get(c);
			for(RetrievalResult sim : result)
			{
				CBRCase otherCase = sim.get_case();
				int othercaseId = case2id.get(otherCase);
				float distance = (float)(1-sim.getEval());
				graph.addDistance(currentcaseId, othercaseId, distance);
				System.out.println("Distance: "+c.getID()+" <--> "+otherCase.getID()+": "+ distance);
				ProgressController.step(CasesVisualization.class);
			}
		}
		ProgressController.finish(CasesVisualization.class);
		
		// Finally, visualize the data
		new InfoVisual( new CaseBaseVis(graph), true, false);

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy