org.matheclipse.core.stat.descriptive
Class SymbolicGeometricMean
- java.lang.Object
-
- org.matheclipse.core.stat.descriptive.AbstractSymbolicStorelessUnivariateStatistic
-
- org.matheclipse.core.stat.descriptive.SymbolicGeometricMean
-
- All Implemented Interfaces:
- java.io.Serializable, StorelessSymbolicUnivariateStatistic, SymbolicUnivariateStatistic
public class SymbolicGeometricMean extends AbstractSymbolicStorelessUnivariateStatistic implements java.io.Serializable
Returns the geometric mean of the available values.Uses a
SumOfLogsinstance to compute sum of logs and returnsexp( 1/n (sum of logs) ).Therefore,- If any of values are < 0, the result is
NaN. - If all values are non-negative and less than
Double.POSITIVE_INFINITY, but at least one value is 0, the result is0. - If both
Double.POSITIVE_INFINITYandDouble.NEGATIVE_INFINITYare among the values, the result isNaN.
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()orclear()method, it must be synchronized externally.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SymbolicGeometricMean()Create a GeometricMean instanceSymbolicGeometricMean(SymbolicSumOfLogs sumOfLogs)Create a GeometricMean instance using the given SumOfLogs instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Clears the internal state of the StatisticIExprevaluate(IAST values, int begin, int length)Returns the geometric mean of the entries in the specified portion of the input array.longgetN()Returns the number of values that have been added.IExprgetResult()Returns the current value of the Statistic.AbstractSymbolicStorelessUnivariateStatisticgetSumLogImpl()Returns the currently configured sum of logs implementationvoidincrement(IExpr d)Updates the internal state of the statistic to reflect the addition of the new value.voidsetSumLogImpl(AbstractSymbolicStorelessUnivariateStatistic sumLogImpl)Sets the implementation for the sum of logs.-
Methods inherited from class org.matheclipse.core.stat.descriptive.AbstractSymbolicStorelessUnivariateStatistic
evaluate, incrementAll, incrementAll
-
-
-
-
Constructor Detail
-
SymbolicGeometricMean
public SymbolicGeometricMean()
Create a GeometricMean instance
-
SymbolicGeometricMean
public SymbolicGeometricMean(SymbolicSumOfLogs sumOfLogs)
Create a GeometricMean instance using the given SumOfLogs instance- Parameters:
sumOfLogs- sum of logs instance to use for computation
-
-
Method Detail
-
increment
public void increment(IExpr d)
Updates the internal state of the statistic to reflect the addition of the new value.- Specified by:
incrementin interfaceStorelessSymbolicUnivariateStatistic- Specified by:
incrementin classAbstractSymbolicStorelessUnivariateStatistic- Parameters:
d- the new value.
-
getResult
public IExpr getResult()
Returns the current value of the Statistic.- Specified by:
getResultin interfaceStorelessSymbolicUnivariateStatistic- Specified by:
getResultin classAbstractSymbolicStorelessUnivariateStatistic- Returns:
- value of the statistic,
Double.NaNif it has been cleared or just instantiated.
-
clear
public void clear()
Clears the internal state of the Statistic- Specified by:
clearin interfaceStorelessSymbolicUnivariateStatistic- Specified by:
clearin classAbstractSymbolicStorelessUnivariateStatistic
-
evaluate
public IExpr evaluate(IAST values, int begin, int length)
Returns the geometric mean of the entries in the specified portion of the input array.See
SymbolicGeometricMeanfor details on the computing algorithm.Throws
IllegalArgumentExceptionif the array is null.- Specified by:
evaluatein interfaceSymbolicUnivariateStatistic- Overrides:
evaluatein classAbstractSymbolicStorelessUnivariateStatistic- Parameters:
values- input array containing the valuesbegin- first array element to includelength- the number of elements to include- Returns:
- the geometric mean or Double.NaN if length = 0 or any of the values are <= 0.
- Throws:
java.lang.IllegalArgumentException- if the input array is null or the array index parameters are not valid- See Also:
UnivariateStatistic.evaluate(double[], int, int)
-
getN
public long getN()
Returns the number of values that have been added.- Specified by:
getNin interfaceStorelessSymbolicUnivariateStatistic- Specified by:
getNin classAbstractSymbolicStorelessUnivariateStatistic- Returns:
- the number of values.
-
setSumLogImpl
public void setSumLogImpl(AbstractSymbolicStorelessUnivariateStatistic sumLogImpl)
Sets the implementation for the sum of logs.
This method must be activated before any data has been added - i.e., before
incrementhas been used to add data; otherwise an IllegalStateException will be thrown.- Parameters:
sumLogImpl- the StorelessUnivariateStatistic instance to use for computing the log sum- Throws:
java.lang.IllegalStateException- if data has already been added (i.e if n > 0)
-
getSumLogImpl
public AbstractSymbolicStorelessUnivariateStatistic getSumLogImpl()
Returns the currently configured sum of logs implementation- Returns:
- the StorelessUnivariateStatistic implementing the log sum
-
-
DMelt 3.0 © DataMelt by jWork.ORG