Package weka.core.neighboursearch

# Class FilteredNeighbourSearch

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

All Implemented Interfaces:
  `Serializable`, `AdditionalMeasureProducer`, `CapabilitiesHandler`, `OptionHandler`, `RevisionHandler`

public class FilteredNeighbourSearch extends NearestNeighbourSearch implements CapabilitiesHandler
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 that 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.filters.AllFilter)

     -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
  Description
  `FilteredNeighbourSearch()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addInstanceInfo(Instance ins)`
  Updates the instance info in the underlying search method, once the instance has been filtered.
  `String`
  `filterTipText()`
  Returns the tip text for this property
  `Capabilities`
  `getCapabilities()`
  Returns default capabilities of the classifier.
  `double[]`
  `getDistances()`
  Returns the distances for the nearest neighbours in the FILTERED space
  `Filter`
  `getFilter()`
  Gets the filter used.
  `String[]`
  `getOptions()`
  Gets the current settings.
  `String`
  `getRevision()`
  Returns the revision string
  `NearestNeighbourSearch`
  `getSearchMethod()`
  Gets the search method used.
  `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.
  `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.
  `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(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 Details

  - ### FilteredNeighbourSearch

    public FilteredNeighbourSearch()

- ## Method Details

  - ### getCapabilities

    public Capabilities getCapabilities()
    Returns default capabilities of the classifier.
    Specified by:
      `getCapabilities` in interface `CapabilitiesHandler`
    Returns:
      the capabilities of this classifier
    See Also:
      - `Capabilities`

  - ### 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 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 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 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 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 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(String[] options) throws 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:
      `Exception` - if an option is not supported

  - ### getRevision

    public String getRevision()
    Returns the revision string
    Specified by:
      `getRevision` in interface `RevisionHandler`
    Returns:
      the revision
    See Also:
      - `RevisionHandler.getRevision()`

  - ### nearestNeighbour

    public Instance nearestNeighbour(Instance target) throws 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:
      `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 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:
      `Exception` - if the neighbours could not be found.
    See Also:
      - `NearestNeighbourSearch.kNearestNeighbours(weka.core.Instance, int)`

  - ### getDistances

    public double[] getDistances() throws 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:
      `Exception` - if called before calling kNearestNeighbours or nearestNeighbours.
    See Also:
      - `NearestNeighbourSearch.getDistances()`

  - ### update

    public void update(Instance ins) throws 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:
      `Exception` - if updating fails
    See Also:
      - `NearestNeighbourSearch.update(weka.core.Instance)`

  - ### addInstanceInfo

    public void addInstanceInfo(Instance ins)
    Updates the instance info in the underlying search method, once the instance has been filtered.
    Overrides:
      `addInstanceInfo` in class `NearestNeighbourSearch`
    Parameters:
      `ins` - The instance to add the information of.