Package weka.core
Class FilteredDistance
java.lang.Object
weka.core.FilteredDistance
- All Implemented Interfaces:
Serializable
,DistanceFunction
,OptionHandler
public class FilteredDistance
extends Object
implements DistanceFunction, OptionHandler, 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.
- Version:
- $Revision: 8034 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clean()
Free any references to training instancesdouble
Calculates the distance between two instances.double
Calculates the distance between two instances.double
distance
(Instance first, Instance second, double cutOffValue, PerformanceStats stats) Calculates the distance between two instances.double
distance
(Instance first, Instance second, PerformanceStats stats) Calculates the distance between two instances.Returns the tip text for this propertyReturns the tip text for this propertyGets the range of attributes used in the calculation of the distance.Gets the distance used.Gets the filter used.returns the instances currently set.boolean
Gets whether the matching sense of attribute indices is inverted or not.String[]
Gets the current settings.Returns a string describing this object.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).void
setAttributeIndices
(String value) Sets the range of attributes to use in the calculation of the distance.void
setDistance
(DistanceFunction distance) Sets the distancevoid
Sets the filtervoid
setInstances
(Instances insts) Sets the instances.void
setInvertSelection
(boolean value) Sets whether the matching sense of attribute indices is inverted or not.void
setOptions
(String[] options) Parses a given list of options.void
Update the distance function (if necessary) for the newly added instance.
-
Constructor Details
-
FilteredDistance
public FilteredDistance()Default constructor: need to set up Remove filter.
-
-
Method Details
-
globalInfo
Returns a string describing this object.- Returns:
- a description of the evaluator suitable for displaying in the explorer/experimenter gui
-
filterTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setFilter
Sets the filter- Parameters:
filter
- the filter with all options set.
-
getFilter
Gets the filter used.- Returns:
- the filter
-
distanceTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setDistance
Sets the distance- Parameters:
distance
- the distance with all options set.
-
getDistance
Gets the distance used.- Returns:
- the distance
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Returns:
- an enumeration of all the available options.
-
getOptions
Gets the current settings. Returns empty array.- Specified by:
getOptions
in interfaceOptionHandler
- Returns:
- an array of strings suitable for passing to setOptions()
-
setOptions
Parses a given list of options.- Specified by:
setOptions
in interfaceOptionHandler
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
setInstances
Sets the instances.- Specified by:
setInstances
in interfaceDistanceFunction
- Parameters:
insts
- the instances to use
-
getInstances
returns the instances currently set.- Specified by:
getInstances
in interfaceDistanceFunction
- Returns:
- the current instances
-
setAttributeIndices
Sets the range of attributes to use in the calculation of the distance. The indices start from 1, 'first' and 'last' are valid as well. E.g.: first-3,5,6-last- Specified by:
setAttributeIndices
in interfaceDistanceFunction
- Parameters:
value
- the new attribute index range
-
getAttributeIndices
Gets the range of attributes used in the calculation of the distance.- Specified by:
getAttributeIndices
in interfaceDistanceFunction
- Returns:
- the attribute index range
-
setInvertSelection
public void setInvertSelection(boolean value) Sets whether the matching sense of attribute indices is inverted or not.- Specified by:
setInvertSelection
in interfaceDistanceFunction
- Parameters:
value
- if true the matching sense is inverted
-
getInvertSelection
public boolean getInvertSelection()Gets whether the matching sense of attribute indices is inverted or not.- Specified by:
getInvertSelection
in interfaceDistanceFunction
- Returns:
- true if the matching sense is inverted
-
distance
Calculates the distance between two instances.- Specified by:
distance
in interfaceDistanceFunction
- Parameters:
first
- the first instancesecond
- the second instance- Returns:
- the distance between the two given instances
-
distance
Calculates the distance between two instances.- Specified by:
distance
in interfaceDistanceFunction
- Parameters:
first
- the first instancesecond
- the second instancestats
- the performance stats object- Returns:
- the distance between the two given instances
- Throws:
Exception
- if calculation fails
-
distance
Calculates the distance between two instances. Offers speed up (if the distance function class in use supports it) in nearest neighbour search by taking into account the cutOff or maximum distance. Depending on the distance function class, post processing of the distances by postProcessDistances(double []) may be required if this function is used.- Specified by:
distance
in interfaceDistanceFunction
- Parameters:
first
- the first instancesecond
- the second instancecutOffValue
- If the distance being calculated becomes larger than cutOffValue then the rest of the calculation is discarded.- Returns:
- the distance between the two given instances or Double.POSITIVE_INFINITY if the distance being calculated becomes larger than cutOffValue.
-
distance
Calculates the distance between two instances. Offers speed up (if the distance function class in use supports it) in nearest neighbour search by taking into account the cutOff or maximum distance. Depending on the distance function class, post processing of the distances by postProcessDistances(double []) may be required if this function is used.- Specified by:
distance
in interfaceDistanceFunction
- Parameters:
first
- the first instancesecond
- the second instancecutOffValue
- If the distance being calculated becomes larger than cutOffValue then the rest of the calculation is discarded.stats
- the performance stats object- Returns:
- the distance between the two given instances or Double.POSITIVE_INFINITY if the distance being calculated becomes larger than cutOffValue.
-
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 may be necessary, depending on the distance function, to do post processing to set the distances on the correct scale. Some distance function classes may not return correct distances using the cutOffValue distance function to minimize the inaccuracies resulting from floating point comparison and manipulation.- Specified by:
postProcessDistances
in interfaceDistanceFunction
- Parameters:
distances
- the distances to post-process
-
update
Update the distance function (if necessary) for the newly added instance.- Specified by:
update
in interfaceDistanceFunction
- Parameters:
ins
- the instance to add
-
clean
public void clean()Free any references to training instances- Specified by:
clean
in interfaceDistanceFunction
-