use of weka.core.FastVector in project iobserve-analysis by research-iobserve.
the class ClusterMerger method execute.
/*
* (non-Javadoc)
*
* @see teetime.framework.AbstractConsumerStage#execute(java.lang.Object)
*/
@Override
protected void execute(final Map<Integer, List<Pair<Instance, Double>>> clustering) throws Exception {
/**
* simply pick the first instance of every cluster lookup attributes to build a new
* instances Object
*/
Instance instance = clustering.entrySet().iterator().next().getValue().get(0).getElement1();
final FastVector attributes = new FastVector();
for (int j = 0; j < instance.numAttributes(); j++) {
attributes.addElement(instance.attribute(j));
}
final Instances result = new Instances("Clustering Result", attributes, clustering.size());
for (final List<Pair<Instance, Double>> entry : clustering.values()) {
if (!entry.isEmpty()) {
instance = entry.get(0).getElement1();
result.add(instance);
}
}
this.printInstances(result);
this.outputPort.send(result);
}
use of weka.core.FastVector 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);
}
use of weka.core.FastVector in project iobserve-analysis by research-iobserve.
the class AbstractClustering method createInstances.
/**
* It transforms the user sessions(userSessions in form of counts of their called operation
* signatures) to Weka instances that can be used for the clustering.
*
* @param countModel
* contains the userSessions in form of counts of called operation signatures
* @param listOfDistinctOperationSignatures
* contains the extracted distinct operation signatures of the input
* entryCallSequenceModel
* @return the Weka instances that hold the data that is used for the clustering
*/
protected Instances createInstances(final List<UserSessionAsCountsOfCalls> countModel, final List<String> listOfDistinctOperationSignatures) {
final int numberOfDistinctOperationSignatures = listOfDistinctOperationSignatures.size();
final FastVector fvWekaAttributes = new FastVector(numberOfDistinctOperationSignatures);
for (int i = 0; i < numberOfDistinctOperationSignatures; i++) {
final String attributeName = "Attribute" + i;
final Attribute attribute = new Attribute(attributeName);
fvWekaAttributes.addElement(attribute);
}
final Instances clusterSet = new Instances("CallCounts", fvWekaAttributes, countModel.size());
for (final UserSessionAsCountsOfCalls userSession : countModel) {
int indexOfAttribute = 0;
final Instance instance = new Instance(numberOfDistinctOperationSignatures);
for (int row = 0; row < listOfDistinctOperationSignatures.size(); row++) {
instance.setValue((Attribute) fvWekaAttributes.elementAt(indexOfAttribute), userSession.getAbsoluteCountOfCalls()[row]);
indexOfAttribute++;
}
clusterSet.add(instance);
}
return clusterSet;
}
Aggregations