Search in sources :

Example 1 with Instance

use of weka.core.Instance in project iobserve-analysis by research-iobserve.

the class ExpectationMaximizationClustering method clusterInstances.

/*
     * (non-Javadoc)
     *
     * @see
     * org.iobserve.analysis.cdoruserbehavior.clustering.IClustering#clusterInstances(weka.core.
     * Instances)
     */
@Override
public Map<Integer, List<Pair<Instance, Double>>> clusterInstances(final Instances instances) {
    final EM emClustering = new EM();
    if (ExpectationMaximizationClustering.LOGGER.isInfoEnabled()) {
        ExpectationMaximizationClustering.LOGGER.info("Computing the EM-Clustering with following options: " + emClustering.getOptions());
    }
    // NOPMD
    final Map<Integer, List<Pair<Instance, Double>>> resultMap = new HashMap<>();
    try {
        emClustering.buildClusterer(instances);
        /**
         * iterate through all instances and bucket sort them with their probabilities to their
         * assigned cluster.
         */
        for (int i = 0; i < instances.numInstances(); i++) {
            final Instance currentInstance = instances.instance(i);
            final int cluster = emClustering.clusterInstance(currentInstance);
            final double probability = emClustering.distributionForInstance(currentInstance)[cluster];
            if (resultMap.get(cluster) == null) {
                resultMap.put(cluster, new LinkedList<Pair<Instance, Double>>());
            }
            resultMap.get(cluster).add(new Pair<>(currentInstance, probability));
        }
    } catch (final Exception e) {
        // NOPMD NOCS api induced
        ExpectationMaximizationClustering.LOGGER.error("Clustering failed.", e);
    }
    return resultMap;
}
Also used : Instance(weka.core.Instance) HashMap(java.util.HashMap) EM(weka.clusterers.EM) List(java.util.List) LinkedList(java.util.LinkedList) Pair(org.eclipse.net4j.util.collection.Pair)

Example 2 with Instance

use of weka.core.Instance in project iobserve-analysis by research-iobserve.

the class ClusterMerger method printInstances.

private void printInstances(final Instances instances) {
    for (int i = 0; i < instances.numInstances(); i++) {
        String logString = "";
        logString += "***************************";
        logString += "Cluster " + i;
        logString += "***************************";
        final Instance instance = instances.instance(i);
        for (int a = 0; a < instance.numAttributes(); a++) {
            logString += instances.attribute(a).name() + " : " + instance.value(a);
        }
        ClusterMerger.LOGGER.info(logString);
    }
}
Also used : Instance(weka.core.Instance)

Example 3 with Instance

use of weka.core.Instance in project iobserve-analysis by research-iobserve.

the class TBehaviorModelCreation method execute.

@Override
protected void execute(final Instances instances) {
    final int size = instances.numInstances();
    for (int i = 0; i < size; i++) {
        final Instance instance = instances.instance(i);
        final Optional<BehaviorModel> behaviorModel = this.createBehaviorModel(instances, instance);
        final String modelName = this.namePrefix + i;
        behaviorModel.ifPresent(model -> model.setName(modelName));
        behaviorModel.ifPresent(this.outputPort::send);
    }
}
Also used : Instance(weka.core.Instance) BehaviorModel(org.iobserve.analysis.clustering.filter.models.BehaviorModel)

Example 4 with Instance

use of weka.core.Instance 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;
}
Also used : Instances(weka.core.Instances) FastVector(weka.core.FastVector) UserSessionAsCountsOfCalls(org.iobserve.analysis.userbehavior.data.UserSessionAsCountsOfCalls) Attribute(weka.core.Attribute) Instance(weka.core.Instance)

Example 5 with Instance

use of weka.core.Instance in project iobserve-analysis by research-iobserve.

the class BehaviorModelTable method toInstances.

/**
 * create an Instances object for clustering.
 *
 * @return instance
 */
public Instances toInstances() {
    final FastVector fastVector = new FastVector();
    // add transitions
    for (int i = 0; i < this.signatures.size(); i++) {
        for (int j = 0; j < this.signatures.size(); j++) {
            if (this.transitions[i][j] > AbstractBehaviorModelTable.TRANSITION_THRESHOLD) {
                final Attribute attribute = new Attribute(AbstractBehaviorModelTable.EDGE_INDICATOR + this.inverseSignatures[i] + AbstractBehaviorModelTable.EDGE_DIVIDER + this.inverseSignatures[j]);
                fastVector.addElement(attribute);
            } else {
                continue;
            }
        }
    }
    // add informations
    this.signatures.values().stream().forEach(pair -> Arrays.stream(pair.getSecond()).forEach(callInformation -> fastVector.addElement(new Attribute(AbstractBehaviorModelTable.INFORMATION_INDICATOR + this.inverseSignatures[pair.getFirst()] + AbstractBehaviorModelTable.INFORMATION_DIVIDER + callInformation.getSignature()))));
    // TODO name
    final Instances instances = new Instances("Test", fastVector, 0);
    final Instance instance = this.toInstance();
    instances.add(instance);
    return instances;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) FastVector(weka.core.FastVector) Pair(org.apache.commons.math3.util.Pair) SingleOrNoneCollector(org.iobserve.analysis.clustering.SingleOrNoneCollector) Instances(weka.core.Instances) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) Instance(weka.core.Instance) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) Attribute(weka.core.Attribute) Instances(weka.core.Instances) FastVector(weka.core.FastVector) Attribute(weka.core.Attribute) Instance(weka.core.Instance)

Aggregations

Instance (weka.core.Instance)14 Instances (weka.core.Instances)6 Attribute (weka.core.Attribute)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 DenseInstance (weka.core.DenseInstance)4 FastVector (weka.core.FastVector)4 List (java.util.List)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Pair (org.apache.commons.math3.util.Pair)2 Pair (org.eclipse.net4j.util.collection.Pair)2 SingleOrNoneCollector (org.iobserve.analysis.clustering.SingleOrNoneCollector)2 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)2 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1