jsat.regression
Class StochasticRidgeRegression
- java.lang.Object
-
- jsat.regression.StochasticRidgeRegression
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Parameterized, Regressor, SimpleWeightVectorModel, SingleWeightVectorModel
public class StochasticRidgeRegression extends java.lang.Object implements Regressor, Parameterized, SingleWeightVectorModel
A Stochastic implementation of Ridge Regression. Ridge Regression is equivalent toMultipleLinearRegressionwith an added L2 penalty for the weight vector.
This algorithm works best for problems with a large number of data points or very high dimensional problems.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description StochasticRidgeRegression(double lambda, int epochs, int batchSize, double learningRate)Creates a new stochastic Ridge Regression learner that does not use a decay rateStochasticRidgeRegression(double lambda, int epochs, int batchSize, double learningRate, DecayRate learningDecay)Creates a new stochastic Ridge Regression learner
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description StochasticRidgeRegressionclone()intgetBatchSize()Returns the batch size for updatesdoublegetBias()Returns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.doublegetBias(int index)Returns the bias term used with the weight vector for the given class index.intgetEpochs()Returns the number of training iterationsdoublegetLambda()Returns the regularization constant in useDecayRategetLearningDecay()Returns the learning decay rate useddoublegetLearningRate()Returns the learning rate in use.VecgetRawWeight()Returns the only weight vector used for the modelVecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.intnumWeightsVecs()Returns the number of weight vectors that can be returned.doubleregress(DataPoint data)voidsetBatchSize(int batchSize)Sets the batch size to learn from.voidsetEpochs(int epochs)Sets the number of iterations through the whole training set that will be performed.voidsetLambda(double lambda)Sets the regularization parameter used.voidsetLearningDecay(DecayRate learningDecay)Sets the learning rate decay function to use.voidsetLearningRate(double learningRate)Sets the learning rate used, and should be in the range (0, 1).booleansupportsWeightedData()voidtrain(RegressionDataSet dataSet)voidtrain(RegressionDataSet dataSet, boolean parallel)-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
StochasticRidgeRegression
public StochasticRidgeRegression(double lambda, int epochs, int batchSize, double learningRate)Creates a new stochastic Ridge Regression learner that does not use a decay rate- Parameters:
lambda- the regularization termepochs- the number of training epochs to performbatchSize- the batch size for updateslearningRate- the learning rate
-
StochasticRidgeRegression
public StochasticRidgeRegression(double lambda, int epochs, int batchSize, double learningRate, DecayRate learningDecay)Creates a new stochastic Ridge Regression learner- Parameters:
lambda- the regularization termepochs- the number of training epochs to performbatchSize- the batch size for updateslearningRate- the learning ratelearningDecay- the learning rate decay
-
-
Method Detail
-
setLambda
public void setLambda(double lambda)
Sets the regularization parameter used.- Parameters:
lambda- the positive regularization constant in (0, Inf)
-
getLambda
public double getLambda()
Returns the regularization constant in use- Returns:
- the regularization constant in use
-
setLearningRate
public void setLearningRate(double learningRate)
Sets the learning rate used, and should be in the range (0, 1).- Parameters:
learningRate- the learning rate to use
-
getLearningRate
public double getLearningRate()
Returns the learning rate in use.- Returns:
- the learning rate to use.
-
setLearningDecay
public void setLearningDecay(DecayRate learningDecay)
Sets the learning rate decay function to use. The decay is applied after each epoch through the data set. Using a decay rate can reduce the time to converge and quality of the solution for difficult problems.- Parameters:
learningDecay- the decay function to apply to the learning rate
-
getLearningDecay
public DecayRate getLearningDecay()
Returns the learning decay rate used- Returns:
- the learning decay rate used
-
setBatchSize
public void setBatchSize(int batchSize)
Sets the batch size to learn from. If larger than the training set, the problem will reduce to classic gradient descent.- Parameters:
batchSize- the number of training points to use in each batch update
-
getBatchSize
public int getBatchSize()
Returns the batch size for updates- Returns:
- the batch size for updates
-
setEpochs
public void setEpochs(int epochs)
Sets the number of iterations through the whole training set that will be performed.- Parameters:
epochs- the number of training iterations
-
getEpochs
public int getEpochs()
Returns the number of training iterations- Returns:
- the number of training iterations
-
getRawWeight
public Vec getRawWeight()
Description copied from interface:SingleWeightVectorModelReturns the only weight vector used for the model- Specified by:
getRawWeightin interfaceSingleWeightVectorModel- Returns:
- the only weight vector used for the model
-
getBias
public double getBias()
Description copied from interface:SingleWeightVectorModelReturns 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:
getBiasin interfaceSingleWeightVectorModel- Returns:
- the bias term for the model
-
getRawWeight
public Vec getRawWeight(int index)
Description copied from interface:SimpleWeightVectorModelReturns the raw weight vector associated with the given class index. If the given class is an implicit zero vector, aConstantVectorobject may be returned.
Do not alter the returned weight vector, as it will change the model's values.
If a regression problem, onlyindex = 0should be used- Specified by:
getRawWeightin interfaceSimpleWeightVectorModel- 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:SimpleWeightVectorModelReturns 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,0will be returned.
If a regression problem, onlyindex = 0should be used- Specified by:
getBiasin interfaceSimpleWeightVectorModel- 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:SimpleWeightVectorModelReturns 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:
numWeightsVecsin interfaceSimpleWeightVectorModel- Returns:
- the number of weight vectors for which
SimpleWeightVectorModel.getRawWeight(int)can be called.
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
train
public void train(RegressionDataSet dataSet)
-
supportsWeightedData
public boolean supportsWeightedData()
- Specified by:
supportsWeightedDatain interfaceRegressor
-
clone
public StochasticRidgeRegression clone()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG