edu.georgetown.gucs.clustering
Class CosineSimilarity

java.lang.Object
  extended by weka.core.NormalizableDistance
      extended by edu.georgetown.gucs.clustering.CosineSimilarity
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, weka.core.DistanceFunction, weka.core.OptionHandler, weka.core.RevisionHandler

public class CosineSimilarity
extends weka.core.NormalizableDistance
implements java.lang.Cloneable

Class for computing the cosine similarity between two instances.

Version:
$Date$, $Revision$
Author:
Mark Maloof (maloof@cs.georgetown.edu)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class weka.core.NormalizableDistance
m_ActiveIndices, m_AttributeIndices, m_Data, m_DontNormalize, m_Ranges, m_Validated, R_MAX, R_MIN, R_WIDTH
 
Constructor Summary
CosineSimilarity()
          Default constructor.
CosineSimilarity(weka.core.Instances instances)
          Explicit constructor.
 
Method Summary
 double distance(weka.core.Instance first, weka.core.Instance second)
          Calculates the cosine similarity between two instances.
 java.lang.String getRevision()
           
 java.lang.String globalInfo()
           
static void main(java.lang.String[] args)
          A main method for testing and illustration.
protected  double updateDistance(double currDist, double diff)
          Updates the current distance calculated so far with the new difference between two attributes.
 
Methods inherited from class weka.core.NormalizableDistance
attributeIndicesTipText, difference, distance, distance, distance, dontNormalizeTipText, getAttributeIndices, getDontNormalize, getInstances, getInvertSelection, getOptions, getRanges, initialize, initializeAttributeIndices, initializeRanges, initializeRanges, initializeRanges, initializeRangesEmpty, inRanges, invalidate, invertSelectionTipText, listOptions, norm, postProcessDistances, rangesSet, setAttributeIndices, setDontNormalize, setInstances, setInvertSelection, setOptions, toString, update, updateRanges, updateRanges, updateRanges, updateRangesFirst, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CosineSimilarity

public CosineSimilarity()
Default constructor. Constructs a Cosine Similarity object. Instances must be still set.


CosineSimilarity

public CosineSimilarity(weka.core.Instances instances)
Explicit constructor. Constructs an Cosine Similarity object and initializes the ranges.

Parameters:
instances - the instances the distance function should work on
Method Detail

distance

public double distance(weka.core.Instance first,
                       weka.core.Instance second)
Calculates the cosine similarity between two instances.

Specified by:
distance in interface weka.core.DistanceFunction
Overrides:
distance in class weka.core.NormalizableDistance
Parameters:
first - the first instance
second - the second instance
Returns:
the distance between the two specified instances

globalInfo

public java.lang.String globalInfo()
Specified by:
globalInfo in class weka.core.NormalizableDistance

getRevision

public java.lang.String getRevision()
Specified by:
getRevision in interface weka.core.RevisionHandler

updateDistance

protected double updateDistance(double currDist,
                                double diff)
Updates the current distance calculated so far with the new difference between two attributes. The difference between the attributes was calculated with the difference(int,double,double) method.

Specified by:
updateDistance in class weka.core.NormalizableDistance
Parameters:
currDist - the current distance calculated so far
diff - the difference between two new attributes
Returns:
the update distance
See Also:
NormalizableDistance.difference(int, double, double)

main

public static void main(java.lang.String[] args)
A main method for testing and illustration.