Package org.tribuo.anomaly.liblinear
Class LibLinearAnomalyTrainer
java.lang.Object
org.tribuo.common.liblinear.LibLinearTrainer<Event>
org.tribuo.anomaly.liblinear.LibLinearAnomalyTrainer
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable
,com.oracle.labs.mlrg.olcut.provenance.Provenancable<TrainerProvenance>
,Trainer<Event>
A
Trainer
which wraps a liblinear-java anomaly detection trainer using a one-class SVM.
See:
Fan RE, Chang KW, Hsieh CJ, Wang XR, Lin CJ. "LIBLINEAR: A library for Large Linear Anomaly" Journal of Machine Learning Research, 2008.and for the original algorithm:
Cortes C, Vapnik V. "Support-Vector Networks" Machine Learning, 1995.
-
Field Summary
Fields inherited from class org.tribuo.common.liblinear.LibLinearTrainer
cost, epsilon, libLinearParams, maxIterations, seed, terminationCriterion, trainerType
Fields inherited from interface org.tribuo.Trainer
DEFAULT_SEED, INCREMENT_INVOCATION_COUNT
-
Constructor Summary
ConstructorDescriptionCreates a trainer using the default values (type:ONECLASS_SVM, cost:1, maxIterations:1000, terminationCriterion:0.1, nu:0.5).LibLinearAnomalyTrainer
(double nu) Creates a trainer using the default values (type:ONECLASS_SVM, cost:1, maxIterations:1000, terminationCriterion:0.1) and the specified nu.LibLinearAnomalyTrainer
(LinearAnomalyType trainerType, double cost, double terminationCriterion, double nu) Creates a trainer for a LibLinearAnomalyModel.LibLinearAnomalyTrainer
(LinearAnomalyType trainerType, double cost, int maxIterations, double terminationCriterion, double nu) Creates a trainer for a LibLinear modelLibLinearAnomalyTrainer
(LinearAnomalyType trainerType, double cost, int maxIterations, double terminationCriterion, double nu, long seed) Creates a trainer for a LibLinear model -
Method Summary
Modifier and TypeMethodDescriptionprotected LibLinearModel<Event>
createModel
(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<Event> outputIDInfo, List<de.bwaldvogel.liblinear.Model> models) Construct the appropriate subtype of LibLinearModel for the prediction task.protected com.oracle.labs.mlrg.olcut.util.Pair<de.bwaldvogel.liblinear.FeatureNode[][],
double[][]> extractData
(Dataset<Event> data, ImmutableOutputInfo<Event> outputInfo, ImmutableFeatureMap featureMap) Extracts the features andOutput
s in LibLinear's format.void
Used by the OLCUT configuration system, and should not be called by external code.protected de.bwaldvogel.liblinear.Parameter
setupParameters
(ImmutableOutputInfo<Event> labelIDMap) Constructs the parameters.protected 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.Methods inherited from class org.tribuo.common.liblinear.LibLinearTrainer
exampleToNodes, getInvocationCount, getProvenance, setInvocationCount, toString, train, train, train
-
Constructor Details
-
LibLinearAnomalyTrainer
public LibLinearAnomalyTrainer()Creates a trainer using the default values (type:ONECLASS_SVM, cost:1, maxIterations:1000, terminationCriterion:0.1, nu:0.5). -
LibLinearAnomalyTrainer
public LibLinearAnomalyTrainer(double nu) Creates a trainer using the default values (type:ONECLASS_SVM, cost:1, maxIterations:1000, terminationCriterion:0.1) and the specified nu.- Parameters:
nu
- The nu parameter in the one-class SVM.
-
LibLinearAnomalyTrainer
public LibLinearAnomalyTrainer(LinearAnomalyType trainerType, double cost, double terminationCriterion, double nu) Creates a trainer for a LibLinearAnomalyModel. Sets maxIterations to 1000.- Parameters:
trainerType
- Loss function and optimisation method combination.cost
- Cost penalty for each incorrectly classified training point.terminationCriterion
- How close does the optimisation function need to be before terminating that subproblem (usually set to 0.1).nu
- The nu parameter in the one-class SVM.
-
LibLinearAnomalyTrainer
public LibLinearAnomalyTrainer(LinearAnomalyType trainerType, double cost, int maxIterations, double terminationCriterion, double nu) Creates a trainer for a LibLinear modelUses
Trainer.DEFAULT_SEED
as 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).nu
- The nu parameter in the one-class SVM.
-
LibLinearAnomalyTrainer
public LibLinearAnomalyTrainer(LinearAnomalyType trainerType, double cost, int maxIterations, double terminationCriterion, double nu, 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).nu
- The nu parameter in the one-class SVM.seed
- The RNG seed.
-
-
Method Details
-
postConfig
public void postConfig()Used by the OLCUT configuration system, and should not be called by external code.- Specified by:
postConfig
in interfacecom.oracle.labs.mlrg.olcut.config.Configurable
- Overrides:
postConfig
in classLibLinearTrainer<Event>
-
setupParameters
Description copied from class:LibLinearTrainer
Constructs the parameters. Most of the time this just clones the existing ones, but classification overrides it to incorporate label weights if they exist.- Overrides:
setupParameters
in classLibLinearTrainer<Event>
- Parameters:
labelIDMap
- The output info.- Returns:
- The Parameters to use for training.
-
trainModels
protected List<de.bwaldvogel.liblinear.Model> trainModels(de.bwaldvogel.liblinear.Parameter curParams, int numFeatures, de.bwaldvogel.liblinear.FeatureNode[][] features, double[][] outputs) Description copied from class:LibLinearTrainer
Train all the liblinear instances necessary for this dataset.- Specified by:
trainModels
in classLibLinearTrainer<Event>
- 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 LibLinearModel<Event> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<Event> outputIDInfo, List<de.bwaldvogel.liblinear.Model> models) Description copied from class:LibLinearTrainer
Construct the appropriate subtype of LibLinearModel for the prediction task.- Specified by:
createModel
in classLibLinearTrainer<Event>
- 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 com.oracle.labs.mlrg.olcut.util.Pair<de.bwaldvogel.liblinear.FeatureNode[][],double[][]> extractData(Dataset<Event> data, ImmutableOutputInfo<Event> outputInfo, ImmutableFeatureMap featureMap) Description copied from class:LibLinearTrainer
Extracts the features andOutput
s in LibLinear's format.- Specified by:
extractData
in classLibLinearTrainer<Event>
- Parameters:
data
- The input data.outputInfo
- The output info.featureMap
- The feature info.- Returns:
- The features and outputs.
-