Esempio n. 1
0
    def test_opt_1(self):
        cellmodel = "ADEXP"

        if cellmodel == "IZHI":
            model = model_classes.IzhiModel()
        if cellmodel == "MAT":
            model = model_classes.MATModel()
        if cellmodel == "ADEXP":
            model = model_classes.ADEXPModel()

        dtc = DataTC()
        dtc.backend = cellmodel
        dtc._backend = model._backend
        dtc.attrs = model.attrs
        dtc.params = {
            k: np.mean(v)
            for k, v in MODEL_PARAMS[cellmodel].items()
        }
        other_params = BPO_PARAMS[cellmodel]
        dtc = dtc_to_rheo(dtc)
        assert dtc.rheobase is not None
        self.assertIsNotNone(dtc.rheobase)
        vm, plt, dtc = inject_and_plot_model(dtc, plotly=False)
        self.assertIsNotNone(vm)
        model = dtc.dtc_to_model()
        self.assertIsNotNone(model)
 def model_test_eval(self, tests):
     """
     Take a model and some tests
     Evaluate a test suite over them.
     """
     from sciunit import TestSuite
     if type(tests) is TestSuite:
         not_suite = TSD({t.name: t for t in tests.tests})
     OM = OptMan(tests, backend=self._backend)
     dtc = DataTC()
     dtc.attrs = self.attrs
     assert set(self._backend.attrs.keys()) in set(self.attrs.keys())
     dtc.backend = self._backend
     dtc.tests = copy.copy(not_suite)
     dtc = dtc_to_rheo(dtc)
     if dtc.rheobase is not None:
         dtc.tests = dtc.format_test()
         dtc = list(map(OM.elephant_evaluation, [dtc]))
     model = dtc.dtc_to_model()
     model.SM = dtc.SM
     model.obs_preds = dtc.obs_preds
     return dtc[0], model
Esempio n. 3
0
    def test_opt_1(self):
        specimen_id = self.ids[1]
        cellmodel = "ADEXP"

        if cellmodel == "IZHI":
            model = model_classes.IzhiModel()
        if cellmodel == "MAT":
            model = model_classes.MATModel()
        if cellmodel == "ADEXP":
            model = model_classes.ADEXPModel()

        target_num_spikes = 8
        dtc = DataTC()
        dtc.backend = cellmodel
        dtc._backend = model._backend
        dtc.attrs = model.attrs
        dtc.params = {
            k: np.mean(v)
            for k, v in MODEL_PARAMS[cellmodel].items()
        }

        dtc = dtc_to_rheo(dtc)
        assert dtc.rheobase is not None
        self.assertIsNotNone(dtc.rheobase)
        vm, plt, dtc = inject_and_plot_model(dtc, plotly=False)
        fixed_current = 122 * qt.pA
        model, suite, nu_tests, target_current, spk_count = opt_setup(
            specimen_id,
            cellmodel,
            target_num_spikes,
            provided_model=model,
            fixed_current=False,
            cached=True)
        model = dtc.dtc_to_model()
        model.seeded_current = target_current['value']
        model.allen = True
        model.seeded_current
        model.NU = True
        cell_evaluator, simple_cell = opt_setup_two(model,
                                                    cellmodel,
                                                    suite,
                                                    nu_tests,
                                                    target_current,
                                                    spk_count,
                                                    provided_model=model)
        NGEN = 15
        MU = 12

        mapping_funct = dask_map_function
        final_pop, hall_of_fame, logs, hist = opt_exec(MU, NGEN, mapping_funct,
                                                       cell_evaluator)
        opt, target = opt_to_model(hall_of_fame, cell_evaluator, suite,
                                   target_current, spk_count)
        best_ind = hall_of_fame[0]
        fitnesses = cell_evaluator.evaluate_with_lists(best_ind)
        assert np.sum(fitnesses) < 0.7
        self.assertGreater(0.7, np.sum(fitnesses))

        #obnames = [obj.name for obj in cell_evaluator.objectives]

        gen_numbers = logs.select('gen')
        min_fitness = logs.select('min')
        max_fitness = logs.select('max')
        avg_fitness = logs.select('avg')
        plt.plot(gen_numbers, max_fitness, label='max fitness')
        plt.plot(gen_numbers, avg_fitness, label='avg fitness')
        plt.plot(gen_numbers, min_fitness, label='min fitness')
        plt.plot(gen_numbers, min_fitness, label='min fitness')
        plt.semilogy()
        plt.xlabel('generation #')
        plt.ylabel('score (# std)')
        plt.legend()
        plt.xlim(min(gen_numbers) - 1, max(gen_numbers) + 1)
        #model = opt.dtc_to_model()
        plt.plot(opt.vm15.times, opt.vm15)
        plt.plot(opt.vm15.times, opt.vm15)
        target.vm15 = suite.traces['vm15']
        plt.plot(target.vm15.times, target.vm15)
        target.vm15 = suite.traces['vm15']
        check_bin_vm15(target, opt)
