Class WeightedEnsembleModel<T extends Output<T>>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>,Serializable,ONNXExportable,ProtoSerializable<org.tribuo.protos.core.ModelProto>
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final EnsembleCombiner<T> The ensemble combination function.static final intProtobuf serialization version.protected final float[]The ensemble member combination weights.Fields inherited from class org.tribuo.ensemble.EnsembleModel
modelsFields inherited from class org.tribuo.Model
ALL_OUTPUTS, BIAS_FEATURE, featureIDMap, generatesProbabilities, name, outputIDInfo, provenance, provenanceOutputFields inherited from interface org.tribuo.ONNXExportable
PROVENANCE_METADATA_FIELD, SERIALIZERFields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER -
Constructor Summary
ConstructorsConstructorDescriptionWeightedEnsembleModel(String name, EnsembleModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<Model<T>> newModels, EnsembleCombiner<T> combiner) Unless you are implementing aTraineryou should not use this constructor directly.WeightedEnsembleModel(String name, EnsembleModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<Model<T>> newModels, EnsembleCombiner<T> combiner, float[] weights) Unless you are implementing aTraineryou should not use this constructor directly. -
Method Summary
Modifier and TypeMethodDescriptionprotected EnsembleModel<T> Copies this ensemble model.static <T extends Output<T>>
WeightedEnsembleModel<T> createEnsembleFromExistingModels(String name, List<Model<T>> models, EnsembleCombiner<T> combiner) Creates an ensemble from existing models.static <T extends Output<T>>
WeightedEnsembleModel<T> createEnsembleFromExistingModels(String name, List<Model<T>> models, EnsembleCombiner<T> combiner, float[] weights) Creates an ensemble from existing models.static WeightedEnsembleModel<?> deserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.ai.onnx.proto.OnnxMl.ModelProtoexportONNXModel(String domain, long modelVersion) Exports thisEnsembleModelas an ONNX model.Generates an excuse for an example.Uses the model to predict the output for a single example.org.tribuo.protos.core.ModelProtoSerializes this object to a protobuf.writeONNXGraph(ONNXRef<?> input) Methods inherited from class org.tribuo.ensemble.EnsembleModel
copy, getModels, getNumModels, getProvenance, getTopFeaturesMethods inherited from class org.tribuo.Model
castModel, copy, createDataCarrier, deserialize, deserializeFromFile, deserializeFromStream, generatesProbabilities, getExcuses, getFeatureIDMap, getName, getOutputIDInfo, innerPredict, predict, predict, serializeToFile, serializeToStream, setName, toString, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.tribuo.ONNXExportable
saveONNXModel, serializeProvenance
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
weights
protected final float[] weightsThe ensemble member combination weights. -
combiner
The ensemble combination function.
-
-
Constructor Details
-
WeightedEnsembleModel
public WeightedEnsembleModel(String name, EnsembleModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<Model<T>> newModels, EnsembleCombiner<T> combiner) Unless you are implementing aTraineryou should not use this constructor directly. Instead usecreateEnsembleFromExistingModels(String, List, EnsembleCombiner).Constructs an ensemble model which uses uniform weights.
- Parameters:
name- The model name.provenance- The model provenance.featureIDMap- The feature domain.outputIDInfo- The output domain.newModels- The list of ensemble members.combiner- The combination function.
-
WeightedEnsembleModel
public WeightedEnsembleModel(String name, EnsembleModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<Model<T>> newModels, EnsembleCombiner<T> combiner, float[] weights) Unless you are implementing aTraineryou should not use this constructor directly. Instead usecreateEnsembleFromExistingModels(String, List, EnsembleCombiner, float[]).Constructs an ensemble model which uses uniform weights.
- Parameters:
name- The model name.provenance- The model provenance.featureIDMap- The feature domain.outputIDInfo- The output domain.newModels- The list of ensemble members.combiner- The combination function.weights- The model combination weights.
-
-
Method Details
-
deserializeFromProto
public static WeightedEnsembleModel<?> deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException Deserialization factory.- Parameters:
version- The serialized object version.className- The class name.message- The serialized data.- Returns:
- The deserialized object.
- Throws:
com.google.protobuf.InvalidProtocolBufferException- If the protobuf could not be parsed from themessage.
-
predict
Description copied from class:ModelUses the model to predict the output for a single example.predict does not mutate the example.
Throws
IllegalArgumentExceptionif the example has no features or no feature overlap with the model. -
getExcuse
Description copied from class:ModelGenerates an excuse for an example.This attempts to explain a classification result. Generating an excuse may be quite an expensive operation.
This excuse either contains per class information or an entry with key Model.ALL_OUTPUTS.
The optional is empty if the model does not provide excuses.
- Specified by:
getExcusein classEnsembleModel<T extends Output<T>>- Parameters:
example- The input example.- Returns:
- An optional excuse object. The optional is empty if this model does not provide excuses.
-
copy
protected EnsembleModel<T> copy(String name, EnsembleModelProvenance newProvenance, List<Model<T>> newModels) Description copied from class:EnsembleModelCopies this ensemble model.- Specified by:
copyin classEnsembleModel<T extends Output<T>>- Parameters:
name- The new name.newProvenance- The new provenance.newModels- The new models.- Returns:
- A copy of the ensemble model.
-
createEnsembleFromExistingModels
public static <T extends Output<T>> WeightedEnsembleModel<T> createEnsembleFromExistingModels(String name, List<Model<T>> models, EnsembleCombiner<T> combiner) Creates an ensemble from existing models. The model outputs are combined using uniform weights.Uses the feature and output domain from the first model as the ensemble model's domains. The individual ensemble members use the domains that they contain.
If the output domains don't cover the same dimensions then it throws
IllegalArgumentException.- Type Parameters:
T- The output type.- Parameters:
name- The ensemble name.models- The ensemble members.combiner- The combination function.- Returns:
- A weighted ensemble model.
-
createEnsembleFromExistingModels
public static <T extends Output<T>> WeightedEnsembleModel<T> createEnsembleFromExistingModels(String name, List<Model<T>> models, EnsembleCombiner<T> combiner, float[] weights) Creates an ensemble from existing models.Uses the feature and output domain from the first model as the ensemble model's domains. The individual ensemble members use the domains that they contain.
If the output domains don't cover the same dimensions then it throws
IllegalArgumentException. If the weights aren't the same length as the models it throwsIllegalArgumentException.- Type Parameters:
T- The output type.- Parameters:
name- The ensemble name.models- The ensemble members.combiner- The combination function.weights- The model combination weights.- Returns:
- A weighted ensemble model.
-
exportONNXModel
Exports thisEnsembleModelas an ONNX model.Note if the ensemble members or the ensemble combination function do not implement
ONNXExportablethen this method will throwUnsupportedOperationException.- Specified by:
exportONNXModelin interfaceONNXExportable- Parameters:
domain- A reverse-DNS name to namespace the model (e.g., org.tribuo.classification.sgd.linear).modelVersion- A version number for this model.- Returns:
- An ONNX ModelProto representing the model.
-
writeONNXGraph
Description copied from interface:ONNXExportable- Specified by:
writeONNXGraphin interfaceONNXExportable- Parameters:
input- The input to the model graph.- Returns:
- the output node of the model graph.
-
serialize
-