Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efe539e

Browse files
author
Stephan Brandauer
committed
Java: better sampling of negative examples
1 parent a89378d commit efe539e

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

java/ql/src/Telemetry/AutomodelApplicationModeExtractNegativeExamples.ql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@ private import AutomodelApplicationModeCharacteristics
1212
private import AutomodelEndpointTypes
1313
private import AutomodelSharedUtil
1414

15+
/**
16+
* Gets a sample of endpoints for which the given characteristic applies.
17+
*/
18+
bindingset[limit]
19+
Endpoint getSampleForCharacteristic(EndpointCharacteristic c, int limit) {
20+
exists(int n |
21+
result =
22+
rank[n](Endpoint e2 | c.appliesToEndpoint(e2) | e2 order by e2.getLocation().toString()) and
23+
// we order the endpoints by location, but (to avoid bias) we select the indices semi-randomly
24+
n = 1 + (([1 .. limit] * 271) % count(Endpoint e | c.appliesToEndpoint(e)))
25+
)
26+
}
27+
1528
from
1629
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
1730
ApplicationModeMetadataExtractor meta, string package, string type, boolean subtypes, string name,
1831
string signature, string input
1932
where
20-
endpoint.getLocation().getStartLine() % 100 = 0 and
21-
characteristic.appliesToEndpoint(endpoint) and
33+
endpoint = getSampleForCharacteristic(characteristic, 100) and
2234
confidence >= SharedCharacteristics::highConfidence() and
2335
characteristic.hasImplications(any(NegativeSinkType negative), true, confidence) and
2436
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly

0 commit comments

Comments
 (0)