public abstract class NormalizableDistance extends Object implements DistanceFunction
Modifier and Type | Field and Description |
---|---|
protected boolean[] |
m_ActiveIndices
The boolean flags, whether an attribute will be used or not.
|
protected weka.core.Instances |
m_Data
the instances used internally.
|
protected boolean |
m_DontNormalize
True if normalization is turned off (default false).
|
protected double[][] |
m_Ranges
The range of the attributes.
|
protected boolean |
m_Validated
Whether all the necessary preparations have been done.
|
static int |
R_MAX
Index in ranges for MAX.
|
static int |
R_MIN
Index in ranges for MIN.
|
static int |
R_WIDTH
Index in ranges for WIDTH.
|
Constructor and Description |
---|
NormalizableDistance()
Invalidates the distance function, Instances must be still set.
|
NormalizableDistance(weka.core.Instances data)
Initializes the distance function and automatically initializes the
ranges.
|
Modifier and Type | Method and Description |
---|---|
String |
attributeIndicesTipText()
Returns the tip text for this property.
|
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)
Calculates the distance between two instances.
|
String |
dontNormalizeTipText()
Returns the tip text for this property.
|
String |
getAttributeIndices()
Gets the range of attributes used in the calculation of the distance.
|
boolean |
getDontNormalize()
Gets whether if the attribute values are to be normazlied in distance
calculation.
|
weka.core.Instances |
getInstances()
returns the instances currently set.
|
boolean |
getInvertSelection()
Gets whether the matching sense of attribute indices is inverted or not.
|
double[][] |
getRanges()
Method to get the ranges.
|
abstract String |
globalInfo()
Returns a string describing this object.
|
protected void |
initialize()
initializes the ranges and the attributes being used.
|
protected void |
initializeAttributeIndices()
initializes the attribute indices.
|
double[][] |
initializeRanges()
Initializes the ranges using all instances of the dataset.
|
double[][] |
initializeRanges(int[] instList)
Initializes the ranges of a subset of the instances of this dataset.
|
double[][] |
initializeRanges(int[] instList,
int startIdx,
int endIdx)
Initializes the ranges of a subset of the instances of this dataset.
|
void |
initializeRangesEmpty(int numAtt,
double[][] ranges)
Used to initialize the ranges.
|
boolean |
inRanges(weka.core.Instance instance,
double[][] ranges)
Test if an instance is within the given ranges.
|
protected void |
invalidate()
invalidates all initializations.
|
String |
invertSelectionTipText()
Returns the tip text for this property.
|
static boolean |
isMissingValue(double val)
Tests if the given value codes "missing".
|
protected double |
norm(double x,
int i)
Normalizes a given value of a numeric attribute.
|
void |
postProcessDistances(double[] distances)
Does nothing, derived classes may override it though.
|
boolean |
rangesSet()
Check if ranges are set.
|
void |
setAttributeIndices(String value)
Sets the range of attributes to use in the calculation of the distance.
|
void |
setDontNormalize(boolean dontNormalize)
Sets whether if the attribute values are to be normalized in distance
calculation.
|
void |
setInstances(weka.core.Instances insts)
Sets the instances.
|
void |
setInvertSelection(boolean value)
Sets whether the matching sense of attribute indices is inverted or not.
|
String |
toString()
Returns an empty string.
|
void |
update(weka.core.Instance ins)
Update the distance function (if necessary) for the newly added instance.
|
protected abstract double |
updateDistance(double currDist,
double diff)
Updates the current distance calculated so far with the new difference
between two attributes.
|
void |
updateRanges(weka.core.Instance instance)
Update the ranges if a new instance comes.
|
double[][] |
updateRanges(weka.core.Instance instance,
double[][] ranges)
Updates the ranges given a new instance.
|
void |
updateRanges(weka.core.Instance instance,
int numAtt,
double[][] ranges)
Updates the minimum and maximum and width values for all the attributes
based on a new instance.
|
void |
updateRangesFirst(weka.core.Instance instance,
int numAtt,
double[][] ranges)
Used to initialize the ranges.
|
protected void |
validate()
performs the initializations if necessary.
|
public static final int R_MIN
public static final int R_MAX
public static final int R_WIDTH
protected weka.core.Instances m_Data
protected boolean m_DontNormalize
protected double[][] m_Ranges
protected boolean[] m_ActiveIndices
protected boolean m_Validated
public NormalizableDistance()
public NormalizableDistance(weka.core.Instances data)
data
- the instances the distance function should work onpublic abstract String globalInfo()
public String dontNormalizeTipText()
public void setDontNormalize(boolean dontNormalize)
dontNormalize
- if true the values are not normalizedpublic boolean getDontNormalize()
public String attributeIndicesTipText()
public void setAttributeIndices(String value)
setAttributeIndices
in interface DistanceFunction
value
- the new attribute index rangepublic String getAttributeIndices()
getAttributeIndices
in interface DistanceFunction
public String invertSelectionTipText()
public void setInvertSelection(boolean value)
setInvertSelection
in interface DistanceFunction
value
- if true the matching sense is invertedpublic boolean getInvertSelection()
getInvertSelection
in interface DistanceFunction
protected void invalidate()
protected void validate()
protected void initialize()
protected void initializeAttributeIndices()
public void setInstances(weka.core.Instances insts)
setInstances
in interface DistanceFunction
insts
- the instances to usepublic weka.core.Instances getInstances()
getInstances
in interface DistanceFunction
public void postProcessDistances(double[] distances)
postProcessDistances
in interface DistanceFunction
distances
- the distances to post-processpublic void update(weka.core.Instance ins)
update
in interface DistanceFunction
ins
- the instance to addpublic double distance(weka.core.Instance first, weka.core.Instance second)
distance
in interface DistanceFunction
first
- the first instancesecond
- the second instancepublic double distance(weka.core.Instance first, weka.core.Instance second, double cutOffValue)
distance
in interface DistanceFunction
first
- the first instancesecond
- the second instancecutOffValue
- If the distance being calculated becomes larger than
cutOffValue then the rest of the calculation is
discarded.protected abstract double updateDistance(double currDist, double diff)
currDist
- the current distance calculated so fardiff
- the difference between two new attributesdifference(int, double, double)
protected double norm(double x, int i)
x
- the value to be normalizedi
- the attribute's indexprotected double difference(int index, double val1, double val2)
index
- the attribute indexval1
- the first valueval2
- the second valuepublic double[][] initializeRanges()
public void updateRangesFirst(weka.core.Instance instance, int numAtt, double[][] ranges)
instance
- the new instancenumAtt
- number of attributes in the modelranges
- low, high and width values for all attributespublic void updateRanges(weka.core.Instance instance, int numAtt, double[][] ranges)
instance
- the new instancenumAtt
- number of attributes in the modelranges
- low, high and width values for all attributespublic void initializeRangesEmpty(int numAtt, double[][] ranges)
numAtt
- number of attributes in the modelranges
- low, high and width values for all attributespublic double[][] updateRanges(weka.core.Instance instance, double[][] ranges)
instance
- the new instanceranges
- low, high and width values for all attributespublic double[][] initializeRanges(int[] instList) throws Exception
instList
- list of indexes of the subsetException
- if something goes wrongpublic double[][] initializeRanges(int[] instList, int startIdx, int endIdx) throws Exception
instList
- list of indexes of the instancesstartIdx
- start index of the subset of instances in the indices arrayendIdx
- end index of the subset of instances in the indices arrayException
- if something goes wrongpublic void updateRanges(weka.core.Instance instance)
instance
- the new instancepublic boolean inRanges(weka.core.Instance instance, double[][] ranges)
instance
- the instanceranges
- the ranges the instance is tested to be inpublic boolean rangesSet()
public double[][] getRanges() throws Exception
Exception
- if no randes are set yetpublic String toString()
public static boolean isMissingValue(double val)
val
- the value to be testedCopyright © 2014 University of Waikato, Hamilton, NZ. All Rights Reserved.