Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add minimum top contributor candidate queue size #151

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class AnomalyLocalizerImpl implements AnomalyLocalizer, Executable {
// Partitions the whole data to up to this number of buckets by time.
protected static final int MAX_TIME_BUCKETS = 8;

// The minimum number of contributor candidates.
protected static final int MIN_CONTRIBUTOR_CANDIDATE = 100;

private final Client client;
private final Settings settings;

Expand Down Expand Up @@ -187,11 +190,12 @@ private void onBaseEntryResponse(SearchResponse response, AnomalyLocalizationInp
result.getBuckets().stream().filter(e -> e.getCompleted() != null && e.getCompleted().get() == false)
.forEach(e -> {
PriorityQueue<AnomalyLocalizationOutput.Entity> queue;
int queueSize = Math.max(input.getNumOutputs(), MIN_CONTRIBUTOR_CANDIDATE);
if (e.getOverallAggValue() > 0) {
queue = new PriorityQueue<AnomalyLocalizationOutput.Entity>(input.getNumOutputs(),
queue = new PriorityQueue<AnomalyLocalizationOutput.Entity>(queueSize,
(a, b) -> (int) Math.signum(a.getContributionValue() - b.getContributionValue()));
} else {
queue = new PriorityQueue<AnomalyLocalizationOutput.Entity>(input.getNumOutputs(),
queue = new PriorityQueue<AnomalyLocalizationOutput.Entity>(queueSize,
(a, b) -> (int) Math.signum(b.getContributionValue() - a.getContributionValue()));
}
;
Expand Down