jsat.linear.distancemetrics
Class TrainableDistanceMetric
- java.lang.Object
-
- jsat.linear.distancemetrics.TrainableDistanceMetric
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, DistanceMetric
- Direct Known Subclasses:
- MahalanobisDistance, NormalizedEuclideanDistance
public abstract class TrainableDistanceMetric extends java.lang.Object implements DistanceMetric
Some Distance Metrics require information that can be learned from the data set. Trainable Distance Metrics support this facility, and algorithms that rely on distance metrics should check if their metric needs training. This is needed priming the distance metric on the whole data set and then performing cross validation would bias the results, as the metric would have been trained on the testing set examples.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description TrainableDistanceMetric()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description abstract TrainableDistanceMetricclone()abstract booleanneedsTraining()Returns true if the metric needs to be trained.abstract booleansupportsClassificationTraining()Some metrics might be special purpose, and not trainable for all types of data sets or tasks.abstract booleansupportsRegressionTraining()Some metrics might be special purpose, and not trainable for all types of data sets tasks.voidtrain(ClassificationDataSet dataSet)Trains this metric on the given classification problem data setabstract voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains this metric on the given classification problem data setvoidtrain(DataSet dataSet)Trains this metric on the given data setabstract voidtrain(DataSet dataSet, boolean parallel)Trains this metric on the given data set<V extends Vec>
voidtrain(java.util.List<V> dataSet)Trains this metric on the given data setabstract <V extends Vec>
voidtrain(java.util.List<V> dataSet, boolean parallel)Trains this metric on the given data setabstract voidtrain(RegressionDataSet dataSet)Trains this metric on the given regression problem data setabstract voidtrain(RegressionDataSet dataSet, boolean parallel)Trains this metric on the given regression problem data setstatic voidtrainIfNeeded(DistanceMetric dm, DataSet dataset)Static helper method for training a distance metric only if it is needed.static voidtrainIfNeeded(DistanceMetric dm, DataSet dataset, boolean parallel)Static helper method for training a distance metric only if it is needed.static voidtrainIfNeeded(DistanceMetric dm, DataSet dataset, java.util.concurrent.ExecutorService threadpool)Deprecated.I WILL DELETE THIS METHOD SOONstatic <V extends Vec>
voidtrainIfNeeded(DistanceMetric dm, java.util.List<V> dataset)Static helper method for training a distance metric only if it is needed.static <V extends Vec>
voidtrainIfNeeded(DistanceMetric dm, java.util.List<V> dataset, boolean parallel)static <V extends Vec>
voidtrainIfNeeded(DistanceMetric dm, java.util.List<V> dataset, java.util.concurrent.ExecutorService threadpool)Deprecated.I WILL DELETE THIS METHOD SOON-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.linear.distancemetrics.DistanceMetric
dist, dist, dist, dist, getAccelerationCache, getAccelerationCache, getQueryInfo, isIndiscemible, isSubadditive, isSymmetric, isValidMetric, metricBound, supportsAcceleration, toString
-
-
-
-
Method Detail
-
train
public <V extends Vec> void train(java.util.List<V> dataSet)
Trains this metric on the given data set- Type Parameters:
V- the type of vectors in the list- Parameters:
dataSet- the data set to train on- Throws:
java.lang.UnsupportedOperationException- if the metric can not be trained from unlabeled data
-
train
public abstract <V extends Vec> void train(java.util.List<V> dataSet, boolean parallel)
Trains this metric on the given data set- Type Parameters:
V- the type of vectors in the list- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used for training.falseif it should be done in a single-threaded manner.- Throws:
java.lang.UnsupportedOperationException- if the metric can not be trained from unlabeled data
-
train
public void train(DataSet dataSet)
Trains this metric on the given data set- Parameters:
dataSet- the data set to train on- Throws:
java.lang.UnsupportedOperationException- if the metric can not be trained from unlabeled data
-
train
public abstract void train(DataSet dataSet, boolean parallel)
Trains this metric on the given data set- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used for training.falseif it should be done in a single-threaded manner.- Throws:
java.lang.UnsupportedOperationException- if the metric can not be trained from unlabeled data
-
train
public void train(ClassificationDataSet dataSet)
Trains this metric on the given classification problem data set- Parameters:
dataSet- the data set to train on- Throws:
java.lang.UnsupportedOperationException- if the metric can not be trained from classification problems
-
train
public abstract void train(ClassificationDataSet dataSet, boolean parallel)
Trains this metric on the given classification problem data set- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used for training.falseif it should be done in a single-threaded manner.- Throws:
java.lang.UnsupportedOperationException- if the metric can not be trained from classification problems
-
supportsClassificationTraining
public abstract boolean supportsClassificationTraining()
Some metrics might be special purpose, and not trainable for all types of data sets or tasks. This method returns true if this metric supports training for classification problems, and false if it does not.
If a metric can learn from unlabeled data, it must return true for this method.- Returns:
- true if this metric supports training for classification problems, and false if it does not
-
train
public abstract void train(RegressionDataSet dataSet)
Trains this metric on the given regression problem data set- Parameters:
dataSet- the data set to train on- Throws:
java.lang.UnsupportedOperationException- if the metric can not be trained from regression problems
-
train
public abstract void train(RegressionDataSet dataSet, boolean parallel)
Trains this metric on the given regression problem data set- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used for training.falseif it should be done in a single-threaded manner.- Throws:
java.lang.UnsupportedOperationException- if the metric can not be trained from regression problems
-
supportsRegressionTraining
public abstract boolean supportsRegressionTraining()
Some metrics might be special purpose, and not trainable for all types of data sets tasks. This method returns true if this metric supports training for regression problems, and false if it does not.
If a metric can learn from unlabeled data, it must return true for this method.- Returns:
- true if this metric supports training for regression problems, and false if it does not
-
needsTraining
public abstract boolean needsTraining()
Returns true if the metric needs to be trained. This may be false if the metric allows the parameters to be specified beforehand. If the information was specified before hand, or does not need training, false is returned.- Returns:
- true if the metric needs training, false if it does not.
-
clone
public abstract TrainableDistanceMetric clone()
- Specified by:
clonein interfaceDistanceMetric- Overrides:
clonein classjava.lang.Object
-
trainIfNeeded
public static void trainIfNeeded(DistanceMetric dm, DataSet dataset)
Static helper method for training a distance metric only if it is needed. This method can be safely called for any Distance Metric.- Parameters:
dm- the distance metric to traindataset- the data set to train from
-
trainIfNeeded
public static void trainIfNeeded(DistanceMetric dm, DataSet dataset, boolean parallel)
Static helper method for training a distance metric only if it is needed. This method can be safely called for any Distance Metric.- Parameters:
dm- the distance metric to traindataset- the data set to train fromparallel-trueif multiple threads should be used for training.falseif it should be done in a single-threaded manner.
-
trainIfNeeded
public static void trainIfNeeded(DistanceMetric dm, DataSet dataset, java.util.concurrent.ExecutorService threadpool)
Deprecated. I WILL DELETE THIS METHOD SOONStatic helper method for training a distance metric only if it is needed. This method can be safely called for any Distance Metric.- Parameters:
dm- the distance metric to traindataset- the data set to train fromthreadpool- the source of threads for parallel training. May be null, in which casetrainIfNeeded(jsat.linear.distancemetrics.DistanceMetric, jsat.DataSet)is used instead.
-
trainIfNeeded
public static <V extends Vec> void trainIfNeeded(DistanceMetric dm, java.util.List<V> dataset, java.util.concurrent.ExecutorService threadpool)
Deprecated. I WILL DELETE THIS METHOD SOON- Type Parameters:
V-- Parameters:
dm-dataset-threadpool-
-
trainIfNeeded
public static <V extends Vec> void trainIfNeeded(DistanceMetric dm, java.util.List<V> dataset)
Static helper method for training a distance metric only if it is needed. This method can be safely called for any Distance Metric.- Type Parameters:
V- the type of vectors in the list- Parameters:
dm- the distance metric to traindataset- the data set to train from
-
trainIfNeeded
public static <V extends Vec> void trainIfNeeded(DistanceMetric dm, java.util.List<V> dataset, boolean parallel)
- Type Parameters:
V- the type of vectors in the list- Parameters:
dm- the distance metric to traindataset- the data set to train fromparallel-trueif multiple threads should be used for training.falseif it should be done in a single-threaded manner.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG