jsat.classifiers.linear
Class LinearBatch
- java.lang.Object
-
- jsat.classifiers.linear.LinearBatch
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, WarmClassifier, Parameterized, Regressor, WarmRegressor, SimpleWeightVectorModel
public class LinearBatch extends java.lang.Object implements Classifier, Regressor, Parameterized, SimpleWeightVectorModel, WarmClassifier, WarmRegressor
LinearBatch learns either a classification or regression problem depending on theloss function ℓ(w,x)used. The solution attempts to minimize ∑i ℓ(w,xi) +λ0/2 ||w||22, and is trained using a batch optimization method.
LinearBatch can be warm started from any model implementing theSimpleWeightVectorModelinterface.
Note: the current implementation does not currently use bias terms- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description classLinearBatch.GradFunctionclassLinearBatch.LossFunctionclassLinearBatch.LossMCFunction
-
Constructor Summary
Constructors Constructor and Description LinearBatch()Creates a new Linear Batch learner for classification using a small regularization termLinearBatch(LinearBatch toCopy)Copy constructorLinearBatch(LossFunc loss, double lambda0)Creates a new Linear Batch learnerLinearBatch(LossFunc loss, double lambda0, double tolerance)Creates a new Linear Batch learnerLinearBatch(LossFunc loss, double lambda0, double tolerance, Optimizer optimizer)Creates a new Linear Batch learner
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.LinearBatchclone()doublegetBias(int index)Returns the bias term used with the weight vector for the given class index.doublegetLambda0()Returns the L2 regularization term in useLossFuncgetLoss()Returns the loss function in useOptimizergetOptimizer()Returns the optimization method in use, ornull.VecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.doublegetTolerance()Returns the value of the convergence tolerance parameterstatic DistributionguessLambda0(DataSet d)Guess the distribution to use for the regularization termλ0.booleanisUseBiasTerm()intnumWeightsVecs()Returns the number of weight vectors that can be returned.doubleregress(DataPoint data)voidsetLambda0(double lambda0)λ0 controls the L2 regularization penalty.voidsetLoss(LossFunc loss)Sets the loss function used for the model.voidsetOptimizer(Optimizer optimizer)Sets the method of batch optimization that will be used.voidsetTolerance(double tolerance)Sets the convergence tolerance to user for training.voidsetUseBiasTerm(boolean useBiasTerm)booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet D, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet D, Classifier warmSolution, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet D, boolean parallel)voidtrain(RegressionDataSet dataSet, Regressor warmSolution)Trains the regressor and constructs a model for regression using the given data set.voidtrain(RegressionDataSet D, Regressor warmSolution, boolean parallel)Trains the regressor and constructs a model for regression using the given data set.booleanwarmFromSameDataOnly()Some models can only be warm started from a solution trained on the exact same data set as the model it is warm starting from.-
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
-
Methods inherited from interface jsat.classifiers.WarmClassifier
train
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
-
-
-
Constructor Detail
-
LinearBatch
public LinearBatch()
Creates a new Linear Batch learner for classification using a small regularization term
-
LinearBatch
public LinearBatch(LossFunc loss, double lambda0)
Creates a new Linear Batch learner- Parameters:
loss- the loss function to uselambda0- the L2 regularization term
-
LinearBatch
public LinearBatch(LossFunc loss, double lambda0, double tolerance)
Creates a new Linear Batch learner- Parameters:
loss- the loss function to uselambda0- the L2 regularization termtolerance- the threshold for convergence
-
LinearBatch
public LinearBatch(LossFunc loss, double lambda0, double tolerance, Optimizer optimizer)
Creates a new Linear Batch learner- Parameters:
loss- the loss function to uselambda0- the L2 regularization termtolerance- the threshold for convergenceoptimizer- the batch optimization method to use
-
LinearBatch
public LinearBatch(LinearBatch toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setUseBiasTerm
public void setUseBiasTerm(boolean useBiasTerm)
-
isUseBiasTerm
public boolean isUseBiasTerm()
-
setLambda0
public void setLambda0(double lambda0)
λ0 controls the L2 regularization penalty.- Parameters:
lambda0- the L2 regularization penalty to use
-
getLambda0
public double getLambda0()
Returns the L2 regularization term in use- Returns:
- the L2 regularization term in use
-
setLoss
public void setLoss(LossFunc loss)
Sets the loss function used for the model. The loss function controls whether or not regression, binary classification, or multi-class classification is supported.- Parameters:
loss- the loss function to use
-
getLoss
public LossFunc getLoss()
Returns the loss function in use- Returns:
- the loss function in use
-
setOptimizer
public void setOptimizer(Optimizer optimizer)
Sets the method of batch optimization that will be used.nullis valid for this value, in which case the implementation will attempt to select a reasonable optimizer automatically.
NOTE: the current implementation requires the optimizer to work based off only the function value and its derivative.- Parameters:
optimizer- the method to use for function minimization
-
getOptimizer
public Optimizer getOptimizer()
Returns the optimization method in use, ornull.- Returns:
- the optimization method in use, or
null.
-
setTolerance
public void setTolerance(double tolerance)
Sets the convergence tolerance to user for training. Smaller values reach a more accuracy solution but may take longer to complete.
While zero is a valid tolerance value, it is not usually useful in practice. Values in [10-4, 10-2] are usually more practical.- Parameters:
tolerance- the convergence tolerance
-
getTolerance
public double getTolerance()
Returns the value of the convergence tolerance parameter- Returns:
- the convergence tolerance parameter
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
train
public void train(ClassificationDataSet D, boolean parallel)
Description copied from interface:ClassifierTrains 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:
trainin interfaceClassifier- Parameters:
D- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
train
public void train(ClassificationDataSet D, Classifier warmSolution, boolean parallel)
Description copied from interface:WarmClassifierTrains 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:
trainin interfaceWarmClassifier- Parameters:
D- the data set to train onwarmSolution- the solution to use to warm start this modelparallel-trueif the training should be done using multiple-cores,falsefor single threaded.
-
train
public void train(RegressionDataSet D, boolean parallel)
-
train
public void train(RegressionDataSet dataSet, Regressor warmSolution)
Description copied from interface:WarmRegressorTrains the regressor and constructs a model for regression using the given data set.- Specified by:
trainin interfaceWarmRegressor- Parameters:
dataSet- the data set to train onwarmSolution- the solution to use to warm start this model
-
train
public void train(RegressionDataSet D, Regressor warmSolution, boolean parallel)
Description copied from interface:WarmRegressorTrains the regressor and constructs a model for regression 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:
trainin interfaceWarmRegressor- Parameters:
D- the data set to train onwarmSolution- the solution to use to warm start this modelparallel-trueif the training should be done using multiple-cores,falsefor single threaded.
-
warmFromSameDataOnly
public boolean warmFromSameDataOnly()
Description copied from interface:WarmClassifierSome models can only be warm started from a solution trained on the exact same data set as the model it is warm starting from. If this is the casetruewill be returned. The behavior for training on a different data set when this is defined is undefined. It may cause an error, or it may cause the algorithm to take longer or reach a worse solution.
Whentrue, it is important that the data set be unaltered - this includes mutating the values stored or re-arranging the data points within the data set.- Specified by:
warmFromSameDataOnlyin interfaceWarmClassifier- Specified by:
warmFromSameDataOnlyin interfaceWarmRegressor- Returns:
trueif the algorithm can only be warm started from the model trained on the exact same data set.
-
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.
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates 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:
supportsWeightedDatain interfaceClassifier- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
clone
public LinearBatch clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
guessLambda0
public static Distribution guessLambda0(DataSet d)
Guess the distribution to use for the regularization termλ0.- Parameters:
d- the data set to get the guess for- Returns:
- the guess for the λ0 parameter
-
-
DataMelt 3.0 © DataMelt by jWork.ORG