use of org.opensearch.ml.common.parameter.Output in project ml-commons by opensearch-project.
the class AnomalyLocalizerImpl method processBaseEntry.
private void processBaseEntry(AnomalyLocalizationInput input, AggregationBuilder agg, AnomalyLocalizationOutput.Result result, AnomalyLocalizationOutput.Bucket bucket, Counter counter, Optional<Map<String, Object>> afterKey, AnomalyLocalizationOutput output, ActionListener<AnomalyLocalizationOutput> listener) {
SearchRequest request = newSearchRequestForEntry(input, agg, bucket, afterKey);
client.search(request, wrap(r -> onBaseEntryResponse(r, input, agg, result, bucket, counter, output, listener), listener::onFailure));
}
use of org.opensearch.ml.common.parameter.Output in project ml-commons by opensearch-project.
the class AnomalyLocalizerImpl method onNewEntryResponse.
/**
* Chooses entities from the new bucket that contribute the most to the overall change.
*/
private void onNewEntryResponse(SearchResponse response, AnomalyLocalizationInput input, AggregationBuilder agg, AnomalyLocalizationOutput.Result result, AnomalyLocalizationOutput.Bucket outputBucket, PriorityQueue<AnomalyLocalizationOutput.Entity> queue, AnomalyLocalizationOutput output, ActionListener<AnomalyLocalizationOutput> listener) {
Optional<CompositeAggregation> respAgg = Optional.ofNullable(response.getAggregations()).map(aggs -> (CompositeAggregation) aggs.get(agg.getName()));
for (CompositeAggregation.Bucket bucket : respAgg.map(a -> a.getBuckets()).orElse(Collections.emptyList())) {
List<String> key = toStringKey(bucket.getKey(), input);
AnomalyLocalizationOutput.Entity entity = new AnomalyLocalizationOutput.Entity();
entity.setKey(key);
entity.setNewValue(getDoubleValue((SingleValue) bucket.getAggregations().get(agg.getName())));
entity.setBaseValue(outputBucket.getBase().get().getCounter().get().estimate(key));
entity.setContributionValue(entity.getNewValue() - entity.getBaseValue());
if (queue.size() < input.getNumOutputs()) {
queue.add(entity);
} else if (queue.comparator().compare(queue.peek(), entity) < 0) {
queue.poll();
queue.add(entity);
}
}
Optional<Map<String, Object>> afterKey = respAgg.map(r -> r.afterKey());
if (afterKey.isPresent()) {
processNewEntry(input, agg, result, outputBucket, afterKey, queue, output, listener);
} else {
List<List<String>> keys = queue.stream().map(AnomalyLocalizationOutput.Entity::getKey).collect(Collectors.toList());
SearchRequest request = newSearchRequestForEntityKeys(input, agg, outputBucket, keys);
client.search(request, wrap(r -> onEntityKeysResponse(r, input, agg, result, outputBucket, queue, output, listener), listener::onFailure));
}
}
use of org.opensearch.ml.common.parameter.Output in project ml-commons by opensearch-project.
the class AnomalyLocalizerImpl method getOverallAggregates.
private void getOverallAggregates(AnomalyLocalizationInput input, LocalizationTimeBuckets timeBuckets, AggregationBuilder agg, AnomalyLocalizationOutput output, ActionListener<AnomalyLocalizationOutput> listener) {
MultiSearchRequest searchRequest = newSearchRequestForOverallAggregates(input, agg, timeBuckets);
client.multiSearch(searchRequest, wrap(r -> onOverallAggregatesResponse(r, input, agg, output, timeBuckets, listener), listener::onFailure));
}
use of org.opensearch.ml.common.parameter.Output in project ml-commons by opensearch-project.
the class MLExecuteTaskRunner method executeTask.
/**
* Execute algorithm and return result.
* TODO: 1. support backend task run; 2. support dispatch task to remote node
* @param request MLExecuteTaskRequest
* @param transportService transport service
* @param listener Action listener
*/
@Override
public void executeTask(MLExecuteTaskRequest request, TransportService transportService, ActionListener<MLExecuteTaskResponse> listener) {
threadPool.executor(TASK_THREAD_POOL).execute(() -> {
Input input = request.getInput();
Output output = MLEngine.execute(input);
MLExecuteTaskResponse response = MLExecuteTaskResponse.builder().output(output).build();
listener.onResponse(response);
});
}
use of org.opensearch.ml.common.parameter.Output in project ml-commons by opensearch-project.
the class MachineLearningNodeClient method execute.
@Override
public void execute(Input input, ActionListener<Output> listener) {
MLExecuteTaskRequest executeTaskRequest = MLExecuteTaskRequest.builder().input(input).build();
client.execute(MLExecuteTaskAction.INSTANCE, executeTaskRequest, ActionListener.wrap(response -> {
listener.onResponse(MLExecuteTaskResponse.fromActionResponse(response).getOutput());
}, listener::onFailure));
}
Aggregations