Class LibLinearTrainer<T extends Output<T>>
java.lang.Object
org.tribuo.common.liblinear.LibLinearTrainer<T>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable,com.oracle.labs.mlrg.olcut.provenance.Provenancable<TrainerProvenance>,Trainer<T>
A
Trainer which wraps a liblinear-java trainer.
See:
Fan RE, Chang KW, Hsieh CJ, Wang XR, Lin CJ. "LIBLINEAR: A library for Large Linear Classification" Journal of Machine Learning Research, 2008.and for the original algorithm:
Cortes C, Vapnik V. "Support-Vector Networks" Machine Learning, 1995.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleprotected doubleprotected de.bwaldvogel.liblinear.Parameterprotected intprotected longprotected doubleprotected LibLinearType<T> Fields inherited from interface org.tribuo.Trainer
DEFAULT_SEED, INCREMENT_INVOCATION_COUNT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFor OLCUTprotectedLibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion) Creates a trainer for a LibLinear modelprotectedLibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion, double epsilon) Creates a trainer for a LibLinear modelprotectedLibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion, double epsilon, long seed) Creates a trainer for a LibLinear modelprotectedLibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion, long seed) Creates a trainer for a LibLinear model -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract LibLinearModel<T> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<de.bwaldvogel.liblinear.Model> models) Construct the appropriate subtype of LibLinearModel for the prediction task.static <T extends Output<T>>
de.bwaldvogel.liblinear.FeatureNode[]exampleToNodes(Example<T> example, ImmutableFeatureMap featureIDMap, List<de.bwaldvogel.liblinear.FeatureNode> features) Converts a TribuoExampleinto a liblinearFeatureNodearray, including a bias feature.protected abstract com.oracle.labs.mlrg.olcut.util.Pair<de.bwaldvogel.liblinear.FeatureNode[][], double[][]> extractData(Dataset<T> data, ImmutableOutputInfo<T> outputInfo, ImmutableFeatureMap featureMap) Extracts the features andOutputs in LibLinear's format.intvoidUsed by the OLCUT configuration system, and should not be called by external code.voidsetInvocationCount(int invocationCount) protected de.bwaldvogel.liblinear.ParametersetupParameters(ImmutableOutputInfo<T> info) Constructs the parameters.toString()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) protected abstract List<de.bwaldvogel.liblinear.Model> trainModels(de.bwaldvogel.liblinear.Parameter curParams, int numFeatures, de.bwaldvogel.liblinear.FeatureNode[][] features, double[][] outputs) Train all the liblinear instances necessary for this dataset.
-
Field Details
-
libLinearParams
-
trainerType
-
cost
-
maxIterations
-
terminationCriterion
@Config(description="Stop iterating when the loss score decreases by less than this value.") protected double terminationCriterion -
epsilon
@Config(description="Epsilon insensitivity in the regression cost function.") protected double epsilon -
seed
-
-
Constructor Details
-
LibLinearTrainer
protected LibLinearTrainer()For OLCUT -
LibLinearTrainer
protected LibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion) Creates a trainer for a LibLinear modelUses
Trainer.DEFAULT_SEEDas the RNG seed, and 0.1 as epsilon.- Parameters:
trainerType- Loss function and optimisation method combination.cost- Cost penalty for each incorrectly classified training point.maxIterations- The maximum number of dataset iterations.terminationCriterion- How close does the optimisation function need to be before terminating that subproblem (usually set to 0.1).
-
LibLinearTrainer
protected LibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion, long seed) Creates a trainer for a LibLinear model- Parameters:
trainerType- Loss function and optimisation method combination.cost- Cost penalty for each incorrectly classified training point.maxIterations- The maximum number of dataset iterations.terminationCriterion- How close does the optimisation function need to be before terminating that subproblem (usually set to 0.1).
-
LibLinearTrainer
protected LibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion, double epsilon) Creates a trainer for a LibLinear modelUses
Trainer.DEFAULT_SEEDas the RNG seed.- Parameters:
trainerType- Loss function and optimisation method combination.cost- Cost penalty for each incorrectly classified training point.maxIterations- The maximum number of dataset iterations.terminationCriterion- How close does the optimisation function need to be before terminating that subproblem (usually set to 0.1).epsilon- The insensitivity of the regression loss to small differences.
-
LibLinearTrainer
protected LibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion, double epsilon, long seed) Creates a trainer for a LibLinear model- Parameters:
trainerType- Loss function and optimisation method combination.cost- Cost penalty for each incorrectly classified training point.maxIterations- The maximum number of dataset iterations.terminationCriterion- How close does the optimisation function need to be before terminating that subproblem (usually set to 0.1).epsilon- The insensitivity of the regression loss to small differences.seed- The RNG seed.
-
-
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
-
train
-
train
-
train
-
getInvocationCount
- Specified by:
getInvocationCountin interfaceTrainer<T extends Output<T>>
-
setInvocationCount
- Specified by:
setInvocationCountin interfaceTrainer<T extends Output<T>>
-
toString
-
trainModels
protected abstract List<de.bwaldvogel.liblinear.Model> trainModels(de.bwaldvogel.liblinear.Parameter curParams, int numFeatures, de.bwaldvogel.liblinear.FeatureNode[][] features, double[][] outputs) Train all the liblinear instances necessary for this dataset.- Parameters:
curParams- The LibLinear parameters.numFeatures- The number of features in this dataset.features- The features themselves.outputs- The outputs.- Returns:
- A list of liblinear models.
-
createModel
protected abstract LibLinearModel<T> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<de.bwaldvogel.liblinear.Model> models) Construct the appropriate subtype of LibLinearModel for the prediction task.- Parameters:
provenance- The model provenance.featureIDMap- The feature id map.outputIDInfo- The output id info.models- The list of linear models.- Returns:
- An implementation of LibLinearModel.
-
extractData
protected abstract com.oracle.labs.mlrg.olcut.util.Pair<de.bwaldvogel.liblinear.FeatureNode[][], double[][]> extractData(Dataset<T> data, ImmutableOutputInfo<T> outputInfo, ImmutableFeatureMap featureMap) Extracts the features andOutputs in LibLinear's format.- Parameters:
data- The input data.outputInfo- The output info.featureMap- The feature info.- Returns:
- The features and outputs.
-
setupParameters
Constructs the parameters. Most of the time this just clones the existing ones, but classification overrides it to incorporate label weights if they exist.- Parameters:
info- The output info.- Returns:
- The Parameters to use for training.
-
exampleToNodes
public static <T extends Output<T>> de.bwaldvogel.liblinear.FeatureNode[] exampleToNodes(Example<T> example, ImmutableFeatureMap featureIDMap, List<de.bwaldvogel.liblinear.FeatureNode> features) Converts a TribuoExampleinto a liblinearFeatureNodearray, including a bias feature.If there is a collision between feature ids (i.e., if there is feature hashing or some other mechanism changing the feature ids) then the feature values are summed.
- Type Parameters:
T- The output type.- Parameters:
example- The input example.featureIDMap- The feature id map which contains the example's indices.features- A buffer. If null then an array list is created and used internally.- Returns:
- The features suitable for use in liblinear.
-
getProvenance
-