Search in sources :

Example 1 with CallInformation

use of org.iobserve.analysis.behavior.models.extended.CallInformation in project iobserve-analysis by research-iobserve.

the class JPetStoreParameterMetric method getNodeDistance.

private double getNodeDistance(final EntryCallNode nodeA, final EntryCallNode nodeB) {
    final CallInformation[] ciA = nodeA.getEntryCallInformation();
    final CallInformation[] ciB = nodeB.getEntryCallInformation();
    // Distance is none if both have no call info
    if (ciA.length == 0 && ciB.length == 0) {
        return 0;
    }
    int distance = 0;
    // Find out call info type (always homogenous for the same node type). Note that
    // one of these arrays has to contain at least one item due to previous
    // condition.
    final CallInformation sample = ciA.length > 0 ? ciA[0] : ciB[0];
    final boolean comparingItems = sample.getInformationSignature().equals("itemId");
    final boolean comparingProducts = sample.getInformationSignature().equals("productId");
    final boolean comparingCategories = sample.getInformationSignature().equals("categoryId");
    // Return if unknown information signature
    if (!(comparingItems || comparingProducts || comparingCategories)) {
        return 0;
    }
    // Match equal call info (all types)
    for (int a = 0; a < ciA.length; a++) {
        for (int b = 0; b < ciB.length; b++) {
            if (ciA[a].hasSameParameters(ciB[b])) {
                this.matchCounts(a, b, ciA, ciB);
                break;
            }
        }
    }
    // Match call info of same product (items only)
    if (comparingItems) {
        for (int a = 0; a < ciA.length; a++) {
            for (int b = 0; b < ciB.length; b++) {
                // Skip trying to match this if either have been matched completely
                if (ciA[a].getCount() == 0 || ciB[b].getCount() == 0) {
                    continue;
                }
                if (this.hasSameProduct(ciA[a], ciB[b])) {
                    this.matchCounts(a, b, ciA, ciB);
                    distance += 1;
                    break;
                }
            }
        }
    }
    // Match call info of same category (items and products only)
    if (comparingItems || comparingProducts) {
        for (int a = 0; a < ciA.length; a++) {
            for (int b = 0; b < ciB.length; b++) {
                // Skip trying to match this if either have been matched completely
                if (ciA[a].getCount() == 0 || ciB[b].getCount() == 0) {
                    continue;
                }
                if (this.hasSameCategory(ciA[a], ciB[b])) {
                    this.matchCounts(a, b, ciA, ciB);
                    // Add distance of 1 when comparing products, distance of 2 for items
                    distance += comparingItems ? 2 : 1;
                    break;
                }
            }
        }
    }
    // Find remaining non-matched call infos and match them, adding 1, 2 or 3
    // distance for
    // each match when comparing categories, products or items respectively, and 4
    // distance for any remaining call infos in either node when
    // the other one is empty
    final int distanceFactor = 3 - (comparingProducts ? 1 : 0) - (comparingCategories ? 2 : 0);
    int remainingA = 0;
    int remainingB = 0;
    for (final CallInformation c : ciA) {
        remainingA += c.getCount();
    }
    for (final CallInformation c : ciB) {
        remainingB += c.getCount();
    }
    final int remainingDiff = Math.abs(remainingA - remainingB);
    // Distance for every matchable element
    distance += Math.min(remainingA, remainingB) * distanceFactor;
    // Distance for every unmatchable element
    distance += remainingDiff * 4;
    return distance;
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation)

Example 2 with CallInformation

use of org.iobserve.analysis.behavior.models.extended.CallInformation in project iobserve-analysis by research-iobserve.

the class DynamicBehaviorModelTable method addInformation.

