Skip to content

Commit 73aa790

Browse files
committed
Java: Improve sampling strategy
Instead of the "random" sampling used before (which could -- in rare circumstances -- end up sampling fewer points than we want) we now sample an equally distributed set of points.
1 parent d4b964c commit 73aa790

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

java/ql/src/Telemetry/AutomodelApplicationModeExtractNegativeExamples.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private import AutomodelSharedUtil
1818
*/
1919
bindingset[limit]
2020
Endpoint getSampleForCharacteristic(EndpointCharacteristic c, int limit) {
21-
exists(int n |
21+
exists(int n, int num_endpoints | num_endpoints = count(Endpoint e | c.appliesToEndpoint(e)) |
2222
result =
2323
rank[n](Endpoint e, Location loc |
2424
loc = e.getLocation() and c.appliesToEndpoint(e)
@@ -29,7 +29,7 @@ Endpoint getSampleForCharacteristic(EndpointCharacteristic c, int limit) {
2929
loc.getEndLine(), loc.getEndColumn()
3030
) and
3131
// we order the endpoints by location, but (to avoid bias) we select the indices semi-randomly
32-
n = 1 + (([1 .. limit] * 271) % count(Endpoint e | c.appliesToEndpoint(e)))
32+
n = 1 + (([0 .. limit - 1] * (num_endpoints / limit).floor() + 46337) % num_endpoints)
3333
)
3434
}
3535

0 commit comments

Comments
 (0)