weka.core
Class EuclideanDistance

java.lang.Object
  extended byweka.core.DistanceFunction
      extended byweka.core.EuclideanDistance
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class EuclideanDistance
extends DistanceFunction
implements java.lang.Cloneable, java.io.Serializable

Implementing Euclidean distance (or similarity) function. One object defines not one distance but the data model in which the distances between objects of that data model can be computed. Attention: For efficiency reasons the use of consistency checks (like are the data models of the two instances exactly the same), is low.

See Also:
Serialized Form

Field Summary
protected  boolean m_Normalize
          True if normalization should be done
protected  double m_NumAttributesUsed
          The number of attributes the contribute to a prediction
 
Fields inherited from class weka.core.DistanceFunction
m_Model, m_Ranges, R_MAX, R_MIN, R_WIDTH
 
Constructor Summary
EuclideanDistance()
          Constructs an Euclidean Distance object.
EuclideanDistance(Instances data)
          Constructs an Euclidean Distance object.
EuclideanDistance(Instances data, boolean normalize)
          Constructs an Euclidean Distance object.
EuclideanDistance(Instances data, double[][] ranges)
          Constructs an Euclidean Distance object.
EuclideanDistance(Instances data, double[][] ranges, boolean normalize)
          Constructs an Euclidean Distance object.
 
Method Summary
 void checkInstances()
          Checks the instances.
 double distance(Instance first, Instance second)
          Calculates the distance (or similarity) between two instances.
 double getMiddle(double[] ranges)
          Returns value in the middle of the two parameter values.
static void main(java.lang.String[] args)
          Main method for testing this class.
 void setNumAttributesUsed()
          Computes and sets the number of attributes used.
 java.lang.String toString()
          Documents the content of an EuclideanDistance object in a string.
 boolean valueIsSmallerEqual(Instance instance, int dim, double value)
          Returns true if the value of the given dimension is smaller or equal the value to be compared with.
 
Methods inherited from class weka.core.DistanceFunction
closestPoint, updateRanges
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Normalize

protected boolean m_Normalize
True if normalization should be done


m_NumAttributesUsed

protected double m_NumAttributesUsed
The number of attributes the contribute to a prediction

Constructor Detail

EuclideanDistance

public EuclideanDistance()
Constructs an Euclidean Distance object.


EuclideanDistance

public EuclideanDistance(Instances data)
Constructs an Euclidean Distance object.

Parameters:
data - the instances the distance function should work on

EuclideanDistance

public EuclideanDistance(Instances data,
                         boolean normalize)
Constructs an Euclidean Distance object.

Parameters:
data - the instances the distance function should work on
normalize - if true normalization is done

EuclideanDistance

public EuclideanDistance(Instances data,
                         double[][] ranges)
Constructs an Euclidean Distance object. Ranges are already given.

Parameters:
data - the instances the distance function should work on
ranges - the min and max values of the attribute values

EuclideanDistance

public EuclideanDistance(Instances data,
                         double[][] ranges,
                         boolean normalize)
Constructs an Euclidean Distance object. Ranges are already given.

Parameters:
data - the instances the distance function should work on
ranges - the min and max values of the attribute values
normalize - if true normalization is done
Method Detail

setNumAttributesUsed

public void setNumAttributesUsed()
Computes and sets the number of attributes used.


distance

public double distance(Instance first,
                       Instance second)
                throws java.lang.Exception
Calculates the distance (or similarity) between two instances.

Specified by:
distance in class DistanceFunction
Parameters:
first - the first instance
second - the second instance
Returns:
the distance between the two given instances,
Throws:
java.lang.Exception

getMiddle

public double getMiddle(double[] ranges)
Returns value in the middle of the two parameter values.

Specified by:
getMiddle in class DistanceFunction
Returns:
the middle value

checkInstances

public void checkInstances()
                    throws java.lang.Exception
Checks the instances. Dataset should only contain nominal or stringumeric attributes.

Specified by:
checkInstances in class DistanceFunction
Returns:
the middle value
Throws:
java.lang.Exception

valueIsSmallerEqual

public boolean valueIsSmallerEqual(Instance instance,
                                   int dim,
                                   double value)
Returns true if the value of the given dimension is smaller or equal the value to be compared with.

Specified by:
valueIsSmallerEqual in class DistanceFunction
Parameters:
instance - the instance where the value should be taken of
dim - the dimension of the value
Returns:
true is value of instance is smaller or equal value

toString

public java.lang.String toString()
Documents the content of an EuclideanDistance object in a string.

Overrides:
toString in class DistanceFunction
Returns:
the converted string

main

public static void main(java.lang.String[] args)
Main method for testing this class.