All Downloads are FREE. Search and download functionalities are using the official Maven repository.

netflix.ocelli.util.ExpAvg Maven / Gradle / Ivy

There is a newer version: 0.1.0-rc.2
Show newest version
package netflix.ocelli.util;

public class ExpAvg implements Average {
    
    private final double k;
    private volatile double ema = 0;
    
    public ExpAvg(int N) {
        this.k = 2.0/(double)(N+1);
    }
    
    @Override
    public synchronized void addSample(long sample) {
        ema = sample * k + ema * (1-k);
    }

    @Override
    public double get() {
        return ema;
    }

    @Override
    public synchronized void reset() {
        ema = 0;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy