gov.sandia.cognition.statistics.distribution
Class DefaultDataDistribution<KeyType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.collection.AbstractScalarMap<KeyType>
          extended by gov.sandia.cognition.collection.AbstractMutableDoubleMap<KeyType>
              extended by gov.sandia.cognition.statistics.AbstractDataDistribution<KeyType>
                  extended by gov.sandia.cognition.statistics.distribution.DefaultDataDistribution<KeyType>
Type Parameters:
KeyType - Type of Key in the distribution
All Implemented Interfaces:
NumericMap<KeyType>, ScalarMap<KeyType>, ComputableDistribution<KeyType>, DataDistribution<KeyType>, DiscreteDistribution<KeyType>, Distribution<KeyType>, EstimableDistribution<KeyType,DataDistribution<KeyType>>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
DataCountTreeSetBinnedMapHistogram, DefaultDataDistribution.PMF, ScalarDataDistribution

public class DefaultDataDistribution<KeyType>
extends AbstractDataDistribution<KeyType>

A default implementation of ScalarDataDistribution that uses a backing map.

Since:
3.1.2
Author:
Justin Basilico
See Also:
Serialized Form

Nested Class Summary
static class DefaultDataDistribution.DefaultFactory<DataType>
          A factory for DefaultDataDistribution objects using some given initial capacity for them.
static class DefaultDataDistribution.Estimator<KeyType>
          Estimator for a DefaultDataDistribution
static class DefaultDataDistribution.PMF<KeyType>
          PMF of the DefaultDataDistribution
static class DefaultDataDistribution.WeightedEstimator<KeyType>
          A weighted estimator for a DefaultDataDistribution
 
Nested classes/interfaces inherited from class gov.sandia.cognition.collection.AbstractMutableDoubleMap
AbstractMutableDoubleMap.SimpleEntry<KeyType>, AbstractMutableDoubleMap.SimpleEntrySet<KeyType>, AbstractMutableDoubleMap.SimpleIterator<KeyType>
 
Nested classes/interfaces inherited from class gov.sandia.cognition.collection.AbstractScalarMap
AbstractScalarMap.MapWrapper
 
Nested classes/interfaces inherited from interface gov.sandia.cognition.collection.ScalarMap
ScalarMap.Entry<KeyType>
 
Field Summary
static int DEFAULT_INITIAL_CAPACITY
          Default initial capacity, 10.
protected  double total
          Total of the counts in the distribution
 
Fields inherited from class gov.sandia.cognition.collection.AbstractMutableDoubleMap
map
 
Constructor Summary
  DefaultDataDistribution()
          Default constructor
  DefaultDataDistribution(DataDistribution<? extends KeyType> other)
          Creates a new instance of DefaultDataDistribution
  DefaultDataDistribution(int initialCapacity)
          Creates a new instance of DefaultDataDistribution
  DefaultDataDistribution(Iterable<? extends KeyType> data)
          Creates a new instance of ScalarDataDistribution
protected DefaultDataDistribution(Map<KeyType,MutableDouble> map, double total)
          Creates a new instance of
 
Method Summary
 void clear()
          Removes all elements from the map.
 DefaultDataDistribution<KeyType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 DistributionEstimator<KeyType,? extends DataDistribution<KeyType>> getEstimator()
          Gets an estimator associated with this distribution.
 double getMeanValue()
          Gets the average value of all keys in the distribution, that is, the total value divided by the number of keys (even zero-value keys)
 DataDistribution.PMF<KeyType> getProbabilityFunction()
          Gets the distribution function associated with this Distribution, either the PDF or PMF.
 double getTotal()
          Gets the total (sum) of the values in the distribution.
 double increment(KeyType key, double value)
          Increments the value associated with the given key by the given amount.
 void set(KeyType key, double value)
          Sets the value associated with a given key.
 
Methods inherited from class gov.sandia.cognition.statistics.AbstractDataDistribution
fromInfiniteVector, getDomain, getDomainSize, getEntropy, getFraction, getLogFraction, getMaxValue, getMinValue, sample, sample, toInfiniteVector
 
