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

netflix.ocelli.stats.Frugal2UQuantiles Maven / Gradle / Ivy

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

import java.util.Random;

/**
 * Implementation of the Frugal2U Algorithm.
 * 
 * Reference:
 *  Ma, Qiang, S. Muthukrishnan, and Mark Sandler. "Frugal Streaming for
 *    Estimating Quantiles." Space-Efficient Data Structures, Streams, and
 *    Algorithms. Springer Berlin Heidelberg, 2013. 77-96.
 * 
 * Original code: 
 * More info: http://blog.aggregateknowledge.com/2013/09/16/sketch-of-the-day-frugal-streaming/
 * 
 * @author Maycon Viana Bordin 
 */
public class Frugal2UQuantiles implements Quantiles {

    private final Quantile quantiles[];

    public Frugal2UQuantiles(Quantile[] quantiles) {
        this.quantiles = quantiles;
    }
    
    public Frugal2UQuantiles(double[] quantiles, int initialEstimate) {
        this.quantiles = new Quantile[quantiles.length];
        for (int i=0; i m && r.nextDouble() > 1-q) {
                step += sign * f(step);
                
                if (step > 0) {
                    m += step;
                } else {
                    m += 1;
                }
                
                if (m > s) {
                    step += (s - m);
                    m = s;
                }
                
                if (sign < 0) {
                    step = 1;
                }
                
                sign = 1;
            } else if (s < m && r.nextDouble() > q) {
                step += -sign * f(step);
                
                if (step > 0) {
                    m -= step;
                } else {
                    m--;
                }
                
                if (m < s) {
                    step += (m - s);
                    m = s;
                }
                
                if (sign > 0) {
                    step = 1;
                }
                
                sign = -1;
            }
        }
        
        int f(int step) {
            return 1;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy