use of org.iobserve.analysis.behavior.clustering.hierarchical.CSVSinkFilter in project iobserve-analysis by research-iobserve.
the class JUnitTestsHierarchicalClustering method setupTestData.
/**
* Create test data sets and their expected clustering results.
*
* @throws IOException
* when failing to write a CSV file to CSVOUTPUTPATH
*/
@Before
public void setupTestData() throws IOException {
// Create Attribute names for the test data sets.
final FastVector attVector = new FastVector(1);
attVector.addElement(new Attribute("Attribute1"));
attVector.addElement(new Attribute("Attribute2"));
// Create a data set with two similar instances i1 and i2 with two attributes.
final Instance i1one = new Instance(1.0, new double[] { 1.0, 2.0 });
final Instance i2one = new Instance(1.0, new double[] { 1.5, 2.1 });
final Instances instancesOne = new Instances("Instances", attVector, 2);
instancesOne.add(i1one);
instancesOne.add(i2one);
i1one.setDataset(instancesOne);
i2one.setDataset(instancesOne);
this.setTestInstancesOneCluster(instancesOne);
// Create expected result.
final Map<Integer, List<Pair<Instance, Double>>> expResOne = new HashMap<>();
expResOne.put(0, new LinkedList<Pair<Instance, Double>>());
expResOne.get(0).add(new Pair<>(i1one, 1.0));
expResOne.get(0).add(new Pair<>(i2one, 1.0));
this.setExpectedResultsOneCluster(expResOne);
/*
* Create a data set with two similar instances i1 and i2 and one different instance i3 with
* two attributes.
*/
final Instance i1two = new Instance(1.0, new double[] { 1.0, 2.0 });
final Instance i2two = new Instance(1.0, new double[] { 1.5, 2.1 });
final Instance i3two = new Instance(1.0, new double[] { 1000.0, 1200.0 });
final Instances instancesTwo = new Instances("Instances", attVector, 3);
instancesTwo.add(i1two);
instancesTwo.add(i2two);
instancesTwo.add(i3two);
i1two.setDataset(instancesTwo);
i2two.setDataset(instancesTwo);
i3two.setDataset(instancesTwo);
this.setTestInstancesTwoClusters(instancesTwo);
// Create expected result.
final Map<Integer, List<Pair<Instance, Double>>> expResTwo = new HashMap<>();
expResTwo.put(0, new LinkedList<Pair<Instance, Double>>());
expResTwo.put(1, new LinkedList<Pair<Instance, Double>>());
expResTwo.get(0).add(new Pair<>(i1two, 1.0));
expResTwo.get(0).add(new Pair<>(i2two, 1.0));
expResTwo.get(1).add(new Pair<>(i3two, 1.0));
this.setExpectedResultsTwoCluster(expResTwo);
// Write a CSV file for a clustering result which expects two clusters.
final CSVSinkFilter csvFilter = new CSVSinkFilter();
final Map<Double, List<Instance>> clusteringKVs = csvFilter.convertClusteringResultsToKVPair(expResTwo);
csvFilter.createCSVFromClusteringResult(JUnitTestsHierarchicalClustering.CSVOUTPUTPATH, clusteringKVs);
}
Aggregations