Class SGDMultiClass

    • Field Detail

      • m_lambda

        protected double m_lambda
        The regularization parameter
      • lambdaRegularizationOption

        public FloatOption lambdaRegularizationOption
      • m_learningRate

        protected double m_learningRate
        The learning rate
      • learningRateOption

        public FloatOption learningRateOption
      • m_weights

        protected DoubleVector[] m_weights
        Stores the weights (+ bias in the last element)
      • m_bias

        protected double[] m_bias
      • m_t

        protected double m_t
        Holds the current iteration number
      • m_numInstances

        protected double m_numInstances
        The number of training instances
      • m_loss

        protected int m_loss
        The current loss function to minimize
    • Constructor Detail

      • SGDMultiClass

        public SGDMultiClass()
    • Method Detail

      • setLambda

        public void setLambda​(double lambda)
        Set the value of lambda to use
        Parameters:
        lambda - the value of lambda to use
      • getLambda

        public double getLambda()
        Get the current value of lambda
        Returns:
        the current value of lambda
      • setLossFunction

        public void setLossFunction​(int function)
        Set the loss function to use.
        Parameters:
        function - the loss function to use.
      • getLossFunction

        public int getLossFunction()
        Get the current loss function.
        Returns:
        the current loss function.
      • setLearningRate

        public void setLearningRate​(double lr)
        Set the learning rate.
        Parameters:
        lr - the learning rate to use.
      • getLearningRate

        public double getLearningRate()
        Get the learning rate.
        Returns:
        the learning rate
      • reset

        public void reset()
        Reset the classifier.
      • dloss

        protected double dloss​(double z)
      • dotProd

        protected static double dotProd​(Instance inst1,
                                        DoubleVector weights,
                                        int classIndex)
      • resetLearningImpl

        public void resetLearningImpl()
        Description copied from class: AbstractClassifier
        Resets this classifier. It must be similar to starting a new classifier from scratch.

        The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.
        Specified by:
        resetLearningImpl in class AbstractClassifier
      • trainOnInstanceImpl

        public void trainOnInstanceImpl​(Instance instance)
        Trains the classifier with the given instance.
        Specified by:
        trainOnInstanceImpl in class AbstractClassifier
        Parameters:
        instance - the new training instance to include in the model
      • trainOnInstanceImpl

        public void trainOnInstanceImpl​(Instance instance,
                                        int classLabel)
      • getVotesForInstance

        public double[] getVotesForInstance​(Instance inst)
        Calculates the class membership probabilities for the given test instance.
        Specified by:
        getVotesForInstance in interface Classifier
        Specified by:
        getVotesForInstance in class AbstractClassifier
        Parameters:
        inst - the instance to be classified
        Returns:
        predicted class probability distribution
      • getModelDescription

        public void getModelDescription​(StringBuilder result,
                                        int indent)
        Description copied from class: AbstractClassifier
        Returns a string representation of the model.
        Specified by:
        getModelDescription in class AbstractClassifier
        Parameters:
        result - the stringbuilder to add the description
        indent - the number of characters to indent
      • toString

        public String toString()
        Prints out the classifier.
        Overrides:
        toString in class AbstractMOAObject
        Returns:
        a description of the classifier as a string
      • getModelMeasurementsImpl

        protected Measurement[] getModelMeasurementsImpl()
        Description copied from class: AbstractClassifier
        Gets the current measurements of this classifier.

        The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.
        Specified by:
        getModelMeasurementsImpl in class AbstractClassifier
        Returns:
        an array of measurements to be used in evaluation tasks
      • isRandomizable

        public boolean isRandomizable()
        Description copied from interface: Learner
        Gets whether this learner needs a random seed. Examples of methods that needs a random seed are bagging and boosting.
        Specified by:
        isRandomizable in interface Learner<Example<Instance>>
        Returns:
        true if the learner needs a random seed.