use of org.opensearch.ml.common.parameter.Output in project ml-commons by opensearch-project.
the class LocalSampleCalculator method execute.
@Override
public Output execute(Input input) {
if (input == null || !(input instanceof LocalSampleCalculatorInput)) {
throw new IllegalArgumentException("wrong input");
}
LocalSampleCalculatorInput sampleCalculatorInput = (LocalSampleCalculatorInput) input;
String operation = sampleCalculatorInput.getOperation();
List<Double> inputData = sampleCalculatorInput.getInputData();
switch(operation) {
case "sum":
double sum = inputData.stream().mapToDouble(f -> f.doubleValue()).sum();
return new SampleAlgoOutput(sum);
case "max":
double max = inputData.stream().max(Comparator.naturalOrder()).get();
return new SampleAlgoOutput(max);
case "min":
double min = inputData.stream().min(Comparator.naturalOrder()).get();
return new SampleAlgoOutput(min);
default:
throw new IllegalArgumentException("can't support this operation");
}
}
use of org.opensearch.ml.common.parameter.Output in project ml-commons by opensearch-project.
the class AnomalyLocalizerImpl method processNewEntry.
private void processNewEntry(AnomalyLocalizationInput input, AggregationBuilder agg, AnomalyLocalizationOutput.Result result, AnomalyLocalizationOutput.Bucket bucket, Optional<Map<String, Object>> afterKey, PriorityQueue<AnomalyLocalizationOutput.Entity> queue, AnomalyLocalizationOutput output, ActionListener<AnomalyLocalizationOutput> listener) {
SearchRequest request = newSearchRequestForEntry(input, agg, bucket, afterKey);
client.search(request, wrap(r -> onNewEntryResponse(r, input, agg, result, bucket, queue, output, listener), listener::onFailure));
}
Aggregations