
net.sf.jagg.VarianceAggregator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jagg-core Show documentation
Show all versions of jagg-core Show documentation
jAgg is a Java 5.0 API that supports “group by” operations on Lists of Java objects: aggregate operations such as count, sum, max, min, avg, and many more. It also allows custom aggregate operations.
The newest version!
package net.sf.jagg;
import net.sf.jagg.math.DoubleDouble;
/**
* This class represents the "sample variance" aggregator over numeric values.
*
* @author Randy Gettman
* @since 0.1.0
*/
public class VarianceAggregator extends AbstractVarianceAggregator
{
/**
* Constructs an VarianceAggregator
that operates on the specified
* property.
* @param property Calculate the variance of this property's values.
*/
public VarianceAggregator(String property)
{
super(property);
}
/**
* Returns an uninitialized copy of this Aggregator
object,
* with the same property(ies) to analyze.
* @return An uninitialized copy of this Aggregator
object.
*/
public VarianceAggregator replicate()
{
return new VarianceAggregator(getProperty());
}
/**
* Return the sample variance by dividing the variance numerator by
* (n - 1), where n is the number of non-null pairs of
* numbers.
*
* @return The sample variance as a Double
,
* NaN
if no values have been accumulated, or 0 if exactly
* one value has been accumulated.
*/
public Double terminate()
{
return terminateDoubleDouble().doubleValue();
}
/**
* Return the result as a DoubleDouble
. This is used mainly
* when other Aggregators
that use this result must maintain a
* high precision.
* @return The sample variance as a DoubleDouble
,
* NaN
if no values have been accumulated, or 0 if exactly
* one value has been accumulated.
* @since 0.4.0
*/
public DoubleDouble terminateDoubleDouble()
{
if (myCount <= 0)
return new DoubleDouble(DoubleDouble.NaN);
if (myCount == 1)
return new DoubleDouble(0);
DoubleDouble result = new DoubleDouble(myVarNumerator);
result.divideSelfBy(myCount - 1);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy