/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 *    FilteredDistance.java
 *    Copyright (C) 2014 University of Waikato, Hamilton, New Zealand
 *
 */

package weka.core;

import weka.core.DistanceFunction;
import weka.core.neighboursearch.PerformanceStats;

import weka.filters.Filter;
import weka.filters.unsupervised.attribute.RandomProjection;
import weka.filters.unsupervised.attribute.Remove;

import java.util.Enumeration;
import java.util.Vector;
import java.util.Collections;

import java.io.Serializable;

/**
 
 Applies the given filter before calling the given distance function.
 

* Valid options are:

 -F
  The filter to use. (default: weka.unsupervised.attribute.RandomProjection
 -E
  The distance function to use. (default: weka.core.EuclideanDistance
 
 Options specific to filter weka.filters.unsupervised.attribute.RandomProjection:
 
 -N <number>
  The number of dimensions (attributes) the data should be reduced to
  (default 10; exclusive of the class attribute, if it is set).
 -D [SPARSE1|SPARSE2|GAUSSIAN]
  The distribution to use for calculating the random matrix.
  Sparse1 is:
    sqrt(3)*{-1 with prob(1/6), 0 with prob(2/3), +1 with prob(1/6)}
  Sparse2 is:
    {-1 with prob(1/2), +1 with prob(1/2)}
 
 -P <percent>
  The percentage of dimensions (attributes) the data should
  be reduced to (exclusive of the class attribute, if it is set). The -N
  option is ignored if this option is present and is greater
  than zero.
 -M
  Replace missing values using the ReplaceMissingValues filter
 -R <num>
  The random seed for the random number generator used for
  calculating the random matrix (default 42).
 
 Options specific to distance function weka.core.EuclideanDistance:
 
 -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.
 -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 Eibe Frank (eibe@cs.waikato.ac.nz) * @version $Revision: 8034 $ */ public class FilteredDistance implements DistanceFunction, OptionHandler, Serializable { /** The distance function to use. */ DistanceFunction m_Distance = new EuclideanDistance(); /** The filter to use. */ Filter m_Filter = new RandomProjection(); /** Remove filter to remove attributes if required. */ Remove m_Remove = new Remove(); /** * Default constructor: need to set up Remove filter. */ public FilteredDistance() { m_Remove.setInvertSelection(true); m_Remove.setAttributeIndices("first-last"); } /** * Returns a string describing this object. * * @return a description of the evaluator suitable for * displaying in the explorer/experimenter gui */ public String globalInfo() { return "Applies the given filter before calling the given distance function."; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String filterTipText() { return "The filter to be used."; } /** * Sets the filter * * @param filter the filter with all options set. */ public void setFilter(Filter filter) { m_Filter = filter; } /** * Gets the filter used. * * @return the filter */ public Filter getFilter() { return m_Filter; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String distanceTipText() { return "The distance to be used."; } /** * Sets the distance * * @param distance the distance with all options set. */ public void setDistance(DistanceFunction distance) { m_Distance = distance; } /** * Gets the distance used. * * @return the distance */ public DistanceFunction getDistance() { return m_Distance; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration

Ads help maintain this website.