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

public Class Sum

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

Returns the sum of the available values.

If there are no values in the dataset, then 0 is returned. If any of the values are NaN, then NaN is returned.

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 long
n

private static final long
serialVersionUID

Serializable version identifier

private double
value

The currently running sum.

Constructor Summary

AccessConstructor and Description
public
Sum()

Create a Sum instance

public
Sum(Sum
the Sum instance to copy
original
)

Copy constructor, creates a new Sum identical to the original

Method Summary

Modifier and TypeMethod and Description
public void
public Sum
public static void
copy(Sum
Sum to copy
source
,
Sum
Sum to copy to
dest
)

Copies source to dest.

public double

Returns:

the sum of the values or 0 if length = 0
evaluate
(final double[]
the input array
values
,
final int
index of the 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.

The sum of the entries in the specified portion of the input array, or 0 if the designated subarray is empty.

public double

Returns:

the sum of the values or 0 if length = 0
evaluate
(final double[]
the input array
values
,
final double[]
the weights array
weights
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

The weighted sum of the entries in the specified portion of the input array, or 0 if the designated subarray is empty.

public double

Returns:

the sum of the values or Double.NaN if length = 0
evaluate
(final double[]
the input array
values
,
final double[]
the weights array
weights
)

The weighted sum of the entries in the 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 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.

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

Field Detail

nback to summary
private long n
serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

valueback to summary
private double value

The currently running sum.

Constructor Detail

Sumback to summary
public Sum()

Create a Sum instance

Sumback to summary
public Sum(Sum original) throws NullArgumentException

Copy constructor, creates a new Sum identical to the original

Parameters
original:Sum

the Sum instance to copy

Exceptions
NullArgumentException:
if original is null

Method Detail

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 Sum 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:Sum

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

a copy of the statistic

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

Copies source to dest.

Neither source nor dest can be null.

Parameters
source:Sum

Sum to copy

dest:Sum

Sum 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.

The sum of the entries in the specified portion of the input array, or 0 if the designated subarray is empty.

Throws MathIllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the sum of the values or 0 if length = 0

Annotations
@Override
Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
evaluateback to summary
public double evaluate(final double[] values, final double[] weights, final int begin, final int length) throws MathIllegalArgumentException

The weighted sum of the entries in the specified portion of the input array, or 0 if the designated subarray is empty.

Throws MathIllegalArgumentException if any of the following are true:

  • the values array is null
  • the weights array is null
  • the weights array does not have the same length as the values array
  • the weights array contains one or more infinite values
  • the weights array contains one or more NaN values
  • the weights array contains negative values
  • the start and length arguments do not determine a valid array

Uses the formula,

   weighted sum = Σ(values[i] * weights[i])

Parameters
values:double[]

the input array

weights:double[]

the weights array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the sum of the values or 0 if length = 0

Exceptions
MathIllegalArgumentException:
if the parameters are not valid
Since
2.1
evaluateback to summary
public double evaluate(final double[] values, final double[] weights) throws MathIllegalArgumentException

The weighted sum of the entries in the the input array.

Throws MathIllegalArgumentException if any of the following are true:

  • the values array is null
  • the weights array is null
  • the weights array does not have the same length as the values array
  • the weights array contains one or more infinite values
  • the weights array contains one or more NaN values
  • the weights array contains negative values

Uses the formula,

   weighted sum = Σ(values[i] * weights[i])

Parameters
values:double[]

the input array

weights:double[]

the weights array

Returns:double

the sum of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the parameters are not valid
Since
2.1
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
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