def try_load(self) -> bool:
        # Try to get the run from cache (this doesn't load the data files yet).
        run_measurement_manager = self.measurement_manager.try_get_cached(
            self._template.experiment_name, self._topology_params)

        if run_measurement_manager is None:
            return False

        logger.info("Loaded from cache.")
        # If the run exists, but we don't want to calculate anything from it, just continue to the next run.

        controller = ExperimentController()
        topology = self._topology_factory.create_topology(
            **self._topology_params)
        self._template.setup_controller(topology, controller,
                                        run_measurement_manager)

        run_measurement_manager.load_from_cache()

        if self._run_params.calculate_statistics:
            controller.calculate_run_results()
            # TODO: Add caching of this as well.
            self.measurement_manager.add_results(run_measurement_manager)

        return True
Exemple #2
0
 def setup_controller(self, topology: TTopology,
                      controller: ExperimentController,
                      run_measurement_manager: RunMeasurementManager):
     controller.register(
         GoalDirectedTemplateMainComponent(
             topology,
             run_measurement_manager,
             window_size=self._avg_reward_window_size))
def test_experiment_controller_should_end(should_end_1, should_end_2):
    controller = ExperimentController()

    events = []

    controller.register(ComponentStub(1, events, should_end_1))
    controller.register(ComponentStub(2, events, should_end_2))

    assert (should_end_1 or should_end_2) == controller.should_end_run()
    def setup_controller(self, topology: ClassificationAccuracyModularTopology,
                         controller: ExperimentController,
                         run_measurement_manager: RunMeasurementManager):
        train_test_component = TrainTestControllingComponent(
            topology, run_measurement_manager, self._train_test_params)

        controller.register(train_test_component)
        controller.register(
            Task0TrainTestClassificationAccComponent(topology,
                                                     run_measurement_manager,
                                                     self._experiment_params,
                                                     train_test_component))
    def setup_controller(self, topology: TTopology,
                         controller: ExperimentController,
                         run_measurement_manager: RunMeasurementManager):
        train_test_component = TrainTestControllingComponent(
            topology, run_measurement_manager, self._train_test_params)
        controller.register(train_test_component)

        train_test_component.add_measurement_f_training('item', self.measure)
        train_test_component.add_measurement_f_training(
            'model_item', topology.value)
        train_test_component.add_measurement_f_testing('item', self.measure)
        train_test_component.add_measurement_f_testing('model_item',
                                                       topology.value)
 def setup_controller(self, topology: Union[GradualLearningTopology,
                                            TrainTestSwitchable],
                      controller: ExperimentController,
                      run_measurement_manager: RunMeasurementManager):
     controller.register(
         GradualLearningWorldComponent(
             topology,
             run_measurement_manager,
             initial_training_steps=self.template_params.
             initial_training_steps,
             testing_steps=self.template_params.testing_steps,
             untraining_steps=self.template_params.untraining_steps,
             retraining_steps=self.template_params.retraining_steps,
             retraining_phases=self.template_params.retraining_phases))
Exemple #7
0
    def setup_controller(self, topology: Task0TaAnalysisTopology,
                         controller: ExperimentController,
                         run_measurement_manager: RunMeasurementManager):

        # splits the measurements into train/test phases
        train_test_component = TrainTestControllingComponent(
            topology, run_measurement_manager, self._train_test_params)
        controller.register(train_test_component)

        # measures and computes common statistics for the classification
        controller.register(
            Task0TaAnalysisComponent(topology, run_measurement_manager,
                                     self._experiment_params,
                                     train_test_component,
                                     self._experiment_params.num_layers,
                                     self._experiment_params.num_classes))

        # measures and computes stats for each layer
        for layer_id in range(self._experiment_params.num_layers):
            controller.register(
                Task0TaAnalysisLayerComponent(
                    topology, run_measurement_manager, self._experiment_params,
                    train_test_component, self._experiment_params.num_layers,
                    self._experiment_params.num_classes, layer_id,
                    self._experiment_params.is_train_test_classifier_computed))
Exemple #8
0
    def setup_controller(self, topology: GradualLearningBasicTopology,
                         controller: ExperimentController,
                         run_measurement_manager: RunMeasurementManager):
        sp_cluster_setter = SpatialPoolerClusterForceSetter(topology)
        controller.register(sp_cluster_setter)

        measuring_component = GradualLearningBasicMeasuringComponent(
            topology, run_measurement_manager)
        controller.register(measuring_component)

        experiment_params = topology.params.experiment_params
        if experiment_params is not None:
            experiment_component = experiment_params.component(
                topology, experiment_params.params)
            controller.register(experiment_component)
    def create_run(self) -> 'SingleExperimentRun[TTopology]':
        # Create a new run.
        run_measurement_manager = self.measurement_manager.create_new_run(
            self._template.experiment_name, self._topology_params)

        parameters_print = DocumentPublisher.parameters_to_string(
            [self._topology_params])[0]
        logger.info(f'Creating run with parameters: \n{parameters_print}')

        controller = ExperimentController()
        topology = self._topology_factory.create_topology(
            **self._topology_params)
        self._template.setup_controller(topology, controller,
                                        run_measurement_manager)

        topology.assign_ids()

        return SingleExperimentRun(self, topology, controller,
                                   self._topology_params,
                                   run_measurement_manager, self._run_params,
                                   self._run_idx)
 def setup_controller(self, topology: TopologyStub,
                      controller: ExperimentController,
                      run_measurement_manager: RunMeasurementManager):
     controller.register(
         ExperimentComponentMeasuringStub(topology,
                                          run_measurement_manager))
def test_experiment_controller_chain():
    controller = ExperimentController()

    events = []

    component1 = controller.register(ComponentStub(1, events))
    component2 = controller.register(ComponentStub(2, events))

    assert [component1, component2] == controller._components

    controller.before_topology_step()
    controller.after_topology_step()
    controller.before_topology_step()
    controller.after_topology_step()
    controller.calculate_run_results()

    assert [('component 1', 'before_step'), ('component 2', 'before_step'),
            ('component 1', 'after_step'), ('component 2', 'after_step'),
            ('component 1', 'before_step'), ('component 2', 'before_step'),
            ('component 1', 'after_step'), ('component 2', 'after_step'),
            ('component 1', 'finish'), ('component 2', 'finish')] == events
 def setup_controller(self, topology: SymbolicInputWordsTopology,
                      controller: ExperimentController,
                      run_measurement_manager: RunMeasurementManager):
     sp_cluster_setter = SpatialPoolerClusterForceSetter(topology)
     controller.register(sp_cluster_setter)