RWalk#
- class capymoa.ocl.strategy.RWalk[source]#
Bases:
BatchClassifier,Module,HandlerRiemannian Walk (RWalk) learner.
RWalk [1] is a regularisation-based continual learning strategy that, like EWC, augments the task loss with a weighted quadratic penalty on parameter changes. The penalty weights combine an exponential moving average of squared gradients with trajectory scores that estimate how sensitive the loss is to parameter updates, accumulated online between periodic checkpoints.
Alternative implementations:
- __init__(
- schema: Schema,
- model: Module,
- optimiser: Optimizer,
- lambda_: float,
- alpha: float = 0.9,
- delta_t: int = 10,
- device: device | None = None,
- mask_test: bool = False,
- mask_train: bool = False,
- task_mask: Tensor | None = None,
Construct an RWalk learner.
- Parameters:
schema – Stream schema used by the classifier interface.
model – Torch model that outputs class logits.
optimiser – Optimiser used to update
modelparameters.lambda – Weight of the RWalk regularisation term.
alpha – EMA decay factor weighting the new gradient estimate (
alpha=1.0keeps only the most recent estimate). MAS’salphaweights the old estimate instead.delta_t – Number of training steps between score checkpoints.
device – Compute device.
mask_test – Whether to apply per-task masking during testing. This is a task incremental scenario.
mask_train – Whether to apply per-task masking during training. This is also known as the labels trick.
task_mask – Optional per-task mask applied to output logits.
- Raises:
ValueError – If
lambda_is negative,alphais outside[0, 1],delta_tis less than 1, or task-specific masking is requested withouttask_mask.
- attach_with(
- source: Dispatcher,
Attach this sink to an event source.
Implementations should call
capymoa.ocl.events.Dispatcher.subscribe()for each event type the sink needs to handle.- Parameters:
dispatcher – The source this sink should subscribe to.
- batch_predict_proba(x: Tensor) Tensor[source]#
Predict the probabilities of the classes for a batch of instances.
- classmethod from_params( ) Any[source]#
Construct an instance from parameters produced by
get_params.
- predict(instance: Instance) int | None[source]#
Predict the label of an instance.
The base implementation calls
predict_proba()and returns the label with the highest probability.- Parameters:
instance – The instance to predict the label for.
- Returns:
The predicted label or
Noneif the classifier is unable to make a prediction.
- predict_proba(
- instance: Instance,
Calls
batch_predict_proba()with a batch of size 1.
- train(instance: LabeledInstance) None[source]#
Calls
batch_train()with a batch of size 1.
- T_destination = ~T_destination#
- device: torch.device = device(type='cpu')#
Device on which the batch will be processed.
- random_seed: int#
The random seed for reproducibility.
When implementing a classifier ensure random number generators are seeded.
- x_dtype: torch.dtype = torch.float32#
Data type for the input features.
- y_dtype: torch.dtype = torch.int64#
Data type for the target value/labels.