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

Class MahalanobisDistance

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DistanceMetric


    public class MahalanobisDistance
    extends TrainableDistanceMetric
    The Mahalanobis Distance is a metric that takes into account the variance of the data. This requires training the metric with the data set to learn the variance of. The extra work involved adds computation time to training and prediction. However, improvements in accuracy can be obtained for many data sets. At the same time, the Mahalanobis Distance can also be detrimental to accuracy.
    See Also:
    Serialized Form
    • Constructor Detail

      • MahalanobisDistance

        public MahalanobisDistance()
    • Method Detail

      • isReTrain

        public boolean isReTrain()
        Returns true if this metric will indicate a need to be retrained once it has been trained once. This will mean needsTraining() will always return true. false means the metric will not indicate a need to be retrained once it has been trained once.
        Returns:
        true if the data should always be retrained, false if it should not.
      • setReTrain

        public void setReTrain(boolean reTrain)
        It may be desirable to have the metric trained only once, and use the same parameters for all other training sessions of the learning algorithm using the metric. This can be controlled through this boolean. Setting true if this metric will indicate a need to be retrained once it has been trained once. This will mean needsTraining() will always return true. false means the metric will not indicate a need to be retrained once it has been trained once.
        Parameters:
        reTrain - true to make the metric always request retraining, false so it will not.
      • setInverseCovariance

        public void setInverseCovariance(Matrix S)
        Sets the Inverse Covariance Matrix used as the distance matrix by this distance metric.
        Parameters:
        S - the matrix to use as the distance matrix
      • train

        public <V extends Vec> void train(java.util.List<V> dataSet)
        Description copied from class: TrainableDistanceMetric
        Trains this metric on the given data set
        Overrides:
        train in class TrainableDistanceMetric
        Type Parameters:
        V - the type of vectors in the list
        Parameters:
        dataSet - the data set to train on
      • train

        public <V extends Vec> void train(java.util.List<V> dataSet,
                                          boolean parallel)
        Description copied from class: TrainableDistanceMetric
        Trains this metric on the given data set
        Specified by:
        train in class TrainableDistanceMetric
        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.
      • train

        public void train(DataSet dataSet,
                          boolean parallel)
        Description copied from class: TrainableDistanceMetric
        Trains this metric on the given data set
        Specified by:
        train in class TrainableDistanceMetric
        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.
      • train

        public void train(ClassificationDataSet dataSet,
                          boolean parallel)
        Description copied from class: TrainableDistanceMetric
        Trains this metric on the given classification problem data set
        Specified by:
        train in class TrainableDistanceMetric
        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.
      • supportsClassificationTraining

        public boolean supportsClassificationTraining()
        Description copied from class: TrainableDistanceMetric
        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.
        Specified by:
        supportsClassificationTraining in class TrainableDistanceMetric
        Returns:
        true if this metric supports training for classification problems, and false if it does not
      • train

        public void train(RegressionDataSet dataSet,
                          boolean parallel)
        Description copied from class: TrainableDistanceMetric
        Trains this metric on the given regression problem data set
        Specified by:
        train in class TrainableDistanceMetric
        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.
      • supportsRegressionTraining

        public boolean supportsRegressionTraining()
        Description copied from class: TrainableDistanceMetric
        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.
        Specified by:
        supportsRegressionTraining in class TrainableDistanceMetric
        Returns:
        true if this metric supports training for regression problems, and false if it does not
      • needsTraining

        public boolean needsTraining()
        Description copied from class: TrainableDistanceMetric
        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.
        Specified by:
        needsTraining in class TrainableDistanceMetric
        Returns:
        true if the metric needs training, false if it does not.
      • dist

        public double dist(Vec a,
                           Vec b)
        Description copied from interface: DistanceMetric
        Computes the distance between 2 vectors. The smaller the value, the closer, and there for, more similar, the vectors are. 0 indicates the vectors are the same.
        Parameters:
        a - the first vector
        b - the second vector
        Returns:
        the distance between them
      • isSymmetric

        public boolean isSymmetric()
        Description copied from interface: DistanceMetric
        Returns true if this distance metric obeys the rule that, for any x, y, and z ∈ S
        d(x, y) = d(y, x)
        Returns:
        true if this distance metric is symmetric, false if it is not
      • isSubadditive

        public boolean isSubadditive()
        Description copied from interface: DistanceMetric
        Returns true if this distance metric obeys the rule that, for any x, y, and z ∈ S
        d(x, z) ≤ d(x, y) + d(y, z)
        Returns:
        true if this distance metric supports the triangle inequality, false if it does not.
      • isIndiscemible

        public boolean isIndiscemible()
        Description copied from interface: DistanceMetric
        Returns true if this distance metric obeys the rule that, for any x and y ∈ S
        d(x, y) = 0 if and only if x = y
        Returns:
        true if this distance metric is indicemible, false otherwise.
      • metricBound

        public double metricBound()
        Description copied from interface: DistanceMetric
        All metrics must return values greater than or equal to 0. The upper bound on the value returned is different for different metrics. This method returns the theoretical maximal value that could be returned by this distance metric. That means Double.POSITIVE_INFINITY is a valid return value.
        Returns:
        the maximal distance for any two points in that could exist by this distance metric.
      • toString

        public java.lang.String toString()
        Description copied from interface: DistanceMetric
        Returns a descriptive name of the Distance Metric in use
        Specified by:
        toString in interface DistanceMetric
        Overrides:
        toString in class java.lang.Object
        Returns:
        the name of this metric

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.