weka.core

## Class MinkowskiDistance

- java.lang.Object
- - weka.core.NormalizableDistance
  - - weka.core.MinkowskiDistance

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DistanceFunction, OptionHandler, RevisionHandler, TechnicalInformationHandler

      public class MinkowskiDistance
      extends NormalizableDistance
      implements java.lang.Cloneable, TechnicalInformationHandler

  Implementing Minkowski 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.
  For more information, see:
  Wikipedia. Minkowski distance. URL http://en.wikipedia.org/wiki/Minkowski_distance.

  BibTeX:

       @misc{missing_id,
          author = {Wikipedia},
          title = {Minkowski distance},
          URL = {http://en.wikipedia.org/wiki/Minkowski_distance}
       }

  Valid options are:

       -P <order>
        The order 'p'. With '1' being the Manhattan distance and '2'
        the Euclidean distance.
        (default: 2)

       -D
        Turns off the normalization of attribute
        values in distance calculation.

       -R <col1,col2-col4,...>
        Specifies list of columns to used in the calculation of the
        distance. 'first' and 'last' are valid indices.
        (default: first-last)

       -V
        Invert matching sense of column indices.

  Version:
    $Revision: 10203 $
  Author:
    FracPete (fracpete at waikato dot ac dot nz)
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class weka.core.NormalizableDistance

      `R_MAX, R_MIN, R_WIDTH`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MinkowskiDistance()` Constructs an Minkowski Distance object, Instances must be still set.
    `MinkowskiDistance(Instances data)` Constructs an Minkowski Distance object and automatically initializes the ranges.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `distance(Instance first, Instance second)` Calculates the distance between two instances.
    `double` | `distance(Instance first, Instance second, PerformanceStats stats)` Calculates the distance (or similarity) between two instances.
    `java.lang.String[]` | `getOptions()` Gets the current settings of this object.
    `double` | `getOrder()` Gets the order.
    `java.lang.String` | `getRevision()` Returns the revision string.
    `TechnicalInformation` | `getTechnicalInformation()` Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
    `java.lang.String` | `globalInfo()` Returns a string describing this object.
    `java.util.Enumeration<Option>` | `listOptions()` Returns an enumeration describing the available options.
    `java.lang.String` | `orderTipText()` Returns the tip text for this property.
    `void` | `postProcessDistances(double[] distances)` Does post processing of the distances (if necessary) returned by distance(distance(Instance first, Instance second, double cutOffValue).
    `void` | `setOptions(java.lang.String[] options)` Parses a given list of options.
    `void` | `setOrder(double value)` Sets the order.

    - ### Methods inherited from class weka.core.NormalizableDistance

      `attributeIndicesTipText, clean, distance, distance, dontNormalizeTipText, getAttributeIndices, getDontNormalize, getInstances, getInvertSelection, getRanges, initializeRanges, initializeRanges, initializeRanges, initializeRangesEmpty, inRanges, invertSelectionTipText, rangesSet, setAttributeIndices, setDontNormalize, setInstances, setInvertSelection, toString, update, updateRanges, updateRanges, updateRanges, updateRangesFirst`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### MinkowskiDistance

          public MinkowskiDistance()

      Constructs an Minkowski Distance object, Instances must be still set.

    - #### MinkowskiDistance

          public MinkowskiDistance(Instances data)

      Constructs an Minkowski Distance object and automatically initializes the ranges.
      Parameters:
        `data` - the instances the distance function should work on

  - ### Method Detail

    - #### globalInfo

          public java.lang.String globalInfo()

      Returns a string describing this object.
      Specified by:
        `globalInfo` in class `NormalizableDistance`
      Returns:
        a description of the evaluator suitable for displaying in the explorer/experimenter gui

    - #### getTechnicalInformation

          public TechnicalInformation getTechnicalInformation()

      Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
      Specified by:
        `getTechnicalInformation` in interface `TechnicalInformationHandler`
      Returns:
        the technical information about this class

    - #### listOptions

          public java.util.Enumeration<Option> listOptions()

      Returns an enumeration describing the available options.
      Specified by:
        `listOptions` in interface `OptionHandler`
      Overrides:
        `listOptions` in class `NormalizableDistance`
      Returns:
        an enumeration of all the available options.

    - #### setOptions

          public void setOptions(java.lang.String[] options)
                          throws java.lang.Exception

      Parses a given list of options.
      Specified by:
        `setOptions` in interface `OptionHandler`
      Overrides:
        `setOptions` in class `NormalizableDistance`
      Parameters:
        `options` - the list of options as an array of strings
      Throws:
        `java.lang.Exception` - if an option is not supported

    - #### getOptions

          public java.lang.String[] getOptions()

      Gets the current settings of this object.
      Specified by:
        `getOptions` in interface `OptionHandler`
      Overrides:
        `getOptions` in class `NormalizableDistance`
      Returns:
        an array of strings suitable for passing to setOptions

    - #### orderTipText

          public java.lang.String orderTipText()

      Returns the tip text for this property.
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### setOrder

          public void setOrder(double value)

      Sets the order.
      Parameters:
        `value` - the new order

    - #### getOrder

          public double getOrder()

      Gets the order.
      Returns:
        the order

    - #### distance

          public double distance(Instance first,
                        Instance second)

      Calculates the distance between two instances.
      Specified by:
        `distance` in interface `DistanceFunction`
      Overrides:
        `distance` in class `NormalizableDistance`
      Parameters:
        `first` - the first instance
        `second` - the second instance
      Returns:
        the distance between the two given instances

    - #### distance

          public double distance(Instance first,
                        Instance second,
                        PerformanceStats stats)

      Calculates the distance (or similarity) between two instances. Need to pass this returned distance later on to postprocess method to set it on correct scale.
      P.S.: Please don't mix the use of this function with distance(Instance first, Instance second), as that already does post processing. Please consider passing Double.POSITIVE_INFINITY as the cutOffValue to this function and then later on do the post processing on all the distances.
      Specified by:
        `distance` in interface `DistanceFunction`
      Overrides:
        `distance` in class `NormalizableDistance`
      Parameters:
        `first` - the first instance
        `second` - the second instance
        `stats` - the structure for storing performance statistics.
      Returns:
        the distance between the two given instances or Double.POSITIVE_INFINITY.

    - #### postProcessDistances

          public void postProcessDistances(double[] distances)

      Does post processing of the distances (if necessary) returned by distance(distance(Instance first, Instance second, double cutOffValue). It is necessary to do so to get the correct distances if distance(distance(Instance first, Instance second, double cutOffValue) is used. This is because that function actually returns the squared distance to avoid inaccuracies arising from floating point comparison.
      Specified by:
        `postProcessDistances` in interface `DistanceFunction`
      Overrides:
        `postProcessDistances` in class `NormalizableDistance`
      Parameters:
        `distances` - the distances to post-process

    - #### getRevision

          public java.lang.String getRevision()

      Returns the revision string.
      Specified by:
        `getRevision` in interface `RevisionHandler`
      Returns:
        the revision