Class AbstractSGDTrainer<T extends Output<T>, U, V extends Model<T>, X extends FeedForwardParameters>
java.lang.Object
org.tribuo.common.sgd.AbstractSGDTrainer<T,U,V,X>
- Type Parameters:
T- The output type.U- The intermediate representation of the labels.V- The model type.X- The parameter type.
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable,com.oracle.labs.mlrg.olcut.provenance.Provenancable<TrainerProvenance>,Trainer<T>,WeightedExamples
- Direct Known Subclasses:
AbstractFMTrainer,AbstractLinearSGDTrainer
public abstract class AbstractSGDTrainer<T extends Output<T>, U, V extends Model<T>, X extends FeedForwardParameters>
extends Object
implements Trainer<T>, WeightedExamples
A trainer for a model which uses SGD.
See:
Bottou L. "Large-Scale Machine Learning with Stochastic Gradient Descent" Proceedings of COMPSTAT, 2010.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected intprotected intprotected intprotected StochasticGradientOptimiserprotected SplittableRandomprotected longprotected booleanFields inherited from interface org.tribuo.Trainer
DEFAULT_SEED, INCREMENT_INVOCATION_COUNT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSGDTrainer(boolean addBias) Base constructor called by subclass no-args constructors used by OLCUT.protectedAbstractSGDTrainer(StochasticGradientOptimiser optimiser, int epochs, int loggingInterval, int minibatchSize, long seed, boolean addBias) Constructs an SGD trainer. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract VcreateModel(String name, ModelProvenance provenance, ImmutableFeatureMap featureMap, ImmutableOutputInfo<T> outputInfo, X parameters) Creates the appropriate model subclass for this subclass of AbstractSGDTrainer.protected abstract XcreateParameters(int numFeatures, int numOutputs, SplittableRandom localRNG) Constructs the trainable parameters object.intprotected abstract StringReturns the class name of the model that's produced by this trainer.protected abstract StringgetName()Returns the default model name.protected abstract SGDObjective<U> Returns the objective used by this trainer.protected abstract UgetTarget(ImmutableOutputInfo<T> outputInfo, T output) Extracts the appropriate training time representation from the supplied output.voidUsed by the OLCUT configuration system, and should not be called by external code.voidsetInvocationCount(int invocationCount) voidsetShuffle(boolean shuffle) Turn on or off shuffling of examples.static <T> voidshuffleInPlace(SGDVector[] features, T[] labels, double[] weights, SplittableRandom rng) Shuffles the features, outputs and weights in place.train(Dataset<T> examples, Map<String, com.oracle.labs.mlrg.olcut.provenance.Provenance> runProvenance) train(Dataset<T> examples, Map<String, com.oracle.labs.mlrg.olcut.provenance.Provenance> runProvenance, int invocationCount)
-
Field Details
-
optimiser
@Config(description="The gradient optimiser to use.") protected StochasticGradientOptimiser optimiser -
epochs
-
loggingInterval
-
minibatchSize
-
seed
-
shuffle
@Config(description="Shuffle the data before each epoch. Only turn off for debugging.") protected boolean shuffle -
addBias
-
rng
-
-
Constructor Details
-
AbstractSGDTrainer
protected AbstractSGDTrainer(StochasticGradientOptimiser optimiser, int epochs, int loggingInterval, int minibatchSize, long seed, boolean addBias) Constructs an SGD trainer.- Parameters:
optimiser- The gradient optimiser to use.epochs- The number of epochs (complete passes through the training data).loggingInterval- Log the loss after this many iterations. If -1 don't log anything.minibatchSize- The size of any minibatches.seed- A seed for the random number generator, used to shuffle the examples before each epoch.addBias- Should the model add a bias feature to the feature vector?
-
AbstractSGDTrainer
Base constructor called by subclass no-args constructors used by OLCUT.- Parameters:
addBias- Should the model add a bias feature to the feature vector?
-
-
Method Details
-
postConfig
Used by the OLCUT configuration system, and should not be called by external code.- Specified by:
postConfigin interfacecom.oracle.labs.mlrg.olcut.config.Configurable
-
setShuffle
Turn on or off shuffling of examples.This isn't exposed in the constructor as it defaults to on. This method should only be used for debugging.
- Parameters:
shuffle- If true shuffle the examples, if false leave them in their current order.
-
train
-
train
-
train
-
getInvocationCount
- Specified by:
getInvocationCountin interfaceTrainer<T extends Output<T>>
-
setInvocationCount
- Specified by:
setInvocationCountin interfaceTrainer<T extends Output<T>>
-
getTarget
Extracts the appropriate training time representation from the supplied output.- Parameters:
outputInfo- The output info to use.output- The output to extract.- Returns:
- The training time representation of the output.
-
getObjective
Returns the objective used by this trainer.- Returns:
- The SGDObjective used by this trainer.
-
createModel
protected abstract V createModel(String name, ModelProvenance provenance, ImmutableFeatureMap featureMap, ImmutableOutputInfo<T> outputInfo, X parameters) Creates the appropriate model subclass for this subclass of AbstractSGDTrainer.- Parameters:
name- The model name.provenance- The model provenance.featureMap- The feature map.outputInfo- The output info.parameters- The model parameters.- Returns:
- A new instance of the appropriate subclass of
Model.
-
getModelClassName
Returns the class name of the model that's produced by this trainer.- Returns:
- The model class name;
-
getName
-
createParameters
Constructs the trainable parameters object.- Parameters:
numFeatures- The number of input features.numOutputs- The number of output dimensions.localRNG- The RNG to use for parameter initialisation.- Returns:
- The trainable parameters.
-
getProvenance
-
shuffleInPlace
public static <T> void shuffleInPlace(SGDVector[] features, T[] labels, double[] weights, SplittableRandom rng) Shuffles the features, outputs and weights in place.- Type Parameters:
T- The output type.- Parameters:
features- Feature array.labels- Output array.weights- Weight array.rng- Random number generator.
-