gov.sandia.cognition.math
Class WeightedNumberAverager

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.math.WeightedNumberAverager
All Implemented Interfaces:
CloneableSerializable, Summarizer<WeightedValue<? extends Number>,Double>, Serializable, Cloneable

public class WeightedNumberAverager
extends AbstractCloneableSerializable
implements Summarizer<WeightedValue<? extends Number>,Double>

Averages together given set of weighted values by adding up the weight times the value and then dividing by the total weight. If the total weight is zero then zero is returned.

Since:
3.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Field Summary
static WeightedNumberAverager INSTANCE
          Instance of WeightedNumberAverager, since it has no state.
 
Constructor Summary
WeightedNumberAverager()
          Creates a new WeightedNumberAverager
 
Method Summary
 Double summarize(Collection<? extends WeightedValue<? extends Number>> data)
          Creates a summary of the given collection of data.
static double weightedAverage(Iterable<? extends WeightedValue<? extends Number>> data)
          Computes the weighted average of the given data.
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final WeightedNumberAverager INSTANCE
Instance of WeightedNumberAverager, since it has no state.

Constructor Detail

WeightedNumberAverager

public WeightedNumberAverager()
Creates a new WeightedNumberAverager

Method Detail

summarize

public Double summarize(Collection<? extends WeightedValue<? extends Number>> data)
Description copied from interface: Summarizer
Creates a summary of the given collection of data.

Specified by:
summarize in interface Summarizer<WeightedValue<? extends Number>,Double>
Parameters:
data - The collection of data to summarize.
Returns:
The summary of the data.

weightedAverage

public static double weightedAverage(Iterable<? extends WeightedValue<? extends Number>> data)
Computes the weighted average of the given data. It is computed by summing each value times its associated weight and then dividing by the sum of all weights.

Parameters:
data - The collection of weighted values of numbers to compute the weighted average over.
Returns:
The weighted average of the given data. It is 0.0 if the sum of the weights is 0.0.