net.sf.jdmf.util
Class MathCalculator

java.lang.Object
  extended by net.sf.jdmf.util.MathCalculator

public class MathCalculator
extends java.lang.Object

A utility class that simplifies some calculations required in data mining algorithms, e.g. Bayes Classifier.

Author:
quorthon

Constructor Summary
MathCalculator()
           
 
Method Summary
 java.util.Vector<java.lang.Double> calculateCentroid(java.util.List<java.util.Vector<java.lang.Double>> points)
          Calculates the centroid of all given points in a nD space (assumes that all points have n coordinates).
 java.lang.Double calculateDistance(java.util.Vector<java.lang.Double> firstPoint, java.util.Vector<java.lang.Double> secondPoint)
          Calculates the distance between two points in a nD space (assumes that n = firstPoint.size() = secondPoint.size()).
 java.lang.Double calculateMean(java.lang.Comparable[] attributeValues)
          Calculates the mean of all attribute values.
 java.lang.Double calculateNormalDistribution(java.lang.Comparable[] attributeValues, java.lang.Double x)
          Calculates the normal distribution for the attribute value of the instance being classified.
 java.lang.Double calculateStandardDeviation(java.lang.Comparable[] attributeValues, java.lang.Double mean)
          Calculates the standard deviation of all attribute values.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MathCalculator

public MathCalculator()
Method Detail

calculateNormalDistribution

public java.lang.Double calculateNormalDistribution(java.lang.Comparable[] attributeValues,
                                                    java.lang.Double x)
Calculates the normal distribution for the attribute value of the instance being classified. Uses all known values of this attribute to calculate the mean and standard deviation. The probability density function used:
              1            ( -(x-m)^2 )
 f(x) = ------------- * exp( -------- )
        sd*sqrt(2*PI)      ( 2*(sd)^2 )
 
m - mean, sd - standard deviation

Parameters:
attributeValues - all values of the attribute (for m and sd)
x - the attribute value of the instance being classified
Returns:
the normal distribution for x

calculateMean

public java.lang.Double calculateMean(java.lang.Comparable[] attributeValues)
Calculates the mean of all attribute values.

Parameters:
attributeValues - attribute values
Returns:
the mean

calculateStandardDeviation

public java.lang.Double calculateStandardDeviation(java.lang.Comparable[] attributeValues,
                                                   java.lang.Double mean)
Calculates the standard deviation of all attribute values.

Parameters:
attributeValues - attribute values
Returns:
the standard deviation

calculateDistance

public java.lang.Double calculateDistance(java.util.Vector<java.lang.Double> firstPoint,
                                          java.util.Vector<java.lang.Double> secondPoint)
Calculates the distance between two points in a nD space (assumes that n = firstPoint.size() = secondPoint.size()).

Parameters:
firstPoint - the first point
secondPoint - the second point
Returns:
the distance between both points

calculateCentroid

public java.util.Vector<java.lang.Double> calculateCentroid(java.util.List<java.util.Vector<java.lang.Double>> points)
Calculates the centroid of all given points in a nD space (assumes that all points have n coordinates). Each coordinate of the centroid is a mean of all values of the same coordinate of each point.

Parameters:
points - all points
Returns:
the centroid of all given points