Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added basic interfaces
  • Loading branch information
amandelpie committed Jul 5, 2022
commit d7c570ea48c15c5b13abb67919b7c6218b6b721a
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package org.utbot.summary.clustering

import org.utbot.framework.plugin.api.Step
import smile.math.distance.Distance
import org.utbot.summary.clustering.dbscan.Distance

class ExecutionDistance : Distance<Iterable<Step>> {
override fun d(x: Iterable<Step>, y: Iterable<Step>): Double {
return compareTwoPaths(x, y)
}

/**
* Minimum Edit Distance
*/
Expand All @@ -31,4 +27,8 @@ class ExecutionDistance : Distance<Iterable<Step>> {
private fun distance(stmt1: Step, stmt2: Step): Int {
return if (stmt1 == stmt2) 0 else 2
}

override fun compute(object1: Iterable<Step>, object2: Iterable<Step>): Double {
return compareTwoPaths(object1, object2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.utbot.framework.plugin.api.Step
import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtTestCase
import org.utbot.summary.UtSummarySettings
import org.utbot.summary.clustering.dbscan.DBSCANTrainer
import smile.clustering.dbscan

class MatrixUniqueness {
Expand Down Expand Up @@ -89,8 +90,11 @@ class MatrixUniqueness {
radius: Double = UtSummarySettings.RADIUS_DBSCAN
): Map<Int, List<UtExecution>> {
val executionPaths = methodExecutions.map { it.path.asIterable() }.toTypedArray()
val cluster = dbscan(executionPaths, ExecutionDistance(), minPts, radius)
return methodExecutions.withIndex().groupBy({ cluster.y[it.index] }, { it.value })
val dbscan = DBSCANTrainer(eps = radius.toFloat(), minSamples = minPts, metric = ExecutionDistance())
val dbscanModel = dbscan.fit(executionPaths)
val clusterLabels = dbscanModel.clusterLabels
//val cluster = dbscan(executionPaths, ExecutionDistance(), minPts, radius)
return methodExecutions.withIndex().groupBy({ clusterLabels[it.index] }, { it.value })
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.utbot.summary.clustering.dbscan

/**
* @property k
* @property clusterLabels
* @property clusterSizes The number of observations in each cluster.
*/
class DBSCANModel(val k: Int = 0, val clusterLabels: IntArray, val clusterSizes: IntArray) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.utbot.summary.clustering.dbscan

class DBSCANTrainer<T>(val eps: Float, val minSamples: Int, val metric: Distance<T>) {
init {
require(minSamples > 0) { "MinSamples parameter should be more than 0: $minSamples" }
require(eps > 0.0f) { "Eps parameter should be more than 0: $eps" }
}


fun fit(data: Array<T>): DBSCANModel {
val numberOfClusters = 0
val clusterLabels = IntArray(data.size)
val clusterSizes = IntArray(numberOfClusters)
return DBSCANModel(k = numberOfClusters, clusterLabels = clusterLabels, clusterSizes = clusterSizes)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.utbot.summary.clustering.dbscan


interface Distance<T> {
fun compute(object1: T, object2: T): Double
}