use of org.elasticsearch.search.aggregations.pipeline.movavg.models.LinearModel in project elasticsearch by elastic.
the class MovAvgUnitTests method testLinearMovAvgModel.
public void testLinearMovAvgModel() {
MovAvgModel model = new LinearModel();
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();
if (i == 0) {
window.offer(randValue);
continue;
}
double avg = 0;
long totalWeight = 1;
long current = 1;
for (double value : window) {
avg += value * current;
totalWeight += current;
current += 1;
}
double expected = avg / totalWeight;
double actual = model.next(window);
assertThat(Double.compare(expected, actual), equalTo(0));
window.offer(randValue);
}
}
use of org.elasticsearch.search.aggregations.pipeline.movavg.models.LinearModel in project elasticsearch by elastic.
the class MovAvgUnitTests method testLinearPredictionModel.
public void testLinearPredictionModel() {
MovAvgModel model = new LinearModel();
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 avg = 0;
long totalWeight = 1;
long current = 1;
for (double value : window) {
avg += value * current;
totalWeight += current;
current += 1;
}
avg = avg / totalWeight;
Arrays.fill(expected, avg);
for (int i = 0; i < numPredictions; i++) {
assertThat(Double.compare(expected[i], actual[i]), equalTo(0));
}
}
Aggregations