Class DeepEnsemble<T>
- Assembly
- AiDotNet.dll
Implements Deep Ensembles for uncertainty estimation.
public class DeepEnsemble<T> : IUncertaintyEstimator<T>
Type Parameters
TThe numeric type used for calculations (e.g., float, double).
- Inheritance
-
DeepEnsemble<T>
- Implements
- Inherited Members
Remarks
For Beginners: Deep Ensembles is one of the most effective methods for uncertainty estimation.
The concept is simple: Train multiple independent neural networks (with different random initializations) on the same task, then use them all to make predictions. The diversity in their predictions gives you uncertainty estimates.
Think of it like a panel of doctors giving diagnoses:
- If all doctors agree on the diagnosis, confidence is high
- If doctors give different diagnoses, uncertainty is high
Advantages:
- Very reliable uncertainty estimates
- No special training procedures needed
- Each network can use standard architectures
Disadvantages:
- Requires training and storing multiple networks
- Slower inference (must run all networks)
- Higher memory usage
Research shows that ensembles of just 5 networks often outperform more complex Bayesian methods.
Constructors
DeepEnsemble(List<INeuralNetwork<T>>)
Initializes a new instance of the DeepEnsemble class.
public DeepEnsemble(List<INeuralNetwork<T>> models)
Parameters
modelsList<INeuralNetwork<T>>The collection of trained models in the ensemble.
Remarks
For Beginners: Each model should be trained independently with different random initializations. Typically 5-10 models is a good balance between performance and cost.
Exceptions
- ArgumentException
Thrown when the model list is empty.
Properties
EnsembleSize
Gets the number of models in the ensemble.
public int EnsembleSize { get; }
Property Value
Methods
EstimateAleatoricUncertainty(Tensor<T>)
Estimates aleatoric uncertainty from the ensemble.
public Tensor<T> EstimateAleatoricUncertainty(Tensor<T> input)
Parameters
inputTensor<T>The input tensor.
Returns
- Tensor<T>
The aleatoric uncertainty estimate.
Remarks
For Beginners: If each model in the ensemble outputs both a prediction and its own uncertainty estimate (e.g., Gaussian likelihood), the average of individual model uncertainties represents aleatoric uncertainty (data noise).
Important: This implementation does not currently have per-model variance heads, so a true aleatoric/epistemic decomposition is not available. As a conservative default, this method returns zeros; to estimate aleatoric uncertainty, modify ensemble members to output explicit variance (e.g., a Gaussian likelihood head).
EstimateEpistemicUncertainty(Tensor<T>)
Estimates epistemic uncertainty from the ensemble.
public Tensor<T> EstimateEpistemicUncertainty(Tensor<T> input)
Parameters
inputTensor<T>The input tensor.
Returns
- Tensor<T>
The epistemic uncertainty estimate.
Remarks
For Beginners: The disagreement between ensemble members represents epistemic uncertainty (model uncertainty). When models disagree, it means they're uncertain about the correct answer.
GetAllPredictions(Tensor<T>)
Gets the predictions from all ensemble members.
public List<Tensor<T>> GetAllPredictions(Tensor<T> input)
Parameters
inputTensor<T>The input tensor.
Returns
- List<Tensor<T>>
A list of predictions from each ensemble member.
Remarks
For Beginners: This is useful when you want to analyze individual model predictions or implement custom uncertainty aggregation methods.
PredictWithUncertainty(Tensor<T>)
Predicts output with uncertainty estimates from the ensemble.
public UncertaintyPredictionResult<T, Tensor<T>> PredictWithUncertainty(Tensor<T> input)
Parameters
inputTensor<T>The input tensor.
Returns
- UncertaintyPredictionResult<T, Tensor<T>>
A tuple containing the mean prediction and uncertainty.
Remarks
For Beginners: This runs the input through all models in the ensemble, then returns the average prediction and how much the models disagreed. More disagreement = higher uncertainty.