weka.core
Class DistanceFunction

java.lang.Object
  extended byweka.core.DistanceFunction
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
EuclideanDistance

public abstract class DistanceFunction
extends java.lang.Object
implements java.io.Serializable

Abstract class to implement a distance function.

See Also:
Serialized Form

Field Summary
protected  Instances m_Model
          the data model
 double[][] m_Ranges
          the range of the attributes
protected static int R_MAX
           
protected static int R_MIN
          Index in ranges for MIN and MAX and WIDTH
protected static int R_WIDTH
           
 
Constructor Summary
DistanceFunction()
          Constructs a distance function object.
DistanceFunction(Instances data)
          Constructs a distance function object.
DistanceFunction(Instances data, double[][] ranges)
          Constructs a distance function object.
 
Method Summary
abstract  void checkInstances()
          Checks the instances if compatibel with the distance function.
 int closestPoint(Instance instance, Instances allPoints, int[] pointList)
          Returns the index of the closest point to the current instance.
abstract  double distance(Instance first, Instance second)
          Calculates the distance (or similarity) between two instances.
abstract  double getMiddle(double[] ranges)
          Returns value in the middle of the two parameter values.
 java.lang.String toString()
          Converts a DistanceFunction object to a string
 void updateRanges(Instance instance)
          Update the ranges if a new instance comes.
abstract  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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Model

protected Instances m_Model
the data model


m_Ranges

public double[][] m_Ranges
the range of the attributes


R_MIN

protected static final int R_MIN
Index in ranges for MIN and MAX and WIDTH

See Also:
Constant Field Values

R_MAX

protected static final int R_MAX
See Also:
Constant Field Values

R_WIDTH

protected static final int R_WIDTH
See Also:
Constant Field Values
Constructor Detail

DistanceFunction

public DistanceFunction()
Constructs a distance function object.


DistanceFunction

public DistanceFunction(Instances data)
Constructs a distance function object.

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

DistanceFunction

public DistanceFunction(Instances data,
                        double[][] ranges)
Constructs a distance function 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
Method Detail

distance

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

Parameters:
first - the first instance
second - the second instance
Returns:
the distance between the two given instances,
Throws:
java.lang.Exception

getMiddle

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

Returns:
the middle value

checkInstances

public abstract void checkInstances()
                             throws java.lang.Exception
Checks the instances if compatibel with the distance function.

Returns:
the middle value
Throws:
java.lang.Exception

valueIsSmallerEqual

public abstract 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.

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

closestPoint

public int closestPoint(Instance instance,
                        Instances allPoints,
                        int[] pointList)
                 throws java.lang.Exception
Returns the index of the closest point to the current instance. Index is index in Instances object that is the second parameter.

Parameters:
instance - the instance to assign a cluster to
Returns:
a cluster index
Throws:
java.lang.Exception

updateRanges

public void updateRanges(Instance instance)
Update the ranges if a new instance comes.

Parameters:
instance - the new instance

toString

public java.lang.String toString()
Converts a DistanceFunction object to a string

Returns:
a string describing a distance function