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;
}
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);
}
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);
}
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);
}
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");
}
Aggregations