weka.core.neighboursearch

## Class FilteredNeighbourSearch

- java.lang.Object
- - weka.core.neighboursearch.NearestNeighbourSearch
  - - weka.core.neighboursearch.FilteredNeighbourSearch

- All Implemented Interfaces:
    java.io.Serializable, AdditionalMeasureProducer, OptionHandler, RevisionHandler

      public class FilteredNeighbourSearch
      extends NearestNeighbourSearch

  Applies the given filter before calling the given neighbour search method. The filter must not change the size of the dataset or the order of the instances! Also, the range setting is specified for the distance function is ignored: all attributes are used for the distance calculation.

  Valid options are:

       -F
        The filter to use. (default: weka.unsupervised.attribute.RandomProjection

       -S
        The search method to use. (default: weka.core.neighboursearch.LinearNNSearch)

       Options specific to filter weka.filters.AllFilter:

       -output-debug-info
        If set, filter is run in debug mode and
        may output additional info to the console

       -do-not-check-capabilities
        If set, filter capabilities are not checked before filter is built
        (use with caution).

       Options specific to search method weka.core.neighboursearch.LinearNNSearch:

       -S
        Skip identical instances (distances equal to zero).

       -A <classname and options>
        Distance function to use.
        (default: weka.core.EuclideanDistance)

       -P
        Calculate performance statistics.

  Version:
    $Revision: 8034 $
  Author:
    Eibe Frank (eibe@cs.waikato.ac.nz)
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FilteredNeighbourSearch()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addInstanceInfo(Instance ins)` Just callsthe update method.
    `java.lang.String` | `filterTipText()` Returns the tip text for this property
    `double[]` | `getDistances()` Returns the distances for the nearest neighbours in the FILTERED space
    `Filter` | `getFilter()` Gets the filter used.
    `java.lang.String[]` | `getOptions()` Gets the current settings.
    `java.lang.String` | `getRevision()` Returns the revision string
    `NearestNeighbourSearch` | `getSearchMethod()` Gets the search method used.
    `java.lang.String` | `globalInfo()` Returns a string describing this object.
    `Instances` | `kNearestNeighbours(Instance target, int k)` Returns the nearest neighbours for the given instance based on distance measured in the filtered space.
    `java.util.Enumeration<Option>` | `listOptions()` Returns an enumeration describing the available options.
    `Instance` | `nearestNeighbour(Instance target)` Returns the nearest neighbour for the given instance based on distance measured in the filtered space.
    `java.lang.String` | `searchMethodTipText()` Returns the tip text for this property
    `void` | `setFilter(Filter filter)` Sets the filter
    `void` | `setInstances(Instances data)` Sets the instances to build the filtering model from.
    `void` | `setOptions(java.lang.String[] options)` Parses a given list of options.
    `void` | `setSearchMethod(NearestNeighbourSearch search)` Sets the search method
    `void` | `update(Instance ins)` Updates ranges based on the given instance, once it has been filtered.

    - ### Methods inherited from class weka.core.neighboursearch.NearestNeighbourSearch

      `combSort11, distanceFunctionTipText, enumerateMeasures, getDistanceFunction, getInstances, getMeasure, getMeasurePerformance, getPerformanceStats, measurePerformanceTipText, quickSort, setDistanceFunction, setMeasurePerformance`

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

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

- - ### Constructor Detail

    - #### FilteredNeighbourSearch

          public FilteredNeighbourSearch()

  - ### Method Detail

    - #### setInstances

          public void setInstances(Instances data)

      Sets the instances to build the filtering model from.
      Overrides:
        `setInstances` in class `NearestNeighbourSearch`
      Parameters:
        `insts` - the Instances object

    - #### globalInfo

          public java.lang.String globalInfo()

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

    - #### filterTipText

          public java.lang.String filterTipText()

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

    - #### setFilter

          public void setFilter(Filter filter)

      Sets the filter
      Parameters:
        `filter` - the filter with all options set.

    - #### getFilter

          public Filter getFilter()

      Gets the filter used.
      Returns:
        the filter

    - #### searchMethodTipText

          public java.lang.String searchMethodTipText()

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

    - #### setSearchMethod

          public void setSearchMethod(NearestNeighbourSearch search)

      Sets the search method
      Parameters:
        `searchMethod` - the search method with all options set.

    - #### getSearchMethod

          public NearestNeighbourSearch getSearchMethod()

      Gets the search method used.
      Returns:
        the search method

    - #### listOptions

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

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

    - #### getOptions

          public java.lang.String[] getOptions()

      Gets the current settings. Returns empty array.
      Specified by:
        `getOptions` in interface `OptionHandler`
      Overrides:
        `getOptions` in class `NearestNeighbourSearch`
      Returns:
        an array of strings suitable for passing to setOptions()

    - #### 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 `NearestNeighbourSearch`
      Parameters:
        `options` - the list of options as an array of strings
      Throws:
        `java.lang.Exception` - if an option is not supported

    - #### getRevision

          public java.lang.String getRevision()

      Returns the revision string
      Returns:
        the revision
      See Also:
        `RevisionHandler.getRevision()`

    - #### nearestNeighbour

          public Instance nearestNeighbour(Instance target)
                                    throws java.lang.Exception

      Returns the nearest neighbour for the given instance based on distance measured in the filtered space.
      Specified by:
        `nearestNeighbour` in class `NearestNeighbourSearch`
      Parameters:
        `target` - the instance for which to find the nearest neighbour
      Returns:
        the nearest neighbour
      Throws:
        `java.lang.Exception` - if the nearest neighbour could not be found.
      See Also:
        `NearestNeighbourSearch.nearestNeighbour(weka.core.Instance)`

    - #### kNearestNeighbours

          public Instances kNearestNeighbours(Instance target,
                                     int k)
                                       throws java.lang.Exception

      Returns the nearest neighbours for the given instance based on distance measured in the filtered space.
      Specified by:
        `kNearestNeighbours` in class `NearestNeighbourSearch`
      Parameters:
        `target` - the instance for which to find the nearest neighbour
        `k` - the number of nearest neighbours to return
      Returns:
        the nearest Neighbours
      Throws:
        `java.lang.Exception` - if the neighbours could not be found.
      See Also:
        `NearestNeighbourSearch.kNearestNeighbours(weka.core.Instance, int)`

    - #### getDistances

          public double[] getDistances()
                                throws java.lang.Exception

      Returns the distances for the nearest neighbours in the FILTERED space
      Specified by:
        `getDistances` in class `NearestNeighbourSearch`
      Returns:
        the array of distances for the nearest neighbours
      Throws:
        `java.lang.Exception` - if called before calling kNearestNeighbours or nearestNeighbours.
      See Also:
        `NearestNeighbourSearch.getDistances()`

    - #### update

          public void update(Instance ins)
                      throws java.lang.Exception

      Updates ranges based on the given instance, once it has been filtered.
      Specified by:
        `update` in class `NearestNeighbourSearch`
      Parameters:
        `ins` - the instance to add
      Throws:
        `java.lang.Exception` - if updating fails
      See Also:
        `NearestNeighbourSearch.update(weka.core.Instance)`

    - #### addInstanceInfo

          public void addInstanceInfo(Instance ins)

      Just callsthe update method.
      Overrides:
        `addInstanceInfo` in class `NearestNeighbourSearch`
      Parameters:
        `ins` - The instance to add the information of.