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