Class WeightedEnsembleModel<T extends Output<T>>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>
,Serializable
,ONNXExportable
- See Also:
-
Field Summary
Fields inherited from class org.tribuo.ensemble.EnsembleModel
models
Fields inherited from class org.tribuo.Model
ALL_OUTPUTS, BIAS_FEATURE, featureIDMap, generatesProbabilities, name, outputIDInfo, provenance, provenanceOutput
Fields inherited from interface org.tribuo.ONNXExportable
PROVENANCE_METADATA_FIELD, SERIALIZER
-
Constructor Summary
ConstructorDescriptionWeightedEnsembleModel
(String name, EnsembleModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<Model<T>> newModels, EnsembleCombiner<T> combiner) Unless you are implementing aTrainer
you 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 aTrainer
you 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.exportONNXModel
(String domain, long modelVersion) Exports thisEnsembleModel
as an ONNX model.Generates an excuse for an example.Uses the model to predict the output for a single example.writeONNXGraph
(ONNXRef<?> input) Methods inherited from class org.tribuo.ensemble.EnsembleModel
copy, getModels, getNumModels, getProvenance, getTopFeatures
Methods inherited from class org.tribuo.Model
castModel, copy, generatesProbabilities, getExcuses, getFeatureIDMap, getName, getOutputIDInfo, innerPredict, predict, predict, setName, toString, validate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.tribuo.ONNXExportable
saveONNXModel, serializeProvenance
-
Field Details
-
weights
protected final float[] weights -
combiner
-
-
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 aTrainer
you 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 aTrainer
you 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
-
predict
Description copied from class:Model
Uses the model to predict the output for a single example.predict does not mutate the example.
Throws
IllegalArgumentException
if the example has no features or no feature overlap with the model. -
getExcuse
Description copied from class:Model
Generates 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:
getExcuse
in 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:EnsembleModel
Copies this ensemble model.- Specified by:
copy
in 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 thisEnsembleModel
as an ONNX model.Note if the ensemble members or the ensemble combination function do not implement
ONNXExportable
then this method will throwUnsupportedOperationException
.- Specified by:
exportONNXModel
in 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:
writeONNXGraph
in interfaceONNXExportable
- Parameters:
input
- The input to the model graph.- Returns:
- the output node of the model graph.
-