Search in sources :

Example 1 with BehaviorModelGED

use of org.iobserve.service.behavior.analysis.model.BehaviorModelGED in project iobserve-analysis by research-iobserve.

the class BehaviorModelDeserialization method deserialize.

public BehaviorModelGED deserialize() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode tree = mapper.readTree(this.input);
    if (!(tree instanceof ObjectNode)) {
        throw new IOException("Wrong format");
    }
    final ObjectNode jsonModel = (ObjectNode) tree;
    final BehaviorModelGED model = new BehaviorModelGED();
    // Read nodes
    final JsonNode jsonNode = jsonModel.get("nodes");
    final Iterator<String> nodeIterator = jsonNode.fieldNames();
    while (nodeIterator.hasNext()) {
        final String operationSignature = nodeIterator.next();
        model.getNodes().put(operationSignature, new BehaviorModelNode(operationSignature));
    }
    // Read edges
    final JsonNode jsonEdges = jsonModel.get("edges");
    final Iterator<JsonNode> edgeIterator = jsonEdges.elements();
    while (edgeIterator.hasNext()) {
        final JsonNode jsonEdge = edgeIterator.next();
        final String source = jsonEdge.get("source").get("name").asText();
        final String target = jsonEdge.get("target").get("name").asText();
        final BehaviorModelNode sourceMatch = model.getNodes().get(source);
        final BehaviorModelNode targetMatch = model.getNodes().get(target);
        final BehaviorModelEdge newEdge = new BehaviorModelEdge(sourceMatch, targetMatch);
        model.getEdges().add(newEdge);
        sourceMatch.getOutgoingEdges().put(targetMatch, newEdge);
        targetMatch.getIngoingEdges().put(sourceMatch, newEdge);
        // Read event groups
        final JsonNode jsonEventGroups = jsonEdge.get("eventGroups");
        final Iterator<JsonNode> eventGroupIterator = jsonEventGroups.elements();
        while (eventGroupIterator.hasNext()) {
            final JsonNode jsonEventGroup = eventGroupIterator.next();
            final Iterator<JsonNode> eventIterator = jsonEventGroup.get("events").elements();
            final List<PayloadAwareEntryCallEvent> events = new ArrayList<>();
            while (eventIterator.hasNext()) {
                final JsonNode jsonEvent = eventIterator.next();
                final String operationSignature = jsonEvent.get("operationSignature").asText();
                final String[] parameters = mapper.treeToValue(jsonEvent.get("parameters"), String[].class);
                final String[] values = mapper.treeToValue(jsonEvent.get("values"), String[].class);
                final PayloadAwareEntryCallEvent event = new PayloadAwareEntryCallEvent(0, 0, operationSignature, operationSignature, "", "", parameters, values, 0);
                events.add(event);
            }
            final EventGroup group = new EventGroup(events.get(0).getParameters());
            group.getEvents().addAll(events);
            newEdge.getEventGroups().add(group);
        }
    }
    return model;
}
Also used : BehaviorModelNode(org.iobserve.service.behavior.analysis.model.BehaviorModelNode) BehaviorModelEdge(org.iobserve.service.behavior.analysis.model.BehaviorModelEdge) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) EventGroup(org.iobserve.service.behavior.analysis.model.EventGroup) BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with BehaviorModelGED

use of org.iobserve.service.behavior.analysis.model.BehaviorModelGED in project iobserve-analysis by research-iobserve.

the class GraphEditDistanceTest method symmetryTest.

@Test
public void symmetryTest() {
    BehaviorModelGED model1 = TestHelper.createBehaviorModelA();
    BehaviorModelGED model2 = TestHelper.createBehaviorModelB();
    double result1 = this.ged.calculate(model1, model2);
    double result2 = this.ged.calculate(model2, model1);
    Assert.assertEquals(result1, result2);
    model1 = TestHelper.createBehaviorModelA();
    model2 = TestHelper.createBehaviorModelC();
    result1 = this.ged.calculate(model1, model2);
    result2 = this.ged.calculate(model2, model1);
    Assert.assertEquals(result1, result2);
    model1 = TestHelper.createBehaviorModelA();
    model2 = TestHelper.createBehaviorModelD();
    result1 = this.ged.calculate(model1, model2);
    result2 = this.ged.calculate(model2, model1);
    Assert.assertEquals(result1, result2);
    model1 = TestHelper.createBehaviorModelA();
    model2 = TestHelper.createBehaviorModelE();
    result1 = this.ged.calculate(model1, model2);
    result2 = this.ged.calculate(model2, model1);
    Assert.assertEquals(result1, result2);
}
Also used : BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED) Test(org.junit.Test)

Example 3 with BehaviorModelGED

use of org.iobserve.service.behavior.analysis.model.BehaviorModelGED in project iobserve-analysis by research-iobserve.

the class GraphEditDistanceTest method parameterRelevantTest.

@Test
public void parameterRelevantTest() {
    final BehaviorModelGED model1 = TestHelper.createBehaviorModelA();
    final BehaviorModelGED model2 = TestHelper.createBehaviorModelC();
    Assert.assertTrue(this.ged.calculate(model1, model2) > 0);
}
Also used : BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED) Test(org.junit.Test)

Example 4 with BehaviorModelGED

use of org.iobserve.service.behavior.analysis.model.BehaviorModelGED in project iobserve-analysis by research-iobserve.

the class GraphEditDistanceTest method valueRelevantTest.

@Test
public void valueRelevantTest() {
    final BehaviorModelGED model1 = TestHelper.createBehaviorModelA();
    final BehaviorModelGED model2 = TestHelper.createBehaviorModelB();
    Assert.assertTrue(this.ged.calculate(model1, model2) > 0);
}
Also used : BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED) Test(org.junit.Test)

Example 5 with BehaviorModelGED

use of org.iobserve.service.behavior.analysis.model.BehaviorModelGED in project iobserve-analysis by research-iobserve.

the class NaiveMediodGenerator method execute.

@Override
protected void execute(final Clustering<BehaviorModelGED> clustering) throws Exception {
    for (final Set<BehaviorModelGED> clusterSet : clustering.getClusters()) {
        final BehaviorModelGED[] cluster = clusterSet.toArray(new BehaviorModelGED[clusterSet.size()]);
        if (cluster.length == 0) {
            NaiveMediodGenerator.LOGGER.warn("Empty cluster received");
            return;
        }
        BehaviorModelGED medoid = cluster[0];
        double minDistanceSum = Double.MAX_VALUE;
        for (int i = 0; i < cluster.length; i++) {
            double distanceSum = 0;
            // calculate the distance to the other objects
            for (int j = 0; j < cluster.length; j++) {
                if (i != j) {
                    distanceSum += this.dm.calculate(cluster[i], cluster[j]);
                }
            }
            // remember this object, if best medoid so far
            if (distanceSum < minDistanceSum) {
                minDistanceSum = distanceSum;
                medoid = cluster[i];
            }
        }
        this.outputPort.send(medoid);
    }
    NaiveMediodGenerator.LOGGER.info("mediod generated");
}
Also used : BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED)

Aggregations

BehaviorModelGED (org.iobserve.service.behavior.analysis.model.BehaviorModelGED)17 BehaviorModelEdge (org.iobserve.service.behavior.analysis.model.BehaviorModelEdge)7 Test (org.junit.Test)7 BehaviorModelNode (org.iobserve.service.behavior.analysis.model.BehaviorModelNode)3 ArrayList (java.util.ArrayList)2 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 OpticsData (org.iobserve.service.behavior.analysis.clustering.OpticsData)1 EventGroup (org.iobserve.service.behavior.analysis.model.EventGroup)1 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)1 Before (org.junit.Before)1