target_num_spikes = 8
dtc = DataTC()
dtc.backend = cellmodel
dtc._backend = model._backend
dtc.attrs = model.attrs
dtc.params = {k: np.mean(v) for k, v in MODEL_PARAMS[cellmodel].items()}
dtc = dtc_to_rheo(dtc)
vm, plt, dtc = inject_and_plot_model(dtc, plotly=False)
fixed_current = 122 * qt.pA
model, suite, nu_tests, target_current, spk_count = opt_setup(
    specimen_id,
    cellmodel,
    target_num_spikes,
    provided_model=model,
    fixed_current=False)
model = dtc.dtc_to_model()
model.seeded_current = target_current['value']
model.allen = True
model.seeded_current
model.NU = True
cell_evaluator, simple_cell = opt_setup_two(model,
                                            cellmodel,
                                            suite,
                                            nu_tests,
                                            target_current,
                                            spk_count,
                                            provided_model=model)
NGEN = 12
MU = 12

mapping_funct = dask_map_function
Esempio n. 5
0
    def test_opt(self):
        ids = [
            324257146, 325479788, 476053392, 623893177, 623960880, 482493761,
            471819401
        ]

        specimen_id = ids[1]
        cellmodel = "MAT"

        if cellmodel == "IZHI":
            model = model_classes.IzhiModel()
        if cellmodel == "MAT":
            model = model_classes.MATModel()
        if cellmodel == "ADEXP":
            model = model_classes.ADEXPModel()

        specific_filter_list = [
            'ISI_log_slope_1.5x', 'mean_frequency_1.5x',
            'adaptation_index2_1.5x', 'first_isi_1.5x', 'ISI_CV_1.5x',
            'median_isi_1.5x', 'Spikecount_1.5x', 'all_ISI_values',
            'ISI_values', 'time_to_first_spike', 'time_to_last_spike',
            'time_to_second_spike', 'spike_times'
        ]
        simple_yes_list = specific_filter_list
        target_num_spikes = 8
        dtc = DataTC()
        dtc.backend = cellmodel
        dtc._backend = model._backend
        dtc.attrs = model.attrs
        dtc.params = {
            k: np.mean(v)
            for k, v in MODEL_PARAMS[cellmodel].items()
        }
        dtc = dtc_to_rheo(dtc)
        vm, plt, dtc = inject_and_plot_model(dtc, plotly=False)
        fixed_current = 122 * qt.pA
        model, suite, nu_tests, target_current, spk_count = opt_setup(
            specimen_id,
            cellmodel,
            target_num_spikes,
            provided_model=model,
            fixed_current=False)
        model = dtc.dtc_to_model()
        model.seeded_current = target_current['value']
        model.allen = True
        model.seeded_current
        model.NU = True
        cell_evaluator, simple_cell = opt_setup_two(model,
                                                    cellmodel,
                                                    suite,
                                                    nu_tests,
                                                    target_current,
                                                    spk_count,
                                                    provided_model=model)
        NGEN = 15
        MU = 12

        mapping_funct = dask_map_function
        final_pop, hall_of_fame, logs, hist = opt_exec(MU, NGEN, mapping_funct,
                                                       cell_evaluator)
        opt, target = opt_to_model(hall_of_fame, cell_evaluator, suite,
                                   target_current, spk_count)
        best_ind = hall_of_fame[0]
        fitnesses = cell_evaluator.evaluate_with_lists(best_ind)
        assert np.sum(fitnesses) < 0.7
        self.assertGreater(0.7, np.sum(fitnesses))

        #obnames = [obj.name for obj in cell_evaluator.objectives]

        gen_numbers = logs.select('gen')
        min_fitness = logs.select('min')
        max_fitness = logs.select('max')
        avg_fitness = logs.select('avg')
        plt.plot(gen_numbers, max_fitness, label='max fitness')
        plt.plot(gen_numbers, avg_fitness, label='avg fitness')
        plt.plot(gen_numbers, min_fitness, label='min fitness')
        plt.plot(gen_numbers, min_fitness, label='min fitness')
        plt.semilogy()
        plt.xlabel('generation #')
        plt.ylabel('score (# std)')
        plt.legend()
        plt.xlim(min(gen_numbers) - 1, max(gen_numbers) + 1)
        #model = opt.dtc_to_model()
        plt.plot(opt.vm15.times, opt.vm15)
        plt.plot(opt.vm15.times, opt.vm15)
        target.vm15 = suite.traces['vm15']
        plt.plot(target.vm15.times, target.vm15)
        target.vm15 = suite.traces['vm15']
        check_bin_vm15(target, opt)