metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickwallen <...@git.apache.org>
Subject [GitHub] incubator-metron pull request #226: METRON-377 Enable Profiles that Use Non-...
Date Wed, 24 Aug 2016 17:39:33 GMT
Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/226#discussion_r76103558
  
    --- Diff: metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StellarStatistics.java
---
    @@ -0,0 +1,207 @@
    +/*
    + *
    + *  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.metron.common.dsl.functions;
    +
    +import org.apache.commons.lang.NotImplementedException;
    +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
    +import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
    +
    +import java.io.Serializable;
    +
    +/**
    + * Provides basic summary statistics to Stellar.
    + *
    + * Used as an adapter to provide a single interface to two underlying Commons
    + * Math classes that provide summary statistics.
    + */
    +public class StellarStatistics implements Serializable {
    +
    +  /**
    +   * DescriptiveStatistics stores a rolling window of input data elements
    +   * which is then used to calculate the summary statistic.  There are some
    +   * summary statistics like kurtosis and percentiles, that can only
    +   * be calculated with this.
    +   *
    +   * This implementation is used if the windowSize > 0.
    +   */
    +  private DescriptiveStatistics descStats;
    +
    +  /**
    +   * SummaryStatistics can be used for summary statistics that only
    +   * require a single pass over the input data.  This has the advantage
    +   * of being less memory intensive, but not all summary statistics are
    +   * available.
    +   *
    +   * This implementation is used if the windowSize == 0.
    +   */
    +  private SummaryStatistics summStats;
    +
    +  /**
    +   * @param windowSize The number of input data elements to maintain in memory.  If
    +   *                   windowSize == 0, then no data elements will be maintained in
    +   *                   memory.
    +   */
    +  public StellarStatistics(int windowSize) {
    +
    +    // only one of the underlying implementation classes will be used at a time
    +    if(windowSize > 0) {
    +      descStats = new DescriptiveStatistics(windowSize);
    +    } else {
    +      summStats = new SummaryStatistics();
    +    }
    +  }
    +
    +  public void addValue(double value) {
    +    if(descStats != null) {
    +      descStats.addValue(value);
    +    } else {
    +      summStats.addValue(value);
    +    }
    +  }
    +
    +  public long getCount() {
    +    if(descStats != null) {
    +      return descStats.getN();
    +    } else {
    +      return summStats.getN();
    +    }
    +  }
    +
    +  public double getMin() {
    +    if(descStats != null) {
    +      return descStats.getMin();
    +    } else {
    +      return summStats.getMin();
    +    }
    +  }
    +
    +  public double getMax() {
    +    if(descStats != null) {
    +      return descStats.getMax();
    +    } else {
    +      return summStats.getMax();
    +    }
    +  }
    +
    +  public double getMean() {
    +    if(descStats != null) {
    +      return descStats.getMean();
    +    } else {
    +      return summStats.getMean();
    +    }
    +  }
    +
    +  public double getSum() {
    +    if(descStats != null) {
    +      return descStats.getSum();
    +    } else {
    +      return summStats.getSum();
    +    }
    +  }
    +
    +  public double getVariance() {
    +    if(descStats != null) {
    +      return descStats.getVariance();
    +    } else {
    +      return summStats.getVariance();
    +    }
    +  }
    +
    +  public double getStandardDeviation() {
    +    if(descStats != null) {
    +      return descStats.getStandardDeviation();
    +    } else {
    +      return summStats.getStandardDeviation();
    +    }
    +  }
    +
    +  public double getGeometricMean() {
    +    if(descStats != null) {
    +      return descStats.getGeometricMean();
    +    } else {
    +      return summStats.getGeometricMean();
    +    }
    +  }
    +
    +  public double getPopulationVariance() {
    +    if(descStats != null) {
    +      return descStats.getPopulationVariance();
    +    } else {
    +      return summStats.getPopulationVariance();
    +    }
    +  }
    +
    +  public double getSecondMoment() {
    +    if(descStats != null) {
    +      throw new NotImplementedException("second moment not available if 'windowSize'
> 0");
    --- End diff --
    
    @cestella pointed out that second moment is the same as variance.  The naming between
DescriptiveStatistics and SummaryStatistics just differs.  Just added a commit that removes
`STATS_SECOND_MOMENT` as it is redundant.  Thanks!


---
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