@Override
public void addInformation(final PayloadAwareEntryCallEvent event) {
    final String eventSignature = this.getSignatureFromEvent(event);
    final List<CallInformation> newCallInformations = new ArrayList<>();
    try {
        for (int i = 0; i < event.getParameters().length; i++) {
            final String value = String.valueOf(this.parameterValueDoubleMapper.mapValue(event.getParameters()[i], event.getValues()[i]));
            newCallInformations.add(new CallInformation(event.getParameters()[i], value));
        }
        // adding if no transition added yet
        if (!this.signatures.containsKey(eventSignature)) {
            this.addSignature(eventSignature);
        }
        final List<AggregatedCallInformation> aggCallInformations = this.signatures.get(eventSignature).getSecond();
        for (final CallInformation newCallInformation : newCallInformations) {
            // add new CallInfromation to the aggregation correctly
            final Optional<AggregatedCallInformation> match = aggCallInformations.stream().filter(aggCallInformation -> aggCallInformation.belongsTo(newCallInformation)).collect(new SingleOrNoneCollector<AggregatedCallInformation>());
            if (match.isPresent()) {
                match.get().addCallInformation(newCallInformation);
            } else {
                // add new Callinformation
                final AggregatedCallInformation newAggregatedCallInformation = new AggregatedCallInformation(this.strategy, newCallInformation);
                aggCallInformations.add(newAggregatedCallInformation);
            }
        }
    } catch (final IllegalArgumentException e) {
        DynamicBehaviorModelTable.LOGGER.error("Exception while adding information to behavior table", e);
    }
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Pair(org.apache.commons.math3.util.Pair) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayList(java.util.ArrayList) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) IRepresentativeStrategy(org.iobserve.analysis.behavior.models.data.configuration.IRepresentativeStrategy) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) 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) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList)

Example 3 with CallInformation

use of org.iobserve.analysis.behavior.models.extended.CallInformation 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 CallInformation

use of org.iobserve.analysis.behavior.models.extended.CallInformation in project iobserve-analysis by research-iobserve.

the class BehaviorModelCreationStage method createNode.

/**
 * Creates an node from a node representing attribute string and value.
 *
 * @param name
 *            attribute name
 * @param value
 *            attribute value
 *
 * @return EntryCallNode
 */
private Optional<EntryCallNode> createNode(final String name, final Double value) {
    final String[] signatures = this.splitSignature(AbstractBehaviorModelTable.INFORMATION_INDICATOR_PATTERN, AbstractBehaviorModelTable.INFORMATION_DIVIDER_PATTERN, name);
    if (signatures.length == 2) {
        final EntryCallNode node = new EntryCallNode(signatures[0]);
        final CallInformation callInformation = new CallInformation(signatures[1], value.toString());
        node.mergeCallInformation(callInformation);
        return Optional.of(node);
    } else {
        return Optional.empty();
    }
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode)

Example 5 with CallInformation

use of org.iobserve.analysis.behavior.models.extended.CallInformation in project iobserve-analysis by research-iobserve.

the class IntersectionModelGenerationStrategy method intersectNode.

private EntryCallNode intersectNode(final EntryCallNode a, final EntryCallNode b) {
    final EntryCallNode result = new EntryCallNode();
    result.setSignature(a.getSignature());
    Optional<CallInformation> matchingInfo;
    for (final CallInformation infoA : a.getEntryCallInformation()) {
        matchingInfo = b.findCallInformation(infoA.getInformationSignature(), infoA.getInformationParameter());
        if (matchingInfo.isPresent()) {
            final int newCalls = Math.min(infoA.getCount(), matchingInfo.get().getCount());
            final CallInformation newInfo = new CallInformation(infoA.getInformationSignature(), infoA.getInformationParameter(), newCalls);
            result.mergeCallInformation(newInfo);
        }
    }
    return result;
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode)

Aggregations

CallInformation (org.iobserve.analysis.behavior.models.extended.CallInformation)18 EntryCallNode (org.iobserve.analysis.behavior.models.extended.EntryCallNode)9 ArrayList (java.util.ArrayList)4 EntryCallEdge (org.iobserve.analysis.behavior.models.extended.EntryCallEdge)4 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Pair (org.apache.commons.math3.util.Pair)3 SingleOrNoneCollector (org.iobserve.analysis.behavior.SingleOrNoneCollector)3 NodeDifference (org.iobserve.evaluation.data.NodeDifference)3 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)3 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2