Methods inherited from class gov.sandia.cognition.collection.AbstractMutableDoubleMap
asMap, compact, containsKey, entrySet, get, keySet, size
 
Methods inherited from class gov.sandia.cognition.collection.AbstractScalarMap
decrement, decrement, decrementAll, decrementAll, getMaxValueKey, getMaxValueKeys, getMinValueKey, getMinValueKeys, increment, incrementAll, incrementAll, isEmpty, setAll
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.collection.ScalarMap
asMap, decrement, decrement, decrementAll, decrementAll, entrySet, get, increment, incrementAll, incrementAll, setAll
 
Methods inherited from interface gov.sandia.cognition.collection.NumericMap
containsKey, getMaxValueKey, getMaxValueKeys, getMinValueKey, getMinValueKeys, isEmpty, keySet, size
 

Field Detail

DEFAULT_INITIAL_CAPACITY

public static final int DEFAULT_INITIAL_CAPACITY
Default initial capacity, 10.

See Also:
Constant Field Values

total

protected double total
Total of the counts in the distribution

Constructor Detail

DefaultDataDistribution

public DefaultDataDistribution()
Default constructor


DefaultDataDistribution

public DefaultDataDistribution(int initialCapacity)
Creates a new instance of DefaultDataDistribution

Parameters:
initialCapacity - Initial capacity of the Map

DefaultDataDistribution

public DefaultDataDistribution(DataDistribution<? extends KeyType> other)
Creates a new instance of DefaultDataDistribution

Parameters:
other - DataDistribution to copy

DefaultDataDistribution

public DefaultDataDistribution(Iterable<? extends KeyType> data)
Creates a new instance of ScalarDataDistribution

Parameters:
data - Data to create the distribution

DefaultDataDistribution

protected DefaultDataDistribution(Map<KeyType,MutableDouble> map,
                                  double total)
Creates a new instance of

Parameters:
map - Backing Map that stores the data
total - Sum of all values in the Map
Method Detail

clone

public DefaultDataDistribution<KeyType> clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface DataDistribution<KeyType>
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractDataDistribution<KeyType>
Returns:
A clone of this object.

increment

public double increment(KeyType key,
                        double value)
Description copied from interface: ScalarMap
Increments the value associated with the given key by the given amount.

Specified by:
increment in interface ScalarMap<KeyType>
Overrides:
increment in class AbstractMutableDoubleMap<KeyType>
Parameters:
key - A key.
value - The amount to increment the value associated with the given key by.
Returns:
The new value associated with the key.

set

public void set(KeyType key,
                double value)
Description copied from interface: ScalarMap
Sets the value associated with a given key. In some cases if the value is 0.0, the key may be removed from the map.

Specified by:
set in interface ScalarMap<KeyType>
Overrides:
set in class AbstractMutableDoubleMap<KeyType>
Parameters:
key - A key.
value - The value to associate with the key.

getTotal

public double getTotal()
Description copied from interface: DataDistribution
Gets the total (sum) of the values in the distribution.

Returns:
The sum of the values in the distribution.

clear

public void clear()
Description copied from interface: NumericMap
Removes all elements from the map.

Specified by:
clear in interface NumericMap<KeyType>
Overrides:
clear in class AbstractMutableDoubleMap<KeyType>

getEstimator

public DistributionEstimator<KeyType,? extends DataDistribution<KeyType>> getEstimator()
Description copied from interface: EstimableDistribution
Gets an estimator associated with this distribution.

Returns:
A distribution estimator associated for this distribution.

getProbabilityFunction

public DataDistribution.PMF<KeyType> getProbabilityFunction()
Description copied from interface: ComputableDistribution
Gets the distribution function associated with this Distribution, either the PDF or PMF.

Returns:
Distribution function associated with this Distribution.

getMeanValue

public double getMeanValue()
Gets the average value of all keys in the distribution, that is, the total value divided by the number of keys (even zero-value keys)

Returns:
Average value of all keys in the distribution