Class LibLinearModel<T extends Output<T>>

java.lang.Object
org.tribuo.Model<T>
org.tribuo.common.liblinear.LibLinearModel<T>
All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>, Serializable, ProtoSerializable<org.tribuo.protos.core.ModelProto>
Direct Known Subclasses:
LibLinearAnomalyModel, LibLinearClassificationModel, LibLinearRegressionModel

public abstract class LibLinearModel<T extends Output<T>> extends Model<T>
A Model which wraps a LibLinear-java model.

It disables the LibLinear debug output as it's very chatty.

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.
 
See Also:
  • Field Details

    • CURRENT_VERSION

      public static final int CURRENT_VERSION
      Protobuf serialization version.
      See Also:
    • models

      protected List<de.bwaldvogel.liblinear.Model> models
      The list of LibLinear models. Multiple models are used by multi-label and multidimensional regression outputs.

      Not final to support deserialization reordering of multidimensional regression models which have an incorrect id mapping. Will be final again in some future version which doesn't maintain serialization compatibility with 4.X.

  • Constructor Details

    • LibLinearModel

      protected LibLinearModel(String name, ModelProvenance description, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> labelIDMap, boolean generatesProbabilities, List<de.bwaldvogel.liblinear.Model> models)
      Constructs a LibLinear model from the supplied arguments.
      Parameters:
      name - The model name.
      description - The model provenance.
      featureIDMap - The features this model knows about.
      labelIDMap - The outputs this model produces.
      generatesProbabilities - Does this model generate probabilities?
      models - The liblinear models themselves.
  • Method Details

    • getInnerModels

      public List<de.bwaldvogel.liblinear.Model> getInnerModels()
      Returns an unmodifiable list containing a copy of each model.

      As liblinear-java models don't expose a copy constructor this requires serializing each model to a String and rebuilding it, and is thus quite expensive.

      Returns:
      A copy of all of the models.
    • getExcuse

      public Optional<Excuse<T>> getExcuse(Example<T> e)
      This call is expensive as it copies out the weight matrix from the LibLinear model.

      Prefer getExcuses(java.lang.Iterable<org.tribuo.Example<T>>) to get multiple excuses.

      Specified by:
      getExcuse in class Model<T extends Output<T>>
      Parameters:
      e - The example to excuse.
      Returns:
      An Excuse for this example.
    • getExcuses

      public Optional<List<Excuse<T>>> getExcuses(Iterable<Example<T>> examples)
      Description copied from class: Model
      Generates an excuse for each example.

      This may be an expensive operation, and probably should be overridden in subclasses for performance reasons.

      These excuses either contain per class information or an entry with key Model.ALL_OUTPUTS.

      The optional is empty if the model does not provide excuses.

      Overrides:
      getExcuses in class Model<T extends Output<T>>
      Parameters:
      examples - An iterable of examples
      Returns:
      A optional list of excuses. The Optional is empty if this model does not provide excuses.
    • copyModel

      protected static de.bwaldvogel.liblinear.Model copyModel(de.bwaldvogel.liblinear.Model model)
      Copies the model by writing it out to a String and loading it back in.

      Unfortunately liblinear-java doesn't have a copy constructor on it's model.

      Parameters:
      model - The model to copy.
      Returns:
      A deep copy of the model.
    • getFeatureWeights

      protected abstract double[][] getFeatureWeights()
      Extracts the feature weights from the models. The first dimension corresponds to the model index.
      Returns:
      The feature weights.
    • innerGetExcuse

      protected abstract Excuse<T> innerGetExcuse(Example<T> e, double[][] featureWeights)
      The call to getFeatureWeights in the public methods copies the weights array so this inner method exists to save the copy in getExcuses.

      If it becomes a problem then we could cache the feature weights in the model.

      Parameters:
      e - The example.
      featureWeights - The per dimension feature weights.
      Returns:
      An excuse for this example.
    • serialize

      public org.tribuo.protos.core.ModelProto serialize()
      Description copied from interface: ProtoSerializable
      Serializes this object to a protobuf.
      Specified by:
      serialize in interface ProtoSerializable<T extends Output<T>>
      Overrides:
      serialize in class Model<T extends Output<T>>
      Returns:
      The protobuf.