Package weka.core

Class WeightedEuclideanDistanceRidge

  • All Implemented Interfaces:
    Serializable, Cloneable, weka.core.DistanceFunction, weka.core.OptionHandler, weka.core.RevisionHandler, weka.core.TechnicalInformationHandler

    public class WeightedEuclideanDistanceRidge
    extends weka.core.NormalizableDistance
    implements Cloneable, weka.core.TechnicalInformationHandler
    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.

    For more information, see:

    Wikipedia. Euclidean distance. URL http://en.wikipedia.org/wiki/Euclidean_distance.

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


    Valid options are:

     -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.
    Author:
    dale (dale at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected double[] m_Coefficients
      Array for storing coefficients of linear regression.
      protected LinearRegressionJ m_LR  
      protected weka.filters.unsupervised.attribute.Normalize m_norm  
      protected double m_Ridge  
      • 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

      Constructors 
      Constructor Description
      WeightedEuclideanDistanceRidge()
      Constructs an Euclidean Distance object, Instances must be still set.
      WeightedEuclideanDistanceRidge​(weka.core.Instances data)
      Constructs an Euclidean Distance object and automatically initializes the ranges.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected double difference​(int index, double val1, double val2)
      Computes the difference between two given attribute values.
      double distance​(weka.core.Instance first, weka.core.Instance second)
      Calculates the distance between two instances.
      double distance​(weka.core.Instance first, weka.core.Instance second, double cutOffValue, weka.core.neighboursearch.PerformanceStats stats)  
      double distance​(weka.core.Instance first, weka.core.Instance second, weka.core.neighboursearch.PerformanceStats stats)
      Calculates the distance (or similarity) between two instances.
      double getMiddle​(double[] ranges)
      Returns value in the middle of the two parameter values.
      String[] getOptions()
      Gets the current settings of the classifier.
      String getRevision()
      Returns the revision string.
      double getRidge()
      Get the value of Ridge.
      weka.core.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.
      String globalInfo()
      Returns a string describing this object.
      protected void initialize()
      initializes the ranges and the attributes being used.
      Enumeration<weka.core.Option> listOptions()
      Returns an enumeration describing the available options.
      void postProcessDistances​(double[] distances)
      Does post processing of the distances (if necessary) returned by distance(distance(Instance first, Instance second, double cutOffValue).
      String ridgeTipText()
      Returns the tip text for this property
      void setOptions​(String[] options)
      Parses a given list of options.
      void setRidge​(double newRidge)
      Set the value of Ridge.
      double sqDifference​(int index, double val1, double val2)
      Returns the squared difference of two values of an attribute.
      protected weka.core.Instance transform​(weka.core.Instance i)  
      protected double updateDistance​(double currDist, double diff)
      Updates the current distance calculated so far with the new difference between two attributes.
      boolean valueIsSmallerEqual​(weka.core.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.NormalizableDistance

        attributeIndicesTipText, clean, distance, dontNormalizeTipText, getAttributeIndices, getDontNormalize, getInstances, getInvertSelection, getRanges, initializeAttributeIndices, initializeRanges, initializeRanges, initializeRanges, initializeRangesEmpty, inRanges, invalidate, invertSelectionTipText, norm, rangesSet, setAttributeIndices, setDontNormalize, setInstances, setInvertSelection, toString, update, updateRanges, updateRanges, updateRanges, updateRangesFirst, validate
    • Field Detail

      • m_Coefficients

        protected double[] m_Coefficients
        Array for storing coefficients of linear regression.
      • m_norm

        protected weka.filters.unsupervised.attribute.Normalize m_norm
      • m_Ridge

        protected double m_Ridge
    • Constructor Detail

      • WeightedEuclideanDistanceRidge

        public WeightedEuclideanDistanceRidge()
        Constructs an Euclidean Distance object, Instances must be still set.
      • WeightedEuclideanDistanceRidge

        public WeightedEuclideanDistanceRidge​(weka.core.Instances data)
        Constructs an Euclidean Distance object and automatically initializes the ranges.
        Parameters:
        data - the instances the distance function should work on
    • Method Detail

      • initialize

        protected void initialize()
        initializes the ranges and the attributes being used.
        Overrides:
        initialize in class weka.core.NormalizableDistance
      • globalInfo

        public String globalInfo()
        Returns a string describing this object.
        Specified by:
        globalInfo in class weka.core.NormalizableDistance
        Returns:
        a description of the evaluator suitable for displaying in the explorer/experimenter gui
      • getTechnicalInformation

        public weka.core.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 weka.core.TechnicalInformationHandler
        Returns:
        the technical information about this class
      • listOptions

        public Enumeration<weka.core.Option> listOptions()
        Returns an enumeration describing the available options.
        Specified by:
        listOptions in interface weka.core.OptionHandler
        Overrides:
        listOptions in class weka.core.NormalizableDistance
        Returns:
        an enumeration of all the available options.
      • getOptions

        public String[] getOptions()
        Gets the current settings of the classifier.
        Specified by:
        getOptions in interface weka.core.OptionHandler
        Overrides:
        getOptions in class weka.core.NormalizableDistance
        Returns:
        an array of strings suitable for passing to setOptions
      • setOptions

        public void setOptions​(String[] options)
                        throws Exception
        Parses a given list of options.

        Valid options are:

         -S <number of selection method>
          Set the attribute selection method to use. 1 = None, 2 = Greedy.
          (default 0 = M5' method)
         
         -C
          Do not try to eliminate colinear attributes.
         
         -R <double>
          Set ridge parameter (default 1.0e-8).
         
         -minimal
          Conserve memory, don't keep dataset header and means/stdevs.
          Model cannot be printed out if this option is enabled. (default: keep data)
         
         -additional-stats
          Output additional statistics.
         
         -output-debug-info
          If set, classifier is run in debug mode and
          may output additional info to the console
         
         -do-not-check-capabilities
          If set, classifier capabilities are not checked before classifier is built
          (use with caution).
         
        Specified by:
        setOptions in interface weka.core.OptionHandler
        Overrides:
        setOptions in class weka.core.NormalizableDistance
        Parameters:
        options - the list of options as an array of strings
        Throws:
        Exception - if an option is not supported
      • ridgeTipText

        public String ridgeTipText()
        Returns the tip text for this property
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getRidge

        public double getRidge()
        Get the value of Ridge.
        Returns:
        Value of Ridge.
      • setRidge

        public void setRidge​(double newRidge)
        Set the value of Ridge.
        Parameters:
        newRidge - Value to assign to Ridge.
      • distance

        public double distance​(weka.core.Instance first,
                               weka.core.Instance second)
        Calculates the distance 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 given instances
      • distance

        public double distance​(weka.core.Instance first,
                               weka.core.Instance second,
                               weka.core.neighboursearch.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 weka.core.DistanceFunction
        Overrides:
        distance in class weka.core.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.
      • 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:
        difference(int, double, double)
      • distance

        public double distance​(weka.core.Instance first,
                               weka.core.Instance second,
                               double cutOffValue,
                               weka.core.neighboursearch.PerformanceStats stats)
        Specified by:
        distance in interface weka.core.DistanceFunction
        Overrides:
        distance in class weka.core.NormalizableDistance
      • difference

        protected double difference​(int index,
                                    double val1,
                                    double val2)
        Computes the difference between two given attribute values.
        Overrides:
        difference in class weka.core.NormalizableDistance
        Parameters:
        index - the attribute index
        val1 - the first value
        val2 - the second value
        Returns:
        the difference
      • 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 weka.core.DistanceFunction
        Overrides:
        postProcessDistances in class weka.core.NormalizableDistance
        Parameters:
        distances - the distances to post-process
      • sqDifference

        public double sqDifference​(int index,
                                   double val1,
                                   double val2)
        Returns the squared difference of two values of an attribute.
        Parameters:
        index - the attribute index
        val1 - the first value
        val2 - the second value
        Returns:
        the squared difference
      • getMiddle

        public double getMiddle​(double[] ranges)
        Returns value in the middle of the two parameter values.
        Parameters:
        ranges - the ranges to this dimension
        Returns:
        the middle value
      • transform

        protected weka.core.Instance transform​(weka.core.Instance i)
      • valueIsSmallerEqual

        public boolean valueIsSmallerEqual​(weka.core.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
        value - the value to compare with
        Returns:
        true if value of instance is smaller or equal value
      • getRevision

        public String getRevision()
        Returns the revision string.
        Specified by:
        getRevision in interface weka.core.RevisionHandler
        Returns:
        the revision