Class Distribution

java.lang.Object
  extended by Distribution

public class Distribution
extends java.lang.Object

For a given attribute, a Distribution object stores information about a probability distribution over the possible attribute values in two different ways: (i) frequencies -- how many times each attribute value was observed, and (ii) probabilities -- the probability that this attribute has each of the possible attribute values. A method is provided for translating frequencies into normalized probabilities.

Author:
jmac

Constructor Summary
Distribution(Attribute attribute)
          Create a distribution on the values of a particular attribute
 
Method Summary
 void computeProbabilitiesFromFrequencies()
          Take the observed frequencies and create normalized probabilities from them, which can later be obtained using getProbabilities().
 double getEntropy()
          Get the entropy of the probability distribution.
 java.lang.String getNameOfMaxFrequency()
          Get the name of the most frequently-observed attribute value.
 java.lang.String getNameOfMaxProbability()
          Get the name of the most probable attribute value.
 java.util.HashMap<java.lang.String,java.lang.Double> getProbabilities()
          Get a HashMap of the probabilities in this distribution.
 int getTotalFrequencies()
          Get the total number of observations.
 int getValueOfMaxFrequency()
          Get the number of times the most frequently-observed value was observed.
 double getValueOfMaxProbability()
          Get the probability of the most probable attribute value.
 void incrementFrequency(java.lang.String attributeValue)
          Increment the observed frequency of the given value by 1.
 void printFrequencies()
          Print out the table of observed frequencies.
 void printProbabilities()
          Print out the table of probabilities.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Distribution

public Distribution(Attribute attribute)
Create a distribution on the values of a particular attribute

Parameters:
attribute - the attribute whose distribution this object records
Method Detail

incrementFrequency

public void incrementFrequency(java.lang.String attributeValue)
Increment the observed frequency of the given value by 1.

Parameters:
attributeValue - the attribute value whose frequency will be incremented by 1

getNameOfMaxFrequency

public java.lang.String getNameOfMaxFrequency()
Get the name of the most frequently-observed attribute value.

Returns:
the name of the most frequent attribute value

getValueOfMaxFrequency

public int getValueOfMaxFrequency()
Get the number of times the most frequently-observed value was observed.

Returns:
the frequency of the most frequent attribute value

getNameOfMaxProbability

public java.lang.String getNameOfMaxProbability()
                                         throws DecisionTreeException
Get the name of the most probable attribute value.

Returns:
the name of the most probable attribute value
Throws:
DecisionTreeException - if the probabilities have not been computed via computeProbabilitiesFromFrequencies()

getValueOfMaxProbability

public double getValueOfMaxProbability()
                                throws DecisionTreeException
Get the probability of the most probable attribute value.

Returns:
the probability of the most probable attribute value
Throws:
DecisionTreeException - if the probabilities have not been computed via computeProbabilitiesFromFrequencies()

getTotalFrequencies

public int getTotalFrequencies()
Get the total number of observations.

Returns:
the total of all frequencies in this distribution (i.e. the total number of instances observed)

getEntropy

public double getEntropy()
                  throws DecisionTreeException
Get the entropy of the probability distribution.

Returns:
the entropy of the probability distribution
Throws:
DecisionTreeException - if the probabilities have not been computed via computeProbabilitiesFromFrequencies()

computeProbabilitiesFromFrequencies

public void computeProbabilitiesFromFrequencies()
                                         throws DecisionTreeException
Take the observed frequencies and create normalized probabilities from them, which can later be obtained using getProbabilities().

Throws:
DecisionTreeException

printFrequencies

public void printFrequencies()
Print out the table of observed frequencies.


printProbabilities

public void printProbabilities()
                        throws DecisionTreeException
Print out the table of probabilities.

Throws:
DecisionTreeException

getProbabilities

public java.util.HashMap<java.lang.String,java.lang.Double> getProbabilities()
                                                                      throws DecisionTreeException
Get a HashMap of the probabilities in this distribution.

Returns:
a HashMap of the probabilities; the key is the attribute value, and the corresponding value is its probability
Throws:
DecisionTreeException