def _select_expert(self, strategy: "SupervisedTemplate", task_label):
        """Given a task label, calculates the relatedness between
        the autoencoder for this task and all other autoencoders.
        Returns the most related expert and the relatedness value.
        """
        print("\nSELECTING EXPERT")
        # If the expert dictionary is empty,
        # build the first expert

        # Preferably we could use `strategy.experience.benchmark.n_classes`
        # but this attribute is not enforced for all benchmarks
        n_classes = len(strategy.experience.classes_seen_so_far) + len(
            strategy.experience.future_classes
        )

        if len(strategy.model.expert_dict) == 0:
            expert = ExpertModel(
                num_classes=n_classes,
                arch=strategy.model.arch,
                device=strategy.device,
                pretrained_flag=strategy.model.pretrained_flag,
            )
            relatedness = 0

        # If experts exist,
        # select an autoencoder using task relatedness
        else:
            # Build an error dictionary
            error_dict = OrderedDict()

            # Iterate through all autoencoders to get error values
            for autoencoder_id in strategy.model.autoencoder_dict:
                error_dict[str(autoencoder_id)] = (
                    self._get_average_reconstruction_error(strategy, autoencoder_id)
                )

            # Send error dictionary to get most relevant autoencoder
            relatedness_dict = self._task_relatedness(strategy, error_dict, task_label)

            # Retrieve best expert
            most_relevant_expert_key = max(relatedness_dict, key=relatedness_dict.get)

            most_relevant_expert = self._get_expert(strategy, most_relevant_expert_key)

            # Build expert with feature template
            expert = ExpertModel(
                num_classes=n_classes,
                arch=strategy.model.arch,
                device=strategy.device,
                pretrained_flag=strategy.model.pretrained_flag,
                provided_template=most_relevant_expert,
            )

            relatedness = relatedness_dict[most_relevant_expert_key]
            print("SELECTED EXPERT FROM TASK ", most_relevant_expert_key)

        print("FINISHED EXPERT SELECTION\n")
        return expert, relatedness
Given a task label, calculates the relatedness between
        the autoencoder for this task and all other autoencoders.
        Returns the most related expert and the relatedness value.
        
avalanche/training/supervised/expert_gate.py