MCDropoutNeuralNetwork<T>
Models & Types · AiDotNet.UncertaintyQuantification.BayesianNeuralNetworks
Implements Monte Carlo Dropout for uncertainty estimation.
Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → VectorModelLayoutBase<T> → SequentialVectorModelLayoutBase<T> → NeuralNetwork<T> → MCDropoutNeuralNetwork<T>
Implements: IUncertaintyEstimator<T>
For Beginners
MC Dropout is the simplest way to add uncertainty estimation to existing neural networks.
The idea is straightforward:
- Add dropout layers to your network
- Keep dropout active even during prediction (normally it’s turned off)
- Run multiple predictions with different random dropout patterns
- The variation in predictions tells you the uncertainty
This is much easier than full Bayesian neural networks but still provides useful uncertainty estimates. It’s like getting a second (and third, and fourth…) opinion from slightly different versions of your model.
Example
var inputTensor = Tensor<float>.CreateRandom(2, 4);
// Create an MC Dropout network for uncertainty-aware predictions
var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 10, outputSize: 1);
// Add MCDropoutLayer instances to the architecture for stochastic inference
var mcDropout = new MCDropoutNeuralNetwork<float>(architecture, options: new MCDropoutNeuralNetworkOptions { NumSamples = 50 });
var result = mcDropout.PredictWithUncertainty(inputTensor);
// result.Mean = average prediction, result.Variance = epistemic uncertainty
Constructors
| Constructor | Summary |
|---|---|
MCDropoutNeuralNetwork(NeuralNetworkArchitecture<T> architecture, MCDropoutNeuralNetworkOptions options) |
Initializes a new instance of the MCDropoutNeuralNetwork class. |
Methods
| Method | Summary |
|---|---|
Tensor<T> EstimateAleatoricUncertainty(Tensor<T> input) |
Estimates aleatoric uncertainty. |
Tensor<T> EstimateEpistemicUncertainty(Tensor<T> input) |
Estimates epistemic uncertainty. |
UncertaintyPredictionResult<T, Tensor<T>> PredictWithUncertainty(Tensor<T> input) |
Predicts output with uncertainty estimates using MC dropout. |