gov.sandia.cognition.statistics
Class AbstractDataDistribution<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>
Type Parameters:
KeyType - The type of data stored at the indices, the hash keys.
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:
DefaultDataDistribution

public abstract class AbstractDataDistribution<KeyType>
extends AbstractMutableDoubleMap<KeyType>
implements DataDistribution<KeyType>

An abstract implementation of the DataDistribution interface.

Since:
3.3.0
Author:
Justin Basilico, Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
 
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.statistics.DataDistribution
DataDistribution.PMF<KeyType>
 
Nested classes/interfaces inherited from interface gov.sandia.cognition.collection.ScalarMap
ScalarMap.Entry<KeyType>
 
Field Summary
 
Fields inherited from class gov.sandia.cognition.collection.AbstractMutableDoubleMap
map
 
Constructor Summary
AbstractDataDistribution(Map<KeyType,MutableDouble> map)
          Creates a new AbstractDataDistribution.
 
Method Summary
 AbstractDataDistribution<KeyType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 void fromInfiniteVector(InfiniteVector<? extends KeyType> vector)
          Replaces the entries in this data distribution with the entries in the given infinite vector.
 Set<KeyType> getDomain()
          Returns an object that allows an iteration through the domain (x-axis, independent variable) of the Distribution
 int getDomainSize()
          Gets the size of the domain.
 double getEntropy()
          Computes the information-theoretic entropy of the vector in bits.
 double getFraction(KeyType key)
          Gets the fraction of the counts represented by the given key.
 double getLogFraction(KeyType key)
          Gets the natural logarithm of the fraction of the counts represented by the given key.
 double getMaxValue()
          The maximum value associated with any key in the map.
 double getMinValue()
          The minimum value associated with any key in the map.
 KeyType sample(Random random)
          Draws a single random sample from the distribution.
 ArrayList<KeyType> sample(Random random, int numSamples)
          Draws multiple random samples from the distribution.
 InfiniteVector<KeyType> toInfiniteVector()
          Converts this data distribution to an infinite vector.
 
Methods inherited from class gov.sandia.cognition.collection.AbstractMutableDoubleMap
asMap, clear, compact, containsKey, entrySet, get, increment, keySet, set, 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.statistics.DataDistribution
getEstimator, getProbabilityFunction, getTotal
 
Methods inherited from interface gov.sandia.cognition.collection.ScalarMap
asMap, decrement, decrement, decrementAll, decrementAll, entrySet, get, increment, increment, incrementAll, incrementAll, set, setAll
 
Methods inherited from interface gov.sandia.cognition.collection.NumericMap
clear, containsKey, getMaxValueKey, getMaxValueKeys, getMinValueKey, getMinValueKeys, isEmpty, keySet, size
 

Constructor Detail

AbstractDataDistribution

public AbstractDataDistribution(Map<KeyType,MutableDouble> map)
Creates a new AbstractDataDistribution.

Parameters:
map - Map that stores the data
Method Detail

clone

public AbstractDataDistribution<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 AbstractMutableDoubleMap<KeyType>
Returns:
A clone of this object.

getDomainSize

public int getDomainSize()
Description copied from interface: DiscreteDistribution
Gets the size of the domain.

Specified by:
getDomainSize in interface DiscreteDistribution<KeyType>
Returns:
The size of the domain.

getEntropy

public double getEntropy()
Description copied from interface: DataDistribution
Computes the information-theoretic entropy of the vector in bits.

Specified by:
getEntropy in interface DataDistribution<KeyType>
Returns:
Entropy in bits of the distribution.

getLogFraction

public double getLogFraction(KeyType key)
Description copied from interface: DataDistribution
Gets the natural logarithm of the fraction of the counts represented by the given key.

Specified by:
getLogFraction in interface DataDistribution<KeyType>
Parameters:
key - Key to consider
Returns:
Natural logarithm of the fraction of the counts represented by the key

getFraction

public double getFraction(KeyType key)
Description copied from interface: DataDistribution
Gets the fraction of the counts represented by the given key.

Specified by:
getFraction in interface DataDistribution<KeyType>
Parameters:
key - The key.
Returns:
The fraction of the total count represented by the key, if it exists. Otherwise, 0.0.

sample

public KeyType sample(Random random)
Description copied from interface: Distribution
Draws a single random sample from the distribution.

Specified by:
sample in interface Distribution<KeyType>
Parameters:
random - Random-number generator to use in order to generate random numbers.
Returns:
Sample drawn according to this distribution.

sample

public ArrayList<KeyType> sample(Random random,
                                 int numSamples)
Description copied from interface: Distribution
Draws multiple random samples from the distribution. It is generally more efficient to use this multiple-sample method than multiple calls of the single-sample method. (But not always.)

Specified by:
sample in interface Distribution<KeyType>
Parameters:
random - Random-number generator to use in order to generate random numbers.
numSamples - Number of samples to draw from the distribution.
Returns:
Samples drawn according to this distribution.

toInfiniteVector

public InfiniteVector<KeyType> toInfiniteVector()
Description copied from interface: DataDistribution
Converts this data distribution to an infinite vector.

Specified by:
toInfiniteVector in interface DataDistribution<KeyType>
Returns:
A new InfiniteVector with values from this data distribution.

fromInfiniteVector

public void fromInfiniteVector(InfiniteVector<? extends KeyType> vector)
Description copied from interface: DataDistribution
Replaces the entries in this data distribution with the entries in the given infinite vector.

Specified by:
fromInfiniteVector in interface DataDistribution<KeyType>
Parameters:
vector - The infinite vector to use to populate this data distribution.

getMaxValue

public double getMaxValue()
Description copied from interface: ScalarMap
The maximum value associated with any key in the map.

Specified by:
getMaxValue in interface ScalarMap<KeyType>
Overrides:
getMaxValue in class AbstractScalarMap<KeyType>
Returns:
The maximum value associated with any key in the map. If the map is empty, then Double.NEGATIVE_INFINITY is returned.

getMinValue

public double getMinValue()
Description copied from interface: ScalarMap
The minimum value associated with any key in the map.

Specified by:
getMinValue in interface ScalarMap<KeyType>
Overrides:
getMinValue in class AbstractScalarMap<KeyType>
Returns:
The minimum value associated with any key in the map. If the map is empty, then Double.POSITIVE_INFINITY is returned.

getDomain

public Set<KeyType> getDomain()
Description copied from interface: DiscreteDistribution
Returns an object that allows an iteration through the domain (x-axis, independent variable) of the Distribution

Specified by:
getDomain in interface DiscreteDistribution<KeyType>
Returns:
Collection that enumerates each value that the domain can take