Search in sources :

Example 1 with SimpleModel

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);
    }
}
Also used : SimpleModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel) MovAvgModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel) EvictingQueue(org.elasticsearch.common.collect.EvictingQueue)

Example 2 with SimpleModel

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));
    }
}
Also used : SimpleModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel) MovAvgModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel) EvictingQueue(org.elasticsearch.common.collect.EvictingQueue)

Aggregations

EvictingQueue (org.elasticsearch.common.collect.EvictingQueue)2 MovAvgModel (org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel)2 SimpleModel (org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel)2