Documentation of 'jsat.linear.distancemetrics.TrainableDistanceMetric' Java class
TrainableDistanceMetric
jsat.linear.distancemetrics

Class 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 Detail

      • TrainableDistanceMetric

        public TrainableDistanceMetric()
    • 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 on
        parallel - true if multiple threads should be used for training. false if 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 on
        parallel - true if multiple threads should be used for training. false if 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 on
        parallel - true if multiple threads should be used for training. false if 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 on
        parallel - true if multiple threads should be used for training. false if 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.
      • 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 train
        dataset - 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 train
        dataset - the data set to train from
        parallel - true if multiple threads should be used for training. false if 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 SOON
        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 train
        dataset - the data set to train from
        threadpool - the source of threads for parallel training. May be null, in which case trainIfNeeded(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 train
        dataset - 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 train
        dataset - the data set to train from
        parallel - true if multiple threads should be used for training. false if it should be done in a single-threaded manner.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.