utilities
Class Distribution

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--utilities.Distribution
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.io.Serializable

public class Distribution
extends java.util.Vector

See Also:
Serialized Form

Constructor Summary
Distribution()
          Makes an empty distribution
Distribution(double Value, double Distribution)
          Makes a distribution with one entry
Distribution(float Value, float Distribution)
          Makes a distribution with one entry
Distribution(java.lang.Float Value, java.lang.Float Distribution)
          Makes a distribution with one entry
Distribution(java.lang.String str)
          Parses a string of the form "5 0.2 10 0.5 20 0.3" into a distribution object.
 
Method Summary
 Distribution appendDistribution(Distribution d)
          Appends a distribution to another one, no normalization
 void appendTerm(double v, double d)
          Appends a new term onto the distribution, no normalization
 void appendTerm(float v, float d)
          Appends a new term onto the distribution, no normalization
 void appendTerm(java.lang.Float v, java.lang.Float d)
          Appends a new term onto the distribution, no normalization
 Distribution applyDensity(float density)
          Apply a density weight to a Distribution.
 Distribution applyOffset(float offset)
          Apply a offset to the value of a Distribution.
 Distribution applyPower(float power)
          Apply a power to the value of a Distribution.
 float calculateAvg()
          Compute the average of a given Distribution
 float calculateDeviation()
          Standart deviation : Sum(f X^2)/ Sum(f) - X_bar^2 Easy computation....
 float calculateMax()
          calculateMax() method computes the maximal value from a Distribution instance.
 float calculateMin()
          calculateMin() method computes the minimal value, you can get from a distribution instance.
 float calculateMostLikely()
          Compute the most likely outcome of a given Distribution
 float calculateTotalDensity()
          Calculate the total density represented by the distribution.
 void cluster(int pointsNumber)
          Clusters the distribution by combining terms to reach at most a given number of points
 void compact()
          Compacts the distribution by combining like valued terms
 double compare(Distribution b)
          Statistic described in our AAAI paper to compare two distributions.
static Distribution computeDifferenceJointDistribution(Distribution d1, Distribution d2)
           
static Distribution computeDifferenceJointDistribution(java.util.Vector v)
          Computes the overall joint probability for a vector of distributions.
static Distribution computeJointDistribution(Distribution d1, Distribution d2)
           
static Distribution computeJointDistribution(java.util.Vector v)
          Computes the overall joint probability for a vector of distributions.
static Distribution computeMaxJointDistribution(Distribution d1, Distribution d2)
           
static Distribution computeMaxJointDistribution(java.util.Vector v)
          Computes the overall joint probability for a vector of distributions.
static Distribution computeMinJointDistribution(Distribution d1, Distribution d2)
           
static Distribution computeMinJointDistribution(java.util.Vector v)
          Computes the overall joint probability for a vector of distributions.
 boolean containsValue(float v, float t)
          Determines if the value is contained in the Distribution
 boolean equals(Distribution d)
          This algorithm assumes no equal values (e.g.
 float findClosestValue(float v)
          Searches for the closest match to the supplied value in the distribution.
 float findValue(float v)
          Searches for the supplied value in the distribution
 float[] getArray()
          getArray method.
 java.util.Hashtable getHashtable()
          getHashtable, converts the Distribution is an hashtable where the pair is for as
 void normalize()
          Normalizes the probabilities to 1
 java.lang.String output()
          Stringify in a TTaemsy way
 void sort()
          Should be removed if nobody uses it.
 void sortByDistribution()
          Sort the distribution by frequency.
 void sortByValue()
          Sort the distribution by value.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Constructor Detail

Distribution

public Distribution()
Makes an empty distribution

Distribution

public Distribution(java.lang.Float Value,
                    java.lang.Float Distribution)
Makes a distribution with one entry

Distribution

public Distribution(float Value,
                    float Distribution)
Makes a distribution with one entry

Distribution

public Distribution(double Value,
                    double Distribution)
Makes a distribution with one entry

Distribution

public Distribution(java.lang.String str)
Parses a string of the form "5 0.2 10 0.5 20 0.3" into a distribution object. Will also trip leading and trailing parentheses if present.

This will crash if you feed it an incorrectly formatted string.

Parameters:
str - The string representation of the distribution
Method Detail

getArray

public float[] getArray()
getArray method. This method is used by the simulator to get the distribution in a float array. This method is called in the simulator.ExecuteEvent constructor.
Returns:
float [] array
See Also:
ExecuteEvent#ExecuteEvent(int, int, Agent, String, Distribution, Distribution, Distribution)

getHashtable

public java.util.Hashtable getHashtable()
getHashtable, converts the Distribution is an hashtable where the pair is for as
Returns:
a hashtable

findValue

public float findValue(float v)
Searches for the supplied value in the distribution
Parameters:
v - The value to look for
Returns:
The value's probability (0 if not found)

findClosestValue

public float findClosestValue(float v)
Searches for the closest match to the supplied value in the distribution. In case of a tie, the element with the greater probability is chosen.
Parameters:
v - The value to look for
Returns:
The value

containsValue

public boolean containsValue(float v,
                             float t)
Determines if the value is contained in the Distribution
Parameters:
v - The value to look for
t - The threshold (+/-) around each value to be considered a match
Returns:
True, if the value is contained

calculateMin

public float calculateMin()
calculateMin() method computes the minimal value, you can get from a distribution instance. Useful for the diagnostic component.

calculateMax

public float calculateMax()
calculateMax() method computes the maximal value from a Distribution instance.

calculateAvg

public float calculateAvg()
Compute the average of a given Distribution

calculateMostLikely

public float calculateMostLikely()
Compute the most likely outcome of a given Distribution

calculateDeviation

public float calculateDeviation()
Standart deviation : Sum(f X^2)/ Sum(f) - X_bar^2 Easy computation....

calculateTotalDensity

public float calculateTotalDensity()
Calculate the total density represented by the distribution.
Returns:
the total density Example:
[0.0, 0.1, 1.0, 0.2, 10.0, 0.3] = total density 0.6

applyDensity

public Distribution applyDensity(float density)
Apply a density weight to a Distribution. Changes are made to a clone, which is returned, the original is left unchanged.
Parameters:
density - Example:
Dc = [0.0, 1.0] Dd = [1.0, 0.5] Dq = [10.0, 0.5]
Applying a density of 0.5 give this result:
Dc = [0.0, 0.5] Dd = [1.0, 0.25] Dq = [10.0, 0.25]

applyPower

public Distribution applyPower(float power)
Apply a power to the value of a Distribution. Changes are made to a clone, which is returned, the original is left unchanged.
Parameters:
power - Example:
Dc = [0.0, 1.0] Dd = [1.0, 0.5] Dq = [10.0, 0.5]
Applying a power of 0.5 give this result:
Dc = [0.0, 1.0] Dd = [0.5, 0.5] Dq = [5.0, 0.5]

applyOffset

public Distribution applyOffset(float offset)
Apply a offset to the value of a Distribution. Changes are made to a clone, which is returned, the original is left unchanged.
Parameters:
offset - Example:
Dc = [0.0, 1.0] Dd = [1.0, 0.5] Dq = [10.0, 0.5]
Applying a power of 2.5 give this result:
Dc = [2.5, 1.0] Dd = [3.5, 0.5] Dq = [12.5, 0.5]

appendTerm

public void appendTerm(java.lang.Float v,
                       java.lang.Float d)
Appends a new term onto the distribution, no normalization

appendTerm

public void appendTerm(float v,
                       float d)
Appends a new term onto the distribution, no normalization

appendTerm

public void appendTerm(double v,
                       double d)
Appends a new term onto the distribution, no normalization

appendDistribution

public Distribution appendDistribution(Distribution d)
Appends a distribution to another one, no normalization

computeJointDistribution

public static Distribution computeJointDistribution(java.util.Vector v)
Computes the overall joint probability for a vector of distributions. Values are summed and compacted.

computeJointDistribution

public static Distribution computeJointDistribution(Distribution d1,
                                                    Distribution d2)

computeDifferenceJointDistribution

public static Distribution computeDifferenceJointDistribution(java.util.Vector v)
Computes the overall joint probability for a vector of distributions. Values are differenced and compacted.

computeDifferenceJointDistribution

public static Distribution computeDifferenceJointDistribution(Distribution d1,
                                                              Distribution d2)

computeMaxJointDistribution

public static Distribution computeMaxJointDistribution(java.util.Vector v)
Computes the overall joint probability for a vector of distributions. Values are maxed and compacted.

computeMaxJointDistribution

public static Distribution computeMaxJointDistribution(Distribution d1,
                                                       Distribution d2)

computeMinJointDistribution

public static Distribution computeMinJointDistribution(java.util.Vector v)
Computes the overall joint probability for a vector of distributions. Values are maxed and compacted.

computeMinJointDistribution

public static Distribution computeMinJointDistribution(Distribution d1,
                                                       Distribution d2)

compact

public void compact()
Compacts the distribution by combining like valued terms

normalize

public void normalize()
Normalizes the probabilities to 1

cluster

public void cluster(int pointsNumber)
Clusters the distribution by combining terms to reach at most a given number of points

sort

public void sort()
Should be removed if nobody uses it. Was used in compare().

sortByValue

public void sortByValue()
Sort the distribution by value. I'm not sure anyone will use this but I need it to compare 2 Distributions

sortByDistribution

public void sortByDistribution()
Sort the distribution by frequency. I'm not sure anyone will use this either but I need it for the cluster() method.

equals

public boolean equals(Distribution d)
This algorithm assumes no equal values (e.g. they're compacted)

compare

public double compare(Distribution b)
Statistic described in our AAAI paper to compare two distributions. It's based on the difference of area between the cumulative probability plots of the distributions.
Returns:
a value significatif depending of the errors between two Distributions

output

public java.lang.String output()
Stringify in a TTaemsy way