jsat.math
Class OnLineStatistics
- java.lang.Object
-
- jsat.math.OnLineStatistics
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.util.function.BiFunction<OnLineStatistics,OnLineStatistics,OnLineStatistics>, java.util.function.BinaryOperator<OnLineStatistics>
public class OnLineStatistics extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable, java.util.function.BinaryOperator<OnLineStatistics>
This class provides a means of updating summary statistics as each new data point is added. The data points are not stored, and values are updated with an online algorithm.
As such, this class has constant memory usage, regardless of how many values are added. But the results may not be as numerically accurate, and can degrade badly given specific data sequences.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description OnLineStatistics()Creates a new set of statistical counts with no informationOnLineStatistics(double n, double mean, double variance, double skew, double kurt)Creates a new set of statistical counts with these initial values, and can then be updated in an online fashionOnLineStatistics(OnLineStatistics other)Copy Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(double x)Adds a data sample with unit weight to the counts.voidadd(double x, double weight)Adds a data sample the the counts with the provided weight of influence.voidadd(OnLineStatistics B)Adds to the current statistics all the samples that were collected inB.static OnLineStatisticsadd(OnLineStatistics A, OnLineStatistics B)Computes a new set of counts that is the sum of the counts from the given distributions.OnLineStatisticsapply(OnLineStatistics t, OnLineStatistics u)OnLineStatisticsclone()doublegetKurtosis()doublegetMax()doublegetMean()doublegetMin()doublegetSkewness()doublegetStandardDeviation()doublegetSumOfWeights()Returns the sum of the weights for all data points added to the statistics.doublegetVarance()Computes the population variancevoidremove(double x, double weight)Effectively removes a sample with the given value and weight from the total.voidremove(OnLineStatistics B)Removes from this set of statistics the observations that where collected inB.
NOTE: removing statistics is not as numerically stable.static OnLineStatisticsremove(OnLineStatistics A, OnLineStatistics B)Computes a new set of statistics that is the equivalent of having removed all observations inBfromA.
-
-
-
Constructor Detail
-
OnLineStatistics
public OnLineStatistics()
Creates a new set of statistical counts with no information
-
OnLineStatistics
public OnLineStatistics(double n, double mean, double variance, double skew, double kurt)Creates a new set of statistical counts with these initial values, and can then be updated in an online fashion- Parameters:
n- the total weight of all data points added. This value must be non negativemean- the starting mean. If n is zero, this value will be ignored.variance- the starting variance. If n is zero, this value will be ignored.skew- the starting skewness. If n is zero, this value will be ignored.kurt- the starting kurtosis. If n is zero, this value will be ignored.- Throws:
java.lang.ArithmeticException- if n is a negative number
-
OnLineStatistics
public OnLineStatistics(OnLineStatistics other)
Copy Constructor- Parameters:
other- the version to make a copy of
-
-
Method Detail
-
add
public void add(double x)
Adds a data sample with unit weight to the counts.- Parameters:
x- the data value to add
-
add
public void add(double x, double weight)Adds a data sample the the counts with the provided weight of influence.- Parameters:
x- the data value to addweight- the weight to give the value- Throws:
java.lang.ArithmeticException- if a negative weight is given
-
remove
public void remove(double x, double weight)Effectively removes a sample with the given value and weight from the total. Removing values that have not been added may yield results that have no meaning
NOTE:getSkewness()andgetKurtosis()are not currently updated correctly- Parameters:
x- the value of the sampleweight- the weight of the sample- Throws:
java.lang.ArithmeticException- if a negative weight is given
-
remove
public static OnLineStatistics remove(OnLineStatistics A, OnLineStatistics B)
Computes a new set of statistics that is the equivalent of having removed all observations inBfromA.
NOTE: removing statistics is not as numerically stable. The values of the 3rd and 4th momentsgetSkewness()andgetKurtosis()will be inaccurate for many inputs. Theminandmaxcan not be determined in this setting, and will not be altered.- Parameters:
A- the first set of statistics, which must have a larger value forgetSumOfWeights()thanBB- the set of statistics to remove fromA.- Returns:
- a new set of statistics that is the removal of
BfromA
-
remove
public void remove(OnLineStatistics B)
Removes from this set of statistics the observations that where collected inB.
NOTE: removing statistics is not as numerically stable. The values of the 3rd and 4th momentsgetSkewness()andgetKurtosis()will be inaccurate for many inputs. Theminandmaxcan not be determined in this setting, and will not be altered.- Parameters:
B- the set of statistics to remove
-
add
public static OnLineStatistics add(OnLineStatistics A, OnLineStatistics B)
Computes a new set of counts that is the sum of the counts from the given distributions.
NOTE: Adding two statistics is not as numerically stable. If A and B have values of similar size and scale, the values of the 3rd and 4th momentsgetSkewness()andgetKurtosis()will suffer from catastrophic cancellations, and may not be as accurate.- Parameters:
A- the first set of statisticsB- the second set of statistics- Returns:
- a new set of statistics that is the addition of the two.
-
add
public void add(OnLineStatistics B)
Adds to the current statistics all the samples that were collected inB.
NOTE: Adding two statistics is not as numerically stable. If A and B have values of similar size and scale, the values of the 3rd and 4th momentsgetSkewness()andgetKurtosis()will suffer from catastrophic cancellations, and may not be as accurate.- Parameters:
B- the set of statistics to add to this set
-
clone
public OnLineStatistics clone()
- Overrides:
clonein classjava.lang.Object
-
getSumOfWeights
public double getSumOfWeights()
Returns the sum of the weights for all data points added to the statistics. If all weights were 1, then this value is the number of data points added.- Returns:
- the sum of weights for every point currently contained in the statistics.
-
getMean
public double getMean()
-
getVarance
public double getVarance()
Computes the population variance- Returns:
- the variance of the data seen
-
getStandardDeviation
public double getStandardDeviation()
-
getSkewness
public double getSkewness()
-
getKurtosis
public double getKurtosis()
-
getMin
public double getMin()
-
getMax
public double getMax()
-
apply
public OnLineStatistics apply(OnLineStatistics t, OnLineStatistics u)
- Specified by:
applyin interfacejava.util.function.BiFunction<OnLineStatistics,OnLineStatistics,OnLineStatistics>
-
-
DataMelt 3.0 © DataMelt by jWork.ORG