Github user mattf-horton commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/401#discussion_r93573955
  
    --- Diff: 
metron-analytics/metron-statistics/src/main/java/org/apache/metron/statistics/MathFunctions.java
 ---
    @@ -59,4 +60,49 @@ public boolean isInitialized() {
           return true;
         }
       }
    +
    +  /**
    +   * Calculates the statistical bin that a value falls in.
    +   */
    +  @Stellar(name = "BIN"
    +          , description = "Computes the bin that the value is in given a 
set of bounds."
    +          , params = {
    +           "value - The value to bin"
    +          , "bounds - A list of value bounds (excluding min and max) in 
sorted order."
    +                    }
    +          ,returns = "Which bin N the value falls in such that bound(N-1) 
< value <= bound(N). " +
    +          "No min and max bounds are provided, so values smaller than the 
0'th bound go in the 0'th bin, " +
    +          "and values greater than the last bound go in the M'th bin."
    +  )
    +  public static class Bin extends BaseStellarFunction {
    +
    +    public static int getBin(double value, List<Double> bins, 
Function<Integer, Double> boundFunc) {
    +      for(int bin = 0; bin < bins.size();++bin) {
    +        double bound = boundFunc.apply(bin);
    +        if(value <= bound) {
    +          return bin;
    +        }
    +      }
    +      return bins.size();
    +    }
    +
    +    @Override
    +    public Object apply(List<Object> args) {
    +      Double value = convert(args.get(0), Double.class);
    +      List<Double> bins = new ArrayList<>();
    +      if (args.size() > 1) {
    +        List<Number> objList = convert(args.get(1), List.class);
    +        if(objList == null) {
    +          return null;
    +        }
    +        for(Number n : objList) {
    +          bins.add(n.doubleValue());
    --- End diff --
    
    During this step we need to validate that the bounds list is strictly 
increasing.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to