
net.sf.jagg.CovariancePopAggregator 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 "population covariance" aggregator over two sets
* of numeric values.
*
* @author Randy Gettman
* @since 0.1.0
*/
public class CovariancePopAggregator extends AbstractCovarianceAggregator
{
/**
* Constructs a CovariancePopAggregator
on the specified
* properties, in the format: property, property2
.
* @param properties A specification string in the format:
* property, property2
.
*/
public CovariancePopAggregator(String properties)
{
super(properties);
}
/**
* Constructs a CovariancePopAggregator
that operates on the specified
* properties.
* @param property Determine the population covariance of this property with the other.
* @param property2 Determine the population covariance of this property with the other.
*/
public CovariancePopAggregator(String property, String property2)
{
super(property, property2);
}
/**
* Returns an uninitialized copy of this Aggregator
object,
* with the same property(ies) to analyze.
* @return An uninitialized copy of this Aggregator
object.
*/
public CovariancePopAggregator replicate()
{
return new CovariancePopAggregator(getProperty(), getProperty2());
}
/**
* Return the population covariance by dividing the variance numerator by
* n, where n is the number of non-null pairs of numbers
* present in the aggregation.
*
* @return The population covariance 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 population covariance 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);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy