m-trieu commented on code in PR #29445:
URL: https://github.com/apache/beam/pull/29445#discussion_r1394868437


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/HistogramData.java:
##########
@@ -184,6 +193,26 @@ public synchronized void record(double value) {
       buckets[bucketType.getBucketIndex(value)]++;
       numBoundedBucketRecords++;
     }
+    updateStatistics(value);
+  }
+
+  /**
+   * Update 'mean' and 'sum of squared deviations' statistics with the newly 
recorded value <a
+   * 
href="https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm">
+   * Welford Method</a>.
+   *
+   * @param value
+   */
+  private void updateStatistics(double value) {
+    long count = getTotalCount();
+    if (count == 1) {
+      mean = value;
+      return;
+    }
+
+    double old_mean = mean;
+    mean = old_mean + (value - old_mean) / count;
+    sum_of_squared_deviations += (value - mean) * (value - old_mean);

Review Comment:
   for java, camel case is preferred 
https://google.github.io/styleguide/javaguide.html#s5.3-camel-case



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/HistogramData.java:
##########
@@ -184,6 +193,26 @@ public synchronized void record(double value) {
       buckets[bucketType.getBucketIndex(value)]++;
       numBoundedBucketRecords++;
     }
+    updateStatistics(value);
+  }
+
+  /**
+   * Update 'mean' and 'sum of squared deviations' statistics with the newly 
recorded value <a
+   * 
href="https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm">
+   * Welford Method</a>.
+   *
+   * @param value
+   */
+  private void updateStatistics(double value) {
+    long count = getTotalCount();
+    if (count == 1) {
+      mean = value;
+      return;
+    }
+
+    double old_mean = mean;

Review Comment:
   for java, camel case is preferred 
https://google.github.io/styleguide/javaguide.html#s5.3-camel-case



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to