apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhupeshchawda <...@git.apache.org>
Subject [GitHub] apex-malhar pull request #301: [APEXMALHAR-2094] Quantiles operator
Date Tue, 07 Jun 2016 22:00:43 GMT
Github user bhupeshchawda commented on a diff in the pull request:

    https://github.com/apache/apex-malhar/pull/301#discussion_r66160956
  
    --- Diff: sketches/src/main/java/org/apache/apex/malhar/sketches/QuantilesEstimator.java
---
    @@ -0,0 +1,188 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.apex.malhar.sketches;
    +
    +import com.yahoo.sketches.quantiles.QuantilesSketch;
    +
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.DefaultOutputPort;
    +import com.datatorrent.api.annotation.OperatorAnnotation;
    +import com.datatorrent.common.util.BaseOperator;
    +
    +/**
    + * An implementation of BaseOperator that computes a "sketch" (a representation of the
probability distribution using
    + * a low memory footprint) of the incoming numeric data, and evaluates/outputs the cumulative
distribution function and
    + * quantiles of the probability distribution. Leverages the quantiles sketch implementation
from the Yahoo Datasketches
    + * Library.
    + * <p/>
    + * <b>Input Port(s) : </b><br>
    + * <b>data : </b> Data values input port. <br>
    + * <br>
    + * <b>Output Port(s) : </b> <br>
    + * <b>cdfOutput : </b>cumulative distribution function output port. <br>
    + * <b>quantilesOutput : </b>quantiles output port. <br>
    + * <br>
    + * <b>Partitions : </b> No unifier. Merging these sketches is non-trivial.
<br>
    + * <br>+
    + */
    +@OperatorAnnotation(partitionable = false)
    +public class QuantilesEstimator extends BaseOperator
    +{
    +  /**
    +   * Constructor that allows non-default initialization of the quantile sketch object
    +   *
    +   * @param k:    Parameter that determines accuracy and memory usage of quantile sketch.
See QuantilesSketch
    +   *              documentation for details
    +   * @param seed: The quantile sketch algorithm is inherently random. Set seed to 0 for
reproducibility in testing, but
    +   *              do not set otherwise.
    +   */
    +  public QuantilesEstimator(int k, short seed)
    +  {
    +    quantilesSketch = QuantilesSketch.builder().setSeed(seed).build(k);
    +  }
    +
    +  private transient QuantilesSketch quantilesSketch = QuantilesSketch.builder().build();
    +
    +  /**
    +   * This field determines the specific quantiles to be calculated. For a stream of numbers,
the quantile at a value
    +   * 0 <= p <= 1 is the number x such that a fraction p of the numbers in the sorted
stream are less than x. E.g., the
    +   * quantile at p = 0.5 is the median (half the numbers in the stream are less than
the median).
    +   * The default is set to compute the standard quartiles (4-quantiles).
    +   */
    +  private double[] fractions = {0.0, 0.25, 0.50, 0.75, 1.00};
    +  /**
    +   * This field determines the intervals on which the probability mass function is computed.
    +   */
    +  private double[] pmfIntervals = {};
    +
    +  /**
    +   * This operator computes three different quantities which are output on separate output
ports. If not using any of
    +   * these quantities, these variables can be set to avoid unnecessary computation.
    +   */
    +  private boolean computeCdf = true;
    +  private boolean computeQuantiles = true;
    +  private boolean computePmf = true;
    +
    +  public boolean isComputeCdf()
    +  {
    +    return computeCdf;
    +  }
    +
    +  public void setComputeCdf(boolean computeCdf)
    --- End diff --
    
    Better to add java docs on getters and setters, the users will access the fields using
these. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message