Documentation of 'jsat.classifiers.svm.DCD' Java class
DCD
jsat.classifiers.svm

Class DCD

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, Parameterized, Regressor, SimpleWeightVectorModel, SingleWeightVectorModel


    public class DCD
    extends java.lang.Object
    implements BinaryScoreClassifier, Regressor, Parameterized, SingleWeightVectorModel
    Implements Dual Coordinate Descent (DCD) training algorithms for a Linear L1 or L2 Support Vector Machine for binary classification and regression. NOTE: While this implementation makes use of the dual formulation only the linear kernel is ever used. The algorithm also uses the primal representation and uses the explicit formulation of w in training and classification. As such, the support vectors found are not necessary once training is complete - and will be discarded.

    See:
    • Hsieh, C.-J., Chang, K.-W., Lin, C.-J., Keerthi, S. S.,&Sundararajan, S. (2008). A Dual Coordinate Descent Method for Large-scale Linear SVM. Proceedings of the 25th international conference on Machine learning - ICML ’08 (pp. 408–415). New York, New York, USA: ACM Press. doi:10.1145/1390156.1390208
    • Ho, C.-H.,&Lin, C.-J. (2012). Large-scale Linear Support Vector Regression. Journal of Machine Learning Research, 13, 3323–3348. Retrieved from here
    See Also:
    DCDs, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      DCD()
      Creates a new DCDL2 SVM object
      DCD(int maxIterations, boolean useL1)
      Creates a new DCD SVM object.
      DCD(int maxIterations, double C, boolean useL1)
      Creates a new DCD SVM object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      CategoricalResults classify(DataPoint data)
      Performs classification on the given data point.
      DCD clone() 
      double getBias()
      Returns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.
      double getBias(int index)
      Returns the bias term used with the weight vector for the given class index.
      double getC()
      Returns the penalty parameter for misclassifications.
      double getEps()
      Returns the epsilon insensitivity parameter used in regression problems.
      int getMaxIterations()
      Returns the maximum number of allowed training epochs
      Vec getRawWeight()
      Returns the only weight vector used for the model
      Vec getRawWeight(int index)
      Returns the raw weight vector associated with the given class index.
      double getScore(DataPoint dp)
      Returns the numeric score for predicting a class of a given data point, where the sign of the value indicates which class the data point is predicted to belong to.
      boolean isOnlineVersion()
      Returns whether or not the online version of the algorithm, algorithm 2 is in use.
      boolean isUseBias()
      Returns true if an implicit bias term is in use, or false if not.
      boolean isUseL1()
      Returns true if the L1 form is in use
      int numWeightsVecs()
      Returns the number of weight vectors that can be returned.
      double regress(DataPoint data) 
      void setC(double C)
      Sets the penalty parameter for misclassifications.
      void setEps(double eps)
      Sets the eps used in the epsilon insensitive loss function used when performing regression.
      void setMaxIterations(int maxIterations)
      Sets the maximum number of iterations allowed through the whole training set.
      void setOnlineVersion(boolean onlineVersion)
      By default, Algorithm 1 is used.
      void setUseBias(boolean useBias)
      Sets whether or not an implicit bias term should be added to the inputs.
      void setUseL1(boolean useL1)
      Determines whether or not to use the L1 or L2 SVM
      boolean supportsWeightedData()
      Indicates whether the model knows how to train using weighted data points.
      void train(ClassificationDataSet dataSet)
      Trains the classifier and constructs a model for classification using the given data set.
      void train(ClassificationDataSet dataSet, boolean parallel)
      Trains the classifier and constructs a model for classification using the given data set.
      void train(RegressionDataSet dataSet) 
      void train(RegressionDataSet dataSet, boolean parallel) 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DCD

        public DCD()
        Creates a new DCDL2 SVM object
      • DCD

        public DCD(int maxIterations,
                   boolean useL1)
        Creates a new DCD SVM object. The default C value of 1 is used as suggested in the original paper.
        Parameters:
        maxIterations - the maximum number of training iterations
        useL1 - whether or not to use L1 or L2 form
      • DCD

        public DCD(int maxIterations,
                   double C,
                   boolean useL1)
        Creates a new DCD SVM object
        Parameters:
        maxIterations - the maximum number of training iterations
        C - the misclassification penalty
        useL1 - whether or not to use L1 or L2 form
    • Method Detail

      • setOnlineVersion

        public void setOnlineVersion(boolean onlineVersion)
        By default, Algorithm 1 is used. Algorithm 2 is an "online" version that updates the dual form by only one data point at a time. This controls which version is used.
        Parameters:
        onlineVersion - false to use algorithm 1, true to use algorithm 2
      • isOnlineVersion

        public boolean isOnlineVersion()
        Returns whether or not the online version of the algorithm, algorithm 2 is in use.
        Returns:
        true if algorithm 2 is in use, false if algorithm 1
      • setEps

        public void setEps(double eps)
        Sets the eps used in the epsilon insensitive loss function used when performing regression. Errors in the output that less than eps during training are treated as correct.
        This parameter has no impact on classification problems.
        Parameters:
        eps - the non-negative value to use as the error tolerance in regression
      • getEps

        public double getEps()
        Returns the epsilon insensitivity parameter used in regression problems.
        Returns:
        the epsilon insensitivity parameter used in regression problems.
      • setC

        public void setC(double C)
        Sets the penalty parameter for misclassifications. The recommended value is 1, and values larger than 4 are not normally needed according to the original paper.
        Parameters:
        C - the penalty parameter in (0, Inf)
      • getC

        public double getC()
        Returns the penalty parameter for misclassifications.
        Returns:
        the penalty parameter for misclassifications.
      • setUseL1

        public void setUseL1(boolean useL1)
        Determines whether or not to use the L1 or L2 SVM
        Parameters:
        useL1 - true to use the L1 form, false to use the L2 form.
      • isUseL1

        public boolean isUseL1()
        Returns true if the L1 form is in use
        Returns:
        true if the L1 form is in use
      • setMaxIterations

        public void setMaxIterations(int maxIterations)
        Sets the maximum number of iterations allowed through the whole training set.
        Parameters:
        maxIterations - the maximum number of training epochs
      • getMaxIterations

        public int getMaxIterations()
        Returns the maximum number of allowed training epochs
        Returns:
        the maximum number of allowed training epochs
      • setUseBias

        public void setUseBias(boolean useBias)
        Sets whether or not an implicit bias term should be added to the inputs.
        Parameters:
        useBias - true to add an implicit bias term to inputs, false to use the input data as provided.
      • isUseBias

        public boolean isUseBias()
        Returns true if an implicit bias term is in use, or false if not.
        Returns:
        true if an implicit bias term is in use, or false if not.
      • getBias

        public double getBias()
        Description copied from interface: SingleWeightVectorModel
        Returns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.
        Specified by:
        getBias in interface SingleWeightVectorModel
        Returns:
        the bias term for the model
      • getRawWeight

        public Vec getRawWeight(int index)
        Description copied from interface: SimpleWeightVectorModel
        Returns the raw weight vector associated with the given class index. If the given class is an implicit zero vector, a ConstantVector object may be returned.
        Do not alter the returned weight vector, as it will change the model's values.

        If a regression problem, only index = 0 should be used
        Specified by:
        getRawWeight in interface SimpleWeightVectorModel
        Parameters:
        index - the class index to get the weight vector for
        Returns:
        the weight vector used for the specified class
      • getBias

        public double getBias(int index)
        Description copied from interface: SimpleWeightVectorModel
        Returns the bias term used with the weight vector for the given class index. If the model does not support or was not trained with bias weights, 0 will be returned.

        If a regression problem, only index = 0 should be used
        Specified by:
        getBias in interface SimpleWeightVectorModel
        Parameters:
        index - the class index to get the weight vector for
        Returns:
        the bias term for the specified class
      • numWeightsVecs

        public int numWeightsVecs()
        Description copied from interface: SimpleWeightVectorModel
        Returns the number of weight vectors that can be returned. For binary classification problems the value may be 1 if only a single weight vector's sign is used to determine the class. For multi-class problems, the weight vector count includes the implicit zero vector (if one is being used).
        Specified by:
        numWeightsVecs in interface SimpleWeightVectorModel
        Returns:
        the number of weight vectors for which SimpleWeightVectorModel.getRawWeight(int) can be called.
      • classify

        public CategoricalResults classify(DataPoint data)
        Description copied from interface: Classifier
        Performs classification on the given data point.
        Specified by:
        classify in interface Classifier
        Parameters:
        data - the data point to classify
        Returns:
        the results of the classification.
      • getScore

        public double getScore(DataPoint dp)
        Description copied from interface: BinaryScoreClassifier
        Returns the numeric score for predicting a class of a given data point, where the sign of the value indicates which class the data point is predicted to belong to.
        Specified by:
        getScore in interface BinaryScoreClassifier
        Parameters:
        dp - the data point to predict the class label of
        Returns:
        the score for the given data point
      • train

        public void train(ClassificationDataSet dataSet,
                          boolean parallel)
        Description copied from interface: Classifier
        Trains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.
        Specified by:
        train in interface Classifier
        Parameters:
        dataSet - the data set to train on
        parallel - true if multiple threads should be used to train the model. false if it should be done in a single threaded manner.
      • train

        public void train(ClassificationDataSet dataSet)
        Description copied from interface: Classifier
        Trains the classifier and constructs a model for classification using the given data set.
        Specified by:
        train in interface Classifier
        Parameters:
        dataSet - the data set to train on
      • supportsWeightedData

        public boolean supportsWeightedData()
        Description copied from interface: Classifier
        Indicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.
        Specified by:
        supportsWeightedData in interface Classifier
        Specified by:
        supportsWeightedData in interface Regressor
        Returns:
        true if the model supports weighted data, false otherwise

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.