TaskAware#

class capymoa.ocl.TaskAware[source]#

Bases: TaskBoundaryAware

Interface for learners that are aware of the task during evaluation.

Knowing the task during inference greatly simplifies the learning problem. When using this interface your problem becomes a task-incremental online continual learning problem.

>>> from capymoa.classifier import NoChange
>>> from capymoa.datasets.ocl import TinySplitMNIST
>>> from capymoa.ocl import TaskAware
>>> from capymoa.evaluation.ocl import ocl_train_eval_loop
>>> class MyTaskAware(TaskAware, NoChange):
...     def set_train_task(self, train_task_id: int):
...         print(f"Training task {train_task_id}")
...
...     def set_test_task(self, test_task_id: int):
...         print(f"Testing task {test_task_id}")
>>> scenario = TinySplitMNIST()
>>> learner = MyTaskAware(scenario.schema)
>>> ocl_train_eval_loop(learner, scenario.train_streams, scenario.test_streams)
Training task 0
Testing task 0
Testing task 1
Testing task 2
Testing task 3
Testing task 4
Training task 1
Testing task 0
Testing task 1
...
abstract set_test_task(test_task_id: int)[source]#

Called when testing on a task starts.

Parameters:

task_id – The ID of the task.

abstract set_train_task(train_task_id: int)[source]#

Called when a new training task starts.

Parameters:

task_id – The ID of the new task.