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 dtc_to_model(self): if str("MAT") in self.backend or str("IZHI") in self.backend or str( "ADEXP") in self.backend: self.jithub = True else: self.jithub = False if self.jithub: #iz = model_classes.IzhiModel() if str("MAT") in self.backend: model = model_classes.MATModel() model._backend.attrs = self.attrs #print(model._backend.attrs) model.attrs = self.attrs model.params = self.to_bpo_param(self.attrs) #model.rheobase = self.rheobase assert len(self.attrs) assert len(model.attrs) return model if str("IZHI") in self.backend: model = model_classes.IzhiModel() model._backend.attrs = self.attrs model.attrs = self.attrs model.params = self.to_bpo_param(self.attrs) #model.rheobase = self.rheobase assert len(self.attrs) assert len(model.attrs) return model if str("ADEXP") in self.backend: model = model_classes.ADEXPModel() model._backend.attrs = self.attrs model.attrs = self.attrs model.params = self.to_bpo_param(self.attrs) #model.rheobase = self.rheobase assert len(self.attrs) assert len(model.attrs) return model else: from neuronunit.models.very_reduced_sans_lems import VeryReducedModel model = VeryReducedModel(backend=self.backend, attrs=self.attrs) #model._backend = self.backend if "GLIF" in self.backend: model._backend.set_attrs(self.attrs) model.attrs = self.attrs else: model.set_attrs(self.attrs) if model.attrs is None: model.attrs = self.attrs '''
def test_opt_1(self): specimen_id = self.ids[1] cellmodel = "IZHI" if cellmodel == "IZHI": model = model_classes.IzhiModel() if cellmodel == "MAT": model = model_classes.MATModel() if cellmodel == "ADEXP": model = model_classes.ADEXPModel() target_num_spikes = 9 efel_filter_iterable = [ "ISI_log_slope", "mean_frequency", "adaptation_index2", "first_isi", "ISI_CV", "median_isi", "Spikecount", "all_ISI_values", "ISI_values", "time_to_first_spike", "time_to_last_spike", "time_to_second_spike", ] [ suite, target_current, spk_count, cell_evaluator, simple_cell ] = opt_setup(specimen_id, cellmodel, target_num_spikes, template_model=model, fixed_current=False, cached=False, score_type=RelativeDifferenceScore) NGEN = 155 MU = 35 mapping_funct = dask_map_function final_pop, hall_of_fame, logs, hist = opt_exec( MU, NGEN, mapping_funct, cell_evaluator, cxpb=0.4, mutpb=0.01 ) opt, target, scores, obs_preds, df = 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) < 8.5 self.assertGreater(8.5, np.sum(fitnesses)) nt.assert_is_instance(8.5, np.sum(fitnesses))
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)
''' import builtins from inspect import getframeinfo, stack original_print = print def print_wrap(*args, **kwargs): caller = getframeinfo(stack()[1][0]) original_print("FN:",caller.filename,"Line:", caller.lineno,"Func:", caller.function,":::", *args, **kwargs) builtins.print = print_wrap ''' specimen_id = 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() 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
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)