use of org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel in project elasticsearch by elastic.
the class MovAvgUnitTests method testSimpleMovAvgModel.
public void testSimpleMovAvgModel() {
MovAvgModel model = new SimpleModel();
int numValues = randomIntBetween(1, 100);
int windowSize = randomIntBetween(1, 50);
EvictingQueue<Double> window = new EvictingQueue<>(windowSize);
for (int i = 0; i < numValues; i++) {
double randValue = randomDouble();
double expected = 0;
if (i == 0) {
window.offer(randValue);
continue;
}
for (double value : window) {
expected += value;
}
expected /= window.size();
double actual = model.next(window);
assertThat(Double.compare(expected, actual), equalTo(0));
window.offer(randValue);
}
}
use of org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel in project elasticsearch by elastic.
the class MovAvgUnitTests method testSimplePredictionModel.
public void testSimplePredictionModel() {
MovAvgModel model = new SimpleModel();
int windowSize = randomIntBetween(1, 50);
int numPredictions = randomIntBetween(1, 50);
EvictingQueue<Double> window = new EvictingQueue<>(windowSize);
for (int i = 0; i < windowSize; i++) {
window.offer(randomDouble());
}
double[] actual = model.predict(window, numPredictions);
double[] expected = new double[numPredictions];
double t = 0;
for (double value : window) {
t += value;
}
t /= window.size();
Arrays.fill(expected, t);
for (int i = 0; i < numPredictions; i++) {
assertThat(Double.compare(expected[i], actual[i]), equalTo(0));
}
}
Aggregations