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