Commit 1c483936 authored by Dinh-An Ho's avatar Dinh-An Ho
Browse files

Merge remote-tracking branch 'origin/ML_clustering' into ML_clustering

# Conflicts:
#	src/main/java/de/monticore/lang/monticar/generator/middleware/Simulation/MonteCarloIntegration.java
parents c3685b33 b165a3be
Pipeline #111097 passed with stages
in 15 minutes and 58 seconds
......@@ -105,7 +105,8 @@ Clustering Parameters:
| numberOfClusters | int | ❓ | Number of clusters the subcomponents should be divided into<br> Overrides numberOfClusters in algorithmParameters |
| flatten | bool | ❓ | Replace all components with their subcomponents execpt when it is atomic or the flatten level is reached |
| flattenLevel | int | ❓ | Maximal level of component flattening |
| chooseBy | String | ❓ | Strategie to choose from the resulting clusterings<br> bestWithFittingN(Default): if numberOfClusters is set, all results with a different number of clusters are ignored<br> bestOverall: ignore numberOfClusters, choose result with best score |
| metric | String | ❓ | Metric to evaluate the quality of the resulting clusters. Available: "CommunicationCost"(Default), "Silhouette"|
| chooseBy | String | ❓ | Strategy to choose from the resulting clusterings<br> bestWithFittingN(Default): if numberOfClusters is set, all results with a different number of clusters are ignored<br> bestOverall: ignore numberOfClusters, choose result with best score |
| algorithmParameters | List<Object> | ❓ | Used to specify which algorithms(and their parameters) are used for clustering |
There are 4 different Clustering Algorithms with distinct parameters
......
......@@ -108,7 +108,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
//Cluster
if(clusteringParameters.getAlgorithmParameters().size() > 0) {
clusteringResults = AutomaticClusteringHelper.executeClusteringFromParams(componentInstanceSymbol, clusteringParameters.getAlgorithmParameters());
clusteringResults = ClusteringResultList.fromParametersList(componentInstanceSymbol, clusteringParameters.getAlgorithmParameters(), clusteringParameters.getMetric());
Optional<Integer> nOpt = clusteringParameters.getNumberOfClusters();
for(ClusteringResult c : clusteringResults){
String prefix = nOpt.isPresent() && !c.hasNumberOfClusters(nOpt.get()) ? "[IGNORED]" : "";
......
......@@ -10,6 +10,7 @@ import java.io.FileReader;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CliParametersLoader {
......@@ -45,17 +46,19 @@ public class CliParametersLoader {
.create();
JsonDeserializer<DynamicSpectralClusteringCliParameters> desCliParameters = new StrictJsonDeserializer<>(Arrays.asList("modelsDir","outputDir","rootModel","generators","emadlBackend","writeTagFile","clusteringParameters"), delegateGson);
JsonDeserializer<ClusteringParameters> desClustering = new StrictJsonDeserializer<>(Arrays.asList("numberOfClusters","flatten","flattenLevel","chooseBy","algorithmParameters"), delegateGson);
JsonDeserializer<CliParameters> desCliParameters = new StrictJsonDeserializer<>(Arrays.asList("emadlBackend","writeTagFile","clusteringParameters","modelsDir","outputDir","rootModel","generators"), delegateGson);
JsonDeserializer<ClusteringParameters> desClustering = new StrictJsonDeserializer<>(Arrays.asList("numberOfClusters","flatten","flattenLevel","chooseBy","algorithmParameters", "metric"), delegateGson);
JsonDeserializer<DynamicSpectralClusteringCliParameters> desSpectral = new StrictJsonDeserializer<>(Arrays.asList("numberOfClusters","l","sigma"), delegateGson);
JsonDeserializer<DynamicSpectralClusteringCliParameters> desMarkov = new StrictJsonDeserializer<>(Arrays.asList("max_residual","gamma_exp","loop_gain","zero_max"), delegateGson);
JsonDeserializer<DynamicSpectralClusteringCliParameters> desDBScan = new StrictJsonDeserializer<>(Arrays.asList("min_pts","radius"), delegateGson);
JsonDeserializer<DynamicMarkovCliParameters> desMarkov = new StrictJsonDeserializer<>(Arrays.asList("max_residual","gamma_exp","loop_gain","zero_max"), delegateGson);
JsonDeserializer<DynamicDBScanCliParameters> desDBScan = new StrictJsonDeserializer<>(Arrays.asList("min_pts","radius"), delegateGson);
JsonDeserializer<DynamicAffinityPropagationCliParameters> desAff = new StrictJsonDeserializer<>(Collections.emptyList(), delegateGson);
Gson gson = new GsonBuilder()
.registerTypeAdapter(DynamicSpectralClusteringCliParameters.class, desSpectral)
.registerTypeAdapter(DynamicMarkovCliParameters.class, desMarkov)
.registerTypeAdapter(DynamicDBScanCliParameters.class, desDBScan)
.registerTypeAdapter(DynamicAffinityPropagationCliParameters.class, desAff)
.registerTypeAdapter(CliParameters.class, desCliParameters)
.registerTypeAdapter(ClusteringParameters.class, desClustering)
.create();
......
package de.monticore.lang.monticar.generator.middleware.cli;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.AlgorithmCliParameters;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.SpectralClusteringCliParameters;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.dynamic.DynamicAlgorithmCliParameters;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.dynamic.DynamicParameter;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.dynamic.DynamicSpectralClusteringCliParameters;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.dynamic.ListParameter;
import de.monticore.lang.monticar.generator.middleware.clustering.qualityMetric.Metric;
import de.monticore.lang.monticar.generator.middleware.clustering.qualityMetric.MetricType;
import java.util.ArrayList;
import java.util.List;
......@@ -18,6 +19,7 @@ public class ClusteringParameters {
private Integer flattenLevel;
private ResultChoosingStrategy chooseBy = ResultChoosingStrategy.bestWithFittingN;
private List<DynamicAlgorithmCliParameters> algorithmParameters = new ArrayList<>();
private MetricType metric;
public ClusteringParameters() {
}
......@@ -54,4 +56,12 @@ public class ClusteringParameters {
public Optional<Integer> getFlattenLevel() {
return Optional.ofNullable(flattenLevel);
}
public Metric getMetric() {
if(metric == null){
return MetricType.CommunicationCost.toMetric();
}else{
return metric.toMetric();
}
}
}
......@@ -2,6 +2,8 @@ package de.monticore.lang.monticar.generator.middleware.cli.algorithms;
import de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm;
import java.util.Optional;
public abstract class AlgorithmCliParameters {
public static final String TYPE_SPECTRAL_CLUSTERING = "SpectralClustering";
public static final String TYPE_UNKOWN = "Unkown";
......@@ -22,4 +24,8 @@ public abstract class AlgorithmCliParameters {
public abstract Object[] asAlgorithmArgs();
public abstract boolean isValid();
public Optional<Integer> expectedClusterCount(){
return Optional.empty();
}
}
......@@ -68,6 +68,11 @@ public class SpectralClusteringCliParameters extends AlgorithmCliParameters {
return numberOfClusters != null;
}
@Override
public Optional<Integer> expectedClusterCount() {
return Optional.of(getNumberOfClusters().get());
}
public Optional<Integer> getNumberOfClusters() {
return Optional.ofNullable(numberOfClusters);
}
......
......@@ -7,7 +7,6 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instance
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol;
import de.monticore.lang.math._ast.ASTNumberExpression;
import de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.AlgorithmCliParameters;
import de.monticore.lang.monticar.ts.MCTypeSymbol;
import de.monticore.lang.monticar.ts.references.MCASTTypeSymbolReference;
import de.monticore.lang.monticar.ts.references.MCTypeReference;
......@@ -25,7 +24,6 @@ import java.util.stream.Collectors;
public class AutomaticClusteringHelper {
// public static double[][] createAdjacencyMatrix(List<ExpandedComponentInstanceSymbol> subcomps, Collection<ConnectorSymbol> connectors, Map<String, Integer> subcompLabels) {
public static double[][] createAdjacencyMatrix(List<EMAComponentInstanceSymbol> subcomps, Collection<EMAConnectorInstanceSymbol> connectors, Map<String, Integer> subcompLabels) {
// Nodes = subcomponents
// Verts = connectors between subcomponents
......@@ -36,18 +34,18 @@ public class AutomaticClusteringHelper {
EMAComponentInstanceSymbol sourceCompOpt = con.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol targetCompOpt = con.getTargetPort().getComponentInstance();
int index1 = subcompLabels.get(sourceCompOpt.getFullName());
int index2 = subcompLabels.get(targetCompOpt.getFullName());
int index1 = subcompLabels.get(sourceCompOpt.getFullName());
int index2 = subcompLabels.get(targetCompOpt.getFullName());
res[index1][index2] += getTypeCostHeuristic(con.getSourcePort());
res[index2][index1] += getTypeCostHeuristic(con.getSourcePort());
res[index1][index2] += getTypeCostHeuristic(con.getSourcePort());
res[index2][index1] += getTypeCostHeuristic(con.getSourcePort());
});
return res;
}
public static double[][] guaranteedConnectedAdjacencyMatrix(List<EMAComponentInstanceSymbol> subcomps, Collection<EMAConnectorInstanceSymbol> connectors, Map<String, Integer> subcompLabels){
public static double[][] guaranteedConnectedAdjacencyMatrix(List<EMAComponentInstanceSymbol> subcomps, Collection<EMAConnectorInstanceSymbol> connectors, Map<String, Integer> subcompLabels) {
double[][] res = createAdjacencyMatrix(subcomps, connectors, subcompLabels);
......@@ -56,7 +54,7 @@ public class AutomaticClusteringHelper {
double max = 0;
for (double[] doubles : res) {
for (double adj : doubles) {
if(adj > max){
if (adj > max) {
max = adj;
}
}
......@@ -70,7 +68,7 @@ public class AutomaticClusteringHelper {
for (Integer a : representativeLabels) {
for (Integer b : representativeLabels) {
if(!a.equals(b)){
if (!a.equals(b)) {
res[a][b] = unconnectedCost;
}
}
......@@ -78,32 +76,60 @@ public class AutomaticClusteringHelper {
return res;
}
public static List<Set<EMAComponentInstanceSymbol>> getConnectedSubcomponentSets(List<EMAComponentInstanceSymbol> subcomps, Collection<EMAConnectorInstanceSymbol> connectors){
public static double[][] getDistanceMatrix(double[][] adjacencyMatrix) {
//Uses Floyd–Warshall
double[][] res = new double[adjacencyMatrix.length][adjacencyMatrix[0].length];
for (int i = 0; i < adjacencyMatrix.length; i++) {
for (int j = 0; j < adjacencyMatrix[0].length; j++) {
if (i != j) {
double curVal = adjacencyMatrix[i][j];
res[i][j] = Math.abs(curVal) <= 0.00000001d ? Double.MAX_VALUE : curVal;
} else {
res[i][i] = 0d;
}
}
}
for (int k = 0; k < adjacencyMatrix.length; k++) {
for (int i = 0; i < adjacencyMatrix.length; i++) {
for (int j = 0; j < adjacencyMatrix.length; j++) {
if (res[i][j] > res[i][k] + res[k][j]) {
res[i][j] = res[i][k] + res[k][j];
}
}
}
}
return res;
}
public static List<Set<EMAComponentInstanceSymbol>> getConnectedSubcomponentSets(List<EMAComponentInstanceSymbol> subcomps, Collection<EMAConnectorInstanceSymbol> connectors) {
Graph<EMAComponentInstanceSymbol, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
subcomps.forEach(graph::addVertex);
connectors.stream()
.filter(c -> subcomps.contains(c.getSourcePort().getComponentInstance()))
.filter(c -> subcomps.contains(c.getTargetPort().getComponentInstance()))
.forEach(c -> graph.addEdge(c.getSourcePort().getComponentInstance(), c.getTargetPort().getComponentInstance()));
.filter(c -> subcomps.contains(c.getSourcePort().getComponentInstance()))
.filter(c -> subcomps.contains(c.getTargetPort().getComponentInstance()))
.forEach(c -> graph.addEdge(c.getSourcePort().getComponentInstance(), c.getTargetPort().getComponentInstance()));
ConnectivityInspector<EMAComponentInstanceSymbol, DefaultEdge> connectivityInspector = new ConnectivityInspector<>(graph);
return connectivityInspector.connectedSets();
}
public static double[][] adjacencyMatrix2transitionMatrix(double[][] adjacencyMatrix) {
double[][] transitionMatrix= adjacencyMatrix;
double[][] transitionMatrix = adjacencyMatrix;
int degree;
for(int i = 0; i < adjacencyMatrix[0].length; i++) {
degree= 0;
for(int j = 0; j < adjacencyMatrix[0].length; j++) {
for (int i = 0; i < adjacencyMatrix[0].length; i++) {
degree = 0;
for (int j = 0; j < adjacencyMatrix[0].length; j++) {
if (adjacencyMatrix[i][j] == 1) degree++;
}
for(int j = 0; j < adjacencyMatrix[0].length; j++) {
if (adjacencyMatrix[i][j] == 1) transitionMatrix[i][j] = 1.0/degree;
for (int j = 0; j < adjacencyMatrix[0].length; j++) {
if (adjacencyMatrix[i][j] == 1) transitionMatrix[i][j] = 1.0 / degree;
}
}
......@@ -113,18 +139,18 @@ public class AutomaticClusteringHelper {
// generic matrix normalizer
public static double[][] normalizeMatrix(double[][] matrix) {
double[][] normalizedMatrix= matrix;
double[][] normalizedMatrix = matrix;
double normalizer;
double sum;
for(int i = 0; i < matrix[0].length; i++) {
normalizer= 0;
sum= 0;
for(int j = 0; j < matrix[0].length; j++) {
sum+= normalizedMatrix[i][j];
for (int i = 0; i < matrix[0].length; i++) {
normalizer = 0;
sum = 0;
for (int j = 0; j < matrix[0].length; j++) {
sum += normalizedMatrix[i][j];
}
if (sum>0) normalizer= 1.0/sum;
for(int j = 0; j < matrix[0].length; j++) {
if (sum > 0) normalizer = 1.0 / sum;
for (int j = 0; j < matrix[0].length; j++) {
normalizedMatrix[i][j] = matrix[i][j] * normalizer;
}
}
......@@ -135,11 +161,11 @@ public class AutomaticClusteringHelper {
// calculate the inverse probabilities of a transition matrix
// (regard zero as immutable zero probability)
public static double[][] inverseProbabilitiesMatrix(double[][] matrix) {
double[][] inverseProbabilityMatrix= matrix;
double[][] inverseProbabilityMatrix = matrix;
for(int i = 0; i < matrix[0].length; i++) {
for (int i = 0; i < matrix[0].length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
if (matrix[i][j] > 0) inverseProbabilityMatrix[i][j] = 1.0/matrix[i][j];
if (matrix[i][j] > 0) inverseProbabilityMatrix[i][j] = 1.0 / matrix[i][j];
}
}
......@@ -163,17 +189,17 @@ public class AutomaticClusteringHelper {
EMAComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance();
for(int i = 0; i < clusters.size(); i++){
if(clusters.get(i).contains(sourceComp)){
for (int i = 0; i < clusters.size(); i++) {
if (clusters.get(i).contains(sourceComp)) {
sourceClusterLabel = i;
}
if(clusters.get(i).contains(targetComp)){
if (clusters.get(i).contains(targetComp)) {
targetClusterLabel = i;
}
}
if(sourceClusterLabel != targetClusterLabel){
if (sourceClusterLabel != targetClusterLabel) {
con.getSourcePort().setMiddlewareSymbol(new RosConnectionSymbol());
con.getTargetPort().setMiddlewareSymbol(new RosConnectionSymbol());
}
......@@ -182,7 +208,7 @@ public class AutomaticClusteringHelper {
}
public static double getTypeCostHeuristic(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clustering){
public static double getTypeCostHeuristic(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clustering) {
List<EMAConnectorInstanceSymbol> interClusterConnectors = getInterClusterConnectors(componentInstanceSymbol, clustering);
return interClusterConnectors.stream()
......@@ -221,18 +247,18 @@ public class AutomaticClusteringHelper {
.collect(Collectors.toList());
}
public static double getTypeCostHeuristic(EMAPortSymbol port){
public static double getTypeCostHeuristic(EMAPortSymbol port) {
return getTypeCostHeuristic(port.getTypeReference());
}
public static double getTypeCostHeuristic(MCTypeReference<? extends MCTypeSymbol> typeReference) {
if (typeReference.getName().equals("CommonMatrixType")){
if (typeReference.getName().equals("CommonMatrixType")) {
double value = getTypeCostHeuristicHelper(
((ASTCommonMatrixType)((MCASTTypeSymbolReference)typeReference).getAstType()).getElementType().getName());
((ASTCommonMatrixType) ((MCASTTypeSymbolReference) typeReference).getAstType()).getElementType().getName());
double res = 0;
List<ASTExpression> vectors = ((ASTCommonMatrixType) ((MCASTTypeSymbolReference) typeReference).
getAstType()).getDimension().getDimensionList();
for (ASTExpression expression : vectors){
for (ASTExpression expression : vectors) {
if (((ASTNumberExpression) expression).getNumberWithUnit().getNumber().isPresent()) {
res += value * ((ASTNumberExpression) expression).getNumberWithUnit().getNumber().get();
}
......@@ -244,10 +270,11 @@ public class AutomaticClusteringHelper {
}
private static double getTypeCostHeuristicHelper(String name) {
// use cost in bytes as used by ROS(http://wiki.ros.org/msg#Field_Types)
double bool = 1;
double z = 5;
double q = 10;
double c = 20;
double z = 4;
double q = 8;
double c = 16;
switch (name) {
case "B":
return bool;
......@@ -262,13 +289,4 @@ public class AutomaticClusteringHelper {
}
public static ClusteringResultList executeClusteringFromParams(EMAComponentInstanceSymbol emaComponentInstance, List<AlgorithmCliParameters> algoParams) {
ClusteringResultList res = new ClusteringResultList();
for (int i = 0; i < algoParams.size(); i++) {
System.out.println("Clustering with algorithm " + (i+1) + "/" + algoParams.size() + ": " +algoParams.get(i).toString());
res.add(ClusteringResult.fromParameters(emaComponentInstance, algoParams.get(i)));
}
return res;
}
}
......@@ -7,12 +7,12 @@ import java.util.Set;
// product if for clustering factory
public interface ClusteringAlgorithm {
List<Set<EMAComponentInstanceSymbol>> cluster(EMAComponentInstanceSymbol component, Object... args);
List<Set<EMAComponentInstanceSymbol>> cluster(ClusteringInput clusteringInput, Object... args);
//TODO: add arguments as typed state of the algorithms(instead of untyped)
default List<Set<EMAComponentInstanceSymbol>> clusterWithState(EMAComponentInstanceSymbol component){
default List<Set<EMAComponentInstanceSymbol>> clusterWithState(ClusteringInput clusteringInput){
Object[] args = getArgs();
return cluster(component, args);
return cluster(clusteringInput, args);
}
default Object[] getArgs(){
......
package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ClusteringInput {
private EMAComponentInstanceSymbol instanceSymbol;
private double[][] adjacencyMatrix;
private boolean initAdjMatrix = false;
private double[][] distanceMatrix;
private boolean initDistMatrix = false;
private List<EMAComponentInstanceSymbol> subcompsOrderedByName;
private boolean initSubcomposOrderedByName = false;
private Map<String, Integer> labelsForSubcomps;
private boolean initLabelsForSubcomps = false;
public ClusteringInput(EMAComponentInstanceSymbol instanceSymbol) {
this.instanceSymbol = instanceSymbol;
}
public EMAComponentInstanceSymbol getComponent() {
return instanceSymbol;
}
public double[][] getAdjacencyMatrix(){
if(!initAdjMatrix){
initAdjMatrix = true;
adjacencyMatrix = AutomaticClusteringHelper.guaranteedConnectedAdjacencyMatrix(getSubcompsOrderedByName(), ComponentHelper.getInnerConnectors(instanceSymbol),getLabelsForSubcomps());
}
return getCopyOf(adjacencyMatrix);
}
public double[][] getDistanceMatrix(){
if(!initDistMatrix){
initDistMatrix = true;
distanceMatrix = AutomaticClusteringHelper.getDistanceMatrix(getAdjacencyMatrix());
}
return getCopyOf(distanceMatrix);
}
public List<EMAComponentInstanceSymbol> getSubcompsOrderedByName(){
if(!initSubcomposOrderedByName){
initSubcomposOrderedByName = true;
subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(instanceSymbol);
}
return new ArrayList<>(subcompsOrderedByName);
}
public Map<String, Integer> getLabelsForSubcomps(){
if(!initLabelsForSubcomps){
initLabelsForSubcomps = true;
labelsForSubcomps = ComponentHelper.getLabelsForSubcomps(subcompsOrderedByName);
}
return new HashMap<>(labelsForSubcomps);
}
private double[][] getCopyOf(double[][] old){
double[][] res = new double[old.length][old[0].length];
for (int i = 0; i < old.length; i++) {
if (old[i].length >= 0) System.arraycopy(old[i], 0, res[i], 0, old[i].length);
}
return res;
}
}
......@@ -6,6 +6,7 @@ import com.google.gson.JsonParser;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.AlgorithmCliParameters;
import de.monticore.lang.monticar.generator.middleware.clustering.qualityMetric.Metric;
import de.monticore.lang.monticar.generator.middleware.clustering.visualization.ModelVisualizer;
import de.monticore.lang.monticar.generator.middleware.impls.MiddlewareTagGenImpl;
import de.se_rwth.commons.logging.Log;
......@@ -15,46 +16,83 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
public class ClusteringResult {
Double score = null;
private EMAComponentInstanceSymbol component;
private ClusteringInput clusteringInput;
private AlgorithmCliParameters parameters;
private List<Set<EMAComponentInstanceSymbol>> clustering;
private long durration;
private long duration;
private int componentNumber;
private boolean valid;
private Metric metric;
private ClusteringResult(EMAComponentInstanceSymbol component, AlgorithmCliParameters parameters,
List<Set<EMAComponentInstanceSymbol>> clustering, long durration, int componentNumber) {
this.component = component;
private ClusteringResult(ClusteringInput clusteringInput, AlgorithmCliParameters parameters,
List<Set<EMAComponentInstanceSymbol>> clustering, long duration, int componentNumber, boolean valid, Metric metric) {
this.clusteringInput = clusteringInput;
this.parameters = parameters;
this.clustering = clustering;
this.durration = durration;
this.duration = duration;
this.componentNumber = componentNumber;
this.valid = valid;
this.metric = metric;
}
public static ClusteringResult fromParameters(EMAComponentInstanceSymbol component, AlgorithmCliParameters parameters){
public static ClusteringResult fromParameters(ClusteringInput clusteringInput, AlgorithmCliParameters parameters, Metric metric) {
List<Set<EMAComponentInstanceSymbol>> res;
long startTime = System.currentTimeMillis();
List<Set<EMAComponentInstanceSymbol>> res = parameters.asClusteringAlgorithm().clusterWithState(component);
try {
res = parameters.asClusteringAlgorithm().clusterWithState(clusteringInput);
} catch (Exception e) {
Log.warn("Marking this result as invalid. Error clustering the component.", e);
return new ClusteringResult(clusteringInput, parameters, new ArrayList<>(), -1, clusteringInput.getComponent().getSubComponents().size(), false, metric);
}
long endTime = System.currentTimeMillis();
boolean curValid = true;
int clustersBefore = res.size();
res.removeIf(Set::isEmpty);
if (clustersBefore != res.size()) {
Log.warn("Removed " + (clustersBefore - res.size()) + " empty clusters for algorithm " + parameters.toString());
}