avalanche.benchmarks.scenarios.NIScenario

class avalanche.benchmarks.scenarios.NIScenario(train_dataset: ClassificationDataset, test_dataset: ClassificationDataset, n_experiences: int, task_labels: bool = False, shuffle: bool = True, seed: int | None = None, balance_experiences: bool = False, min_class_patterns_in_exp: int = 0, fixed_exp_assignment: Sequence[Sequence[int]] | None = None, reproducibility_data: Dict[str, Any] | None = None)[source]

This class defines a “New Instance” scenario. Once created, an instance of this class can be iterated in order to obtain the experience sequence under the form of instances of NIExperience.

Instances of this class can be created using the constructor directly. However, we recommend using facilities like avalanche.benchmarks.generators.ni_scenario().

Consider that every method from NIExperience used to retrieve parts of the test set (past, current, future, cumulative) always return the complete test set. That is, they behave as the getter for the complete test set.

__init__(train_dataset: ClassificationDataset, test_dataset: ClassificationDataset, n_experiences: int, task_labels: bool = False, shuffle: bool = True, seed: int | None = None, balance_experiences: bool = False, min_class_patterns_in_exp: int = 0, fixed_exp_assignment: Sequence[Sequence[int]] | None = None, reproducibility_data: Dict[str, Any] | None = None)[source]

Creates a NIScenario instance given the training and test Datasets and the number of experiences.

Parameters:
  • train_dataset – The training dataset. The dataset must be an instance of AvalancheDataset. For instance, one can use the datasets from the torchvision package like that: train_dataset=AvalancheDataset(torchvision_dataset).

  • test_dataset – The test dataset. The dataset must be a subclass of AvalancheDataset. For instance, one can use the datasets from the torchvision package like that: test_dataset=AvalancheDataset(torchvision_dataset).

  • n_experiences – The number of experiences.

  • task_labels – If True, each experience will have an ascending task label. If False, the task label will be 0 for all the experiences. Defaults to False.

  • shuffle – If True, the patterns order will be shuffled. Defaults to True.

  • seed – If shuffle is True and seed is not None, the class order will be shuffled according to the seed. When None, the current PyTorch random number generator state will be used. Defaults to None.

  • balance_experiences – If True, pattern of each class will be equally spread across all experiences. If False, patterns will be assigned to experiences in a complete random way. Defaults to False.

  • min_class_patterns_in_exp – The minimum amount of patterns of every class that must be assigned to every experience. Compatible with the balance_experiences parameter. An exception will be raised if this constraint can’t be satisfied. Defaults to 0.

  • fixed_exp_assignment – If not None, the pattern assignment to use. It must be a list with an entry for each experience. Each entry is a list that contains the indexes of patterns belonging to that experience. Overrides the shuffle, balance_experiences and min_class_patterns_in_exp parameters.

  • reproducibility_data – If not None, overrides all the other scenario definition options, including fixed_exp_assignment. This is usually a dictionary containing data used to reproduce a specific experiment. One can use the get_reproducibility_data method to get (and even distribute) the experiment setup so that it can be loaded by passing it as this parameter. In this way one can be sure that the same specific experimental setup is being used (for reproducibility purposes). Beware that, in order to reproduce an experiment, the same train and test datasets must be used. Defaults to None.

Methods

__init__(train_dataset, test_dataset, ...[, ...])

Creates a NIScenario instance given the training and test Datasets and the number of experiences.

get_classes_timeline(current_experience[, ...])

Returns the classes timeline given the ID of a experience.

get_reproducibility_data()

Gets the data needed to reproduce this experiment.

Attributes

classes_in_experience

A dictionary mapping each stream (by name) to a list.

n_experiences

The number of incremental training experiences contained in the train stream.

streams

task_labels

The task label of each training experience.

n_classes

The amount of classes in the original training set.

n_patterns_per_class

The amount of patterns for each class in the original training set.

n_patterns_per_experience

The number of patterns in each experience.

exp_structure

This field contains, for each training experience, the number of instances of each class assigned to that experience.

train_exps_patterns_assignment

A list containing which training instances are assigned to each experience in the train stream.