Top Description Fields Constructors Methods
org.apache.commons.math3.stat.descriptive.moment

public Class GeometricMean

extends AbstractStorelessUnivariateStatistic
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, org.apache.commons.math3.exception.MathIllegalArgumentException, .MathIllegalStateException, .NullArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic, .StorelessUnivariateStatistic, org.apache.commons.math3.stat.descriptive.summary.SumOfLogs, org.apache.commons.math3.util.FastMath, .MathUtils

Returns the geometric mean of the available values.

Uses a SumOfLogs instance to compute sum of logs and returns exp( 1/n (sum of logs) ). Therefore,

Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads invokes the increment() or clear() method, it must be synchronized externally.

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serializable version identifier

private StorelessUnivariateStatistic
sumOfLogs

Wrapped SumOfLogs instance

Constructor Summary

AccessConstructor and Description
public
GeometricMean()

Create a GeometricMean instance

public
GeometricMean(GeometricMean
the GeometricMean instance to copy
original
)

Copy constructor, creates a new GeometricMean identical to the original

public
GeometricMean(SumOfLogs
sum of logs instance to use for computation
sumOfLogs
)

Create a GeometricMean instance using the given SumOfLogs instance

Method Summary

Modifier and TypeMethod and Description
private void
checkEmpty()

Throws MathIllegalStateException if n > 0.

public void
public GeometricMean
public static void
copy(GeometricMean
GeometricMean to copy
source
,
GeometricMean
GeometricMean to copy to
dest
)

Copies source to dest.

public double

Returns:

the geometric mean or Double.NaN if length = 0 or any of the values are <= 0.
evaluate
(final double[]
input array containing the values
values
,
final int
first array element to include
begin
,
final int
the number of elements to include
length
)

Overrides org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.evaluate.

Implements org.apache.commons.math3.stat.descriptive.UnivariateStatistic.evaluate.

Returns the geometric mean of the entries in the specified portion of the input array.

public long
getN()

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Returns the number of values that have been added.

public double
public StorelessUnivariateStatistic

Returns:

the StorelessUnivariateStatistic implementing the log sum
getSumLogImpl
()

Returns the currently configured sum of logs implementation

public void
increment(final double
the new value.
d
)

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

Updates the internal state of the statistic to reflect the addition of the new value.

public void
setSumLogImpl(StorelessUnivariateStatistic
the StorelessUnivariateStatistic instance to use for computing the log sum
sumLogImpl
)

Sets the implementation for the sum of logs.

Inherited from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic:
equalsevaluatehashCodeincrementAllincrementAll

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

sumOfLogsback to summary
private StorelessUnivariateStatistic sumOfLogs

Wrapped SumOfLogs instance

Constructor Detail

GeometricMeanback to summary
public GeometricMean()

Create a GeometricMean instance

GeometricMeanback to summary
public GeometricMean(GeometricMean original) throws NullArgumentException

Copy constructor, creates a new GeometricMean identical to the original

Parameters
original:GeometricMean

the GeometricMean instance to copy

Exceptions
NullArgumentException:
if original is null
GeometricMeanback to summary
public GeometricMean(SumOfLogs sumOfLogs)

Create a GeometricMean instance using the given SumOfLogs instance

Parameters
sumOfLogs:SumOfLogs

sum of logs instance to use for computation

Method Detail

checkEmptyback to summary
private void checkEmpty() throws MathIllegalStateException

Throws MathIllegalStateException if n > 0.

Exceptions
MathIllegalStateException:
if data has been added to this statistic
clearback to summary
public void clear()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.clear.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.clear.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.clear.

Clears the internal state of the Statistic

Annotations
@Override
copyback to summary
public GeometricMean copy()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.copy.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.copy, org.apache.commons.math3.stat.descriptive.UnivariateStatistic.copy.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.copy.

Returns a copy of the statistic with the same internal state.

Returns:GeometricMean

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.copy.

a copy of the statistic

Annotations
@Override
copyback to summary
public static void copy(GeometricMean source, GeometricMean dest) throws NullArgumentException

Copies source to dest.

Neither source nor dest can be null.

Parameters
source:GeometricMean

GeometricMean to copy

dest:GeometricMean

GeometricMean to copy to

Exceptions
NullArgumentException:
if either source or dest is null
evaluateback to summary
public double evaluate(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Overrides org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.evaluate.

Implements org.apache.commons.math3.stat.descriptive.UnivariateStatistic.evaluate.

Returns the geometric mean of the entries in the specified portion of the input array.

See GeometricMean for details on the computing algorithm.

Throws IllegalArgumentException if the array is null.

Parameters
values:double[]

input array containing the values

begin:int

first array element to include

length:int

the number of elements to include

Returns:double

the geometric mean or Double.NaN if length = 0 or any of the values are <= 0.

Annotations
@Override
Exceptions
MathIllegalArgumentException:
if the input array is null or the array index parameters are not valid
getNback to summary
public long getN()

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Returns the number of values that have been added.

Returns:long

the number of values.

getResultback to summary
public double getResult()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.getResult.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getResult.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.getResult.

Returns the current value of the Statistic.

Returns:double

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getResult.

value of the statistic, Double.NaN if it has been cleared or just instantiated.

Annotations
@Override
getSumLogImplback to summary
public StorelessUnivariateStatistic getSumLogImpl()

Returns the currently configured sum of logs implementation

Returns:StorelessUnivariateStatistic

the StorelessUnivariateStatistic implementing the log sum

incrementback to summary
public void increment(final double d)

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Updates the internal state of the statistic to reflect the addition of the new value.

Parameters
d:double

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

the new value.

Annotations
@Override
setSumLogImplback to summary
public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl) throws MathIllegalStateException

Sets the implementation for the sum of logs.

This method must be activated before any data has been added - i.e., before increment has been used to add data; otherwise an IllegalStateException will be thrown.

Parameters
sumLogImpl:StorelessUnivariateStatistic

the StorelessUnivariateStatistic instance to use for computing the log sum

Exceptions
MathIllegalStateException:
if data has already been added (i.e if n > 0)