1 16 package org.apache.commons.math.stat.descriptive.summary; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; 21 22 43 public class SumOfLogs extends AbstractStorelessUnivariateStatistic implements Serializable { 44 45 46 static final long serialVersionUID = -370076995648386763L; 47 48 49 private int n; 50 51 54 private double value; 55 56 59 public SumOfLogs() { 60 value = 0d; 61 n = 0; 62 } 63 64 67 public void increment(final double d) { 68 value += Math.log(d); 69 n++; 70 } 71 72 75 public double getResult() { 76 if (n > 0) { 77 return value; 78 } else { 79 return Double.NaN; 80 } 81 } 82 83 86 public long getN() { 87 return n; 88 } 89 90 93 public void clear() { 94 value = 0d; 95 n = 0; 96 } 97 98 115 public double evaluate(final double[] values, final int begin, final int length) { 116 double sumLog = Double.NaN; 117 if (test(values, begin, length)) { 118 sumLog = 0.0; 119 for (int i = begin; i < begin + length; i++) { 120 sumLog += Math.log(values[i]); 121 } 122 } 123 return sumLog; 124 } 125 } | Popular Tags |