Search in sources :

Example 1 with Attribute

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

the class TBehaviorModelCreation method createBehaviorModel.

/**
 * create a BehaviorModel from Instance.
 *
 * @param instances
 *            instances containing the attribute names
 * @param instance
 *            instance containing the attributes
 * @return behavior model if relevant
 */
private Optional<BehaviorModel> createBehaviorModel(final Instances instances, final Instance instance) {
    final int size = instance.numAttributes();
    final BehaviorModel behaviorModel = new BehaviorModel();
    for (int i = 0; i < size; i++) {
        final Attribute attribute = instances.attribute(i);
        final String attributeName = attribute.name();
        final Double attributeValue = instance.value(attribute);
        if (this.matchEdge(attributeName)) {
            final Optional<EntryCallEdge> edge = this.createEdge(attributeName, attributeValue);
            if (edge.isPresent()) {
                behaviorModel.addEdge(edge.get());
            }
        } else if (this.matchNode(attributeName)) {
            final Optional<EntryCallNode> node = this.createNode(attributeName, attributeValue);
            if (node.isPresent()) {
                behaviorModel.addNode(node.get());
            }
        }
    }
    if (behaviorModel.getEdges().isEmpty() && behaviorModel.getNodes().isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(behaviorModel);
}
Also used : EntryCallEdge(org.iobserve.analysis.clustering.filter.models.EntryCallEdge) Optional(java.util.Optional) Attribute(weka.core.Attribute) BehaviorModel(org.iobserve.analysis.clustering.filter.models.BehaviorModel)

Example 2 with Attribute

use of weka.core.Attribute 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 3 with Attribute

use of weka.core.Attribute 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)

Example 4 with Attribute

use of weka.core.Attribute 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) Instances(weka.core.Instances) Collection(java.util.Collection) 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) SingleOrNoneCollector(org.iobserve.analysis.behavior.SingleOrNoneCollector) CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) 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)

Example 5 with Attribute

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

the class BehaviorModelCreationStage method createBehaviorModel.

/**
 * create a BehaviorModel from Instance.
 *
 * @param instances
 *            instances containing the attribute names
 * @param instance
 *            instance containing the attributes
 * @return behavior model if relevant
 */
private Optional<BehaviorModel> createBehaviorModel(final Instances instances, final Instance instance) {
    final int size = instance.numAttributes();
    final BehaviorModel behaviorModel = new BehaviorModel();
    for (int i = 0; i < size; i++) {
        final Attribute attribute = instances.attribute(i);
        final String attributeName = attribute.name();
        final Double attributeValue = instance.value(attribute);
        if (this.matchEdge(attributeName)) {
            final Optional<EntryCallEdge> edge = this.createEdge(attributeName, attributeValue);
            if (edge.isPresent()) {
                behaviorModel.addEdge(edge.get(), true);
            }
        } else if (this.matchNode(attributeName)) {
            final Optional<EntryCallNode> node = this.createNode(attributeName, attributeValue);
            if (node.isPresent()) {
                behaviorModel.addNode(node.get(), true);
            }
        }
    }
    if (behaviorModel.getEdges().isEmpty() && behaviorModel.getNodes().isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(behaviorModel);
}
Also used : EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) Optional(java.util.Optional) Attribute(weka.core.Attribute) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Aggregations

Attribute (weka.core.Attribute)33 Instances (weka.core.Instances)16 ArrayList (java.util.ArrayList)15 Feature (org.dkpro.tc.api.features.Feature)8 Instance (org.dkpro.tc.api.features.Instance)8 Instance (weka.core.Instance)7 FastVector (weka.core.FastVector)6 DenseInstance (weka.core.DenseInstance)5 SparseInstance (weka.core.SparseInstance)5 HashMap (java.util.HashMap)4 Optional (java.util.Optional)4 Test (org.junit.Test)4 ArffSaver (weka.core.converters.ArffSaver)4 File (java.io.File)3 List (java.util.List)3 MultiLabelInstances (mulan.data.MultiLabelInstances)3 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)3 AttributeStore (org.dkpro.tc.ml.weka.util.AttributeStore)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2