Search in sources :

Example 1 with FastVector

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;
}
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 2 with FastVector

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

use of weka.core.FastVector 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 4 with FastVector

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);
        }
    }
    if (ClusterMerger.LOGGER.isDebugEnabled()) {
        this.printInstances(result);
    }
    this.outputPort.send(result);
}
Also used : Instances(weka.core.Instances) FastVector(weka.core.FastVector) Instance(weka.core.Instance) Pair(org.eclipse.net4j.util.collection.Pair)

Example 5 with FastVector

use of weka.core.FastVector in project lobcder by skoulouzis.

the class LDClustering method initAttributes.

private void initAttributes() throws ParseException, Exception {
    int index = 0;
    Attribute uidAttribute = new Attribute("uid", index++);
    // Declare a nominal attribute along with its values
    FastVector verbVector = new FastVector(Request.Method.values().length);
    for (Request.Method m : Request.Method.values()) {
        verbVector.addElement(m.code);
    }
    Attribute verbAttribute = new Attribute("verb", verbVector, index++);
    Attribute checksumAttribute = new Attribute("checksum", (FastVector) null, index++);
    Attribute contentTypeAttribute = new Attribute("contentType", (FastVector) null, index++);
    Attribute createDateAttribute = new Attribute("createDate", "yyyy-MM-dd HH:mm:ss", index++);
    Attribute locationPreferenceAttribute = new Attribute("locationPreference", (FastVector) null, index++);
    Attribute descriptionAttribute = new Attribute("description", (FastVector) null, index++);
    Attribute validationDateAttribute = new Attribute("validationDate", "yyyy-MM-dd HH:mm:ss", index++);
    Attribute lengthAttribute = new Attribute("length", index++);
    Attribute modifiedDateAttribute = new Attribute("modifiedDate", "yyyy-MM-dd HH:mm:ss", index++);
    Attribute pathAttribute = new Attribute("name", (FastVector) null, index++);
    Attribute parentRefAttribute = new Attribute("parentRef", index++);
    Attribute statusAttribute = new Attribute("status", (FastVector) null, index++);
    FastVector typeVector = new FastVector(3);
    typeVector.addElement(nl.uva.cs.lobcder.util.Constants.LOGICAL_DATA);
    typeVector.addElement(nl.uva.cs.lobcder.util.Constants.LOGICAL_FILE);
    typeVector.addElement(nl.uva.cs.lobcder.util.Constants.LOGICAL_FOLDER);
    Attribute typeAttribute = new Attribute("type", typeVector, index++);
    // Declare the class attribute along with its values
    FastVector supervisedVector = new FastVector(2);
    supervisedVector.addElement("true");
    supervisedVector.addElement("false");
    Attribute supervisedAttribute = new Attribute("supervised", supervisedVector, index++);
    Attribute ownerAttribute = new Attribute("owner", (FastVector) null, index++);
    // Declare the feature vector
    metdataAttributes = new FastVector();
    // 0
    metdataAttributes.addElement(uidAttribute);
    // 1
    metdataAttributes.addElement(verbAttribute);
    // 2
    metdataAttributes.addElement(checksumAttribute);
    // 3
    metdataAttributes.addElement(contentTypeAttribute);
    // 4
    metdataAttributes.addElement(createDateAttribute);
    // 5
    metdataAttributes.addElement(locationPreferenceAttribute);
    // 6
    metdataAttributes.addElement(descriptionAttribute);
    // 7
    metdataAttributes.addElement(validationDateAttribute);
    // 8
    metdataAttributes.addElement(lengthAttribute);
    // 9
    metdataAttributes.addElement(modifiedDateAttribute);
    // 10
    metdataAttributes.addElement(pathAttribute);
    // 11
    metdataAttributes.addElement(parentRefAttribute);
    // 12
    metdataAttributes.addElement(statusAttribute);
    // 13
    metdataAttributes.addElement(typeAttribute);
    // 14
    metdataAttributes.addElement(supervisedAttribute);
    // 15
    metdataAttributes.addElement(ownerAttribute);
}
Also used : FastVector(weka.core.FastVector) Attribute(weka.core.Attribute) Method(io.milton.http.Request.Method) Request(io.milton.http.Request)

Aggregations

FastVector (weka.core.FastVector)8 Instance (weka.core.Instance)7 Instances (weka.core.Instances)7 Attribute (weka.core.Attribute)6 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Pair (org.eclipse.net4j.util.collection.Pair)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Pair (org.apache.commons.math3.util.Pair)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 Request (io.milton.http.Request)1 Method (io.milton.http.Request.Method)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1