classifiers.usm.distance
Class USMStringDistance

java.lang.Object
  |
  +--coreComponents.DistanceMetric
        |
        +--classifiers.usm.distance.USMDistanceFunction
              |
              +--classifiers.usm.distance.USMStringDistance
All Implemented Interfaces:
java.io.Serializable

public class USMStringDistance
extends USMDistanceFunction

Class to implement Vitanyi's wonderful Universal Similarity Metric (USM) distance function for simple strings! Does exactly what it says on the tin.

Version:
$Version: 1.0$
Author:
David Lindsay (davidl@cs.rhul.ac.uk)
See Also:
Serialized Form

Constructor Summary
USMStringDistance(Instances data)
          Simple constructor, just initialise with the data that is being used to check that it is in the correct format!
 
Method Summary
 USMComplexityCache calculateComplexityAndComplexityStarOf(Instance x, Attribute a)
          Calculates the first K(x) and second order K(x*) complexities of an object x
 double calculateConcatenatedComplexityOf(Instance x, Instance y, USMComplexityCache usmcc)
          Calculates the first K(xy*) complexity of an object x with a compressed object y*
 boolean checkInstance(Instance i)
          Function to check that an individual instance is of the correct format.
 boolean checkInstances(Instances is)
          Function to check that the data instances are in the correct format.
 byte[] compressBytes(byte[] input)
          Simple function for compressing an array of bytes into another array of bytes!
static void main(java.lang.String[] args)
          Test class for the object!
 
Methods inherited from class classifiers.usm.distance.USMDistanceFunction
calculateUSM, definePrefix, distance, findAttributesWithPrefix, findInstanceInCache, returnInstanceCache, toString, updateInstanceCache
 
Methods inherited from class coreComponents.DistanceMetric
forName, reset, updateRanges
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

USMStringDistance

public USMStringDistance(Instances data)
Simple constructor, just initialise with the data that is being used to check that it is in the correct format!

Parameters:
data - the Instance format to be initialised
Method Detail

checkInstances

public boolean checkInstances(Instances is)
                       throws java.lang.Exception
Function to check that the data instances are in the correct format.

Specified by:
checkInstances in class USMDistanceFunction
Parameters:
is - the instances to be checked
Returns:
true if the Instances are in the correct format for this distance function, else false
java.lang.Exception

checkInstance

public boolean checkInstance(Instance i)
                      throws java.lang.Exception
Function to check that an individual instance is of the correct format. This may be a little inefficient with lots of distance calculations.

Specified by:
checkInstance in class USMDistanceFunction
Parameters:
i - the instance to be checked
Returns:
true if the instance has the same fromat as initially set, else false
java.lang.Exception

calculateComplexityAndComplexityStarOf

public USMComplexityCache calculateComplexityAndComplexityStarOf(Instance x,
                                                                 Attribute a)
Calculates the first K(x) and second order K(x*) complexities of an object x

Specified by:
calculateComplexityAndComplexityStarOf in class USMDistanceFunction
Parameters:
x - the instance to calculate the complexities for
Returns:
the complexitys in a paired array [ K(x) , K(x*) ]

calculateConcatenatedComplexityOf

public double calculateConcatenatedComplexityOf(Instance x,
                                                Instance y,
                                                USMComplexityCache usmcc)
Calculates the first K(xy*) complexity of an object x with a compressed object y*

Specified by:
calculateConcatenatedComplexityOf in class USMDistanceFunction
Parameters:
x - the instance to use
y - the instance to use the compression of
Returns:
the complexitys of the concatenated string xy (not with a comma!)

compressBytes

public byte[] compressBytes(byte[] input)
Simple function for compressing an array of bytes into another array of bytes!

Parameters:
input - byte array to be compressed
Returns:
the compressed version of the byte array

main

public static void main(java.lang.String[] args)
Test class for the object!



Copyright (c) 2003 David Lindsay, Computer Learning Research Centre, Dept. Computer Science, Royal Holloway, University of London