VariationalContinualLearning<T>

Models & Types · AiDotNet.ContinualLearning

Implements Variational Continual Learning (VCL) for Bayesian continual learning.

Implements: IContinualLearningStrategy<T>

For Beginners

VCL uses Bayesian neural networks where each weight has a probability distribution (mean and variance) rather than a single value. This allows the network to represent uncertainty and naturally prevents forgetting by using the posterior from previous tasks as the prior for new tasks.

How It Works

How it works:

Key Formula:

Loss = E_q[log p(D|w)] - KL(q(w|D_new) || p(w|D_old))

where q(w|D_new) is the current posterior and p(w|D_old) is the previous posterior (now prior).

Advantages:

Reference: Nguyen, C.V., Li, Y., Bui, T.D., and Turner, R.E. “Variational Continual Learning” (2018). ICLR.

Constructors

Constructor Summary
VariationalContinualLearning(double lambda, double initialLogVar, int? seed) Initializes a new instance of the VariationalContinualLearning class.

Properties

Property Summary
bool AccumulatesAcrossTasks { get; }
double InitialLogVar { get; } Gets the initial log-variance value.
double Lambda { get; set; }
int TaskCount { get; } Gets the number of tasks processed.

Methods

Method Summary
T ComputeLoss(INeuralNetwork<T> network)
ValueTuple<Vector<T>, Vector<T>> GetPosterior() Gets the current posterior distribution parameters.
ValueTuple<Vector<T>, Vector<T>> GetPrior() Gets the current prior distribution parameters.
Vector<T> ModifyGradients(INeuralNetwork<T> network, Vector<T> gradients)
Vector<T> SampleWeights(INeuralNetwork<T> network) Samples weights from the posterior distribution for prediction.
void AfterTask(INeuralNetwork<T> network, ValueTuple<Tensor<T>, Tensor<T>> taskData, int taskId)
void BeforeTask(INeuralNetwork<T> network, int taskId)
void Reset()
void UpdateVariance(Vector<T> gradients, double learningRate) Updates the posterior log-variance based on gradient information.