Class LibSVMAnomalyTrainer

All Implemented Interfaces:,<TrainerProvenance>, Trainer<Event>

public class LibSVMAnomalyTrainer extends LibSVMTrainer<Event>
A trainer for anomaly models that uses LibSVM.

Note the train method is synchronized on LibSVMTrainer.class due to a global RNG in LibSVM. This is insufficient to ensure reproducibility if LibSVM is used directly in the same JVM as Tribuo, but avoids locking on classes Tribuo does not control.


 Chang CC, Lin CJ.
 "LIBSVM: a library for Support Vector Machines"
 ACM transactions on intelligent systems and technology (TIST), 2011.

and for the anomaly detection algorithm:

 Schölkopf B, Platt J, Shawe-Taylor J, Smola A J, Williamson R C.
 "Estimating the support of a high-dimensional distribution"
 Neural Computation, 2001, 1443-1471.
  • Constructor Details

    • LibSVMAnomalyTrainer

      protected LibSVMAnomalyTrainer()
      For OLCUT.
    • LibSVMAnomalyTrainer

      public LibSVMAnomalyTrainer(SVMParameters<Event> parameters)
      Creates a one-class LibSVM trainer using the supplied parameters and Trainer.DEFAULT_SEED.
      parameters - The SVM training parameters.
    • LibSVMAnomalyTrainer

      public LibSVMAnomalyTrainer(SVMParameters<Event> parameters, long seed)
      Creates a one-class LibSVM trainer using the supplied parameters and RNG seed.
      parameters - The SVM parameters.
      seed - The RNG seed for LibSVM's internal RNG.
  • Method Details

    • postConfig

      public void postConfig()
      Used by the OLCUT configuration system, and should not be called by external code.
      Specified by:
      postConfig in interface
      postConfig in class LibSVMTrainer<Event>
    • train

      public LibSVMModel<Event> train(Dataset<Event> dataset, Map<String,> instanceProvenance)
      Description copied from interface: Trainer
      Trains a predictive model using the examples in the given data set.
      Specified by:
      train in interface Trainer<Event>
      train in class LibSVMTrainer<Event>
      dataset - the data set containing the examples.
      instanceProvenance - Training run specific provenance (e.g., fold number).
      a predictive model that can be used to generate predictions for new examples.
    • createModel

      protected LibSVMModel<Event> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<Event> outputIDInfo, List<libsvm.svm_model> models)
      Description copied from class: LibSVMTrainer
      Construct the appropriate subtype of LibSVMModel for the prediction task.
      Specified by:
      createModel in class LibSVMTrainer<Event>
      provenance - The model provenance.
      featureIDMap - The feature id map.
      outputIDInfo - The output id info.
      models - The svm models.
      An implementation of LibSVMModel.
    • trainModels

      protected List<libsvm.svm_model> trainModels(libsvm.svm_parameter curParams, int numFeatures, libsvm.svm_node[][] features, double[][] outputs, SplittableRandom localRNG)
      Description copied from class: LibSVMTrainer
      Train all the LibSVM instances necessary for this dataset.
      Specified by:
      trainModels in class LibSVMTrainer<Event>
      curParams - The LibSVM parameters.
      numFeatures - The number of features in this dataset.
      features - The features themselves.
      outputs - The outputs.
      localRNG - The RNG to use for seeding LibSVM's RNG.
      A list of LibSVM models.
    • extractData

      protected<libsvm.svm_node[][],double[][]> extractData(Dataset<Event> data, ImmutableOutputInfo<Event> outputInfo, ImmutableFeatureMap featureMap)
      Description copied from class: LibSVMTrainer
      Extracts the features and Outputs in LibSVM's format.
      Specified by:
      extractData in class LibSVMTrainer<Event>
      data - The input data.
      outputInfo - The output info.
      featureMap - The feature info.
      The features and outputs.
    • extractOutput

      protected double extractOutput(Event output)
      Converts an output into a double for use in training.

      By convention Event.EventType.EXPECTED is 1.0, other events are -1.0.

      output - The output to convert.
      The double value.