change start parameters, clean up old code
This commit is contained in:
parent
05c808e90b
commit
90ccb4459d
168
run_Fitter.py
168
run_Fitter.py
@ -29,21 +29,10 @@ def main():
|
||||
fit_cell_parallel(cell_data, start_parameters)
|
||||
quit()
|
||||
|
||||
# test_single_cell("invivo_data/2012-01-17-ap/")
|
||||
#
|
||||
# quit()
|
||||
test_single_cell("data/invivo/2010-11-08-al-invivo-1/")
|
||||
|
||||
start_parameters = [p for p in iget_start_parameters()]
|
||||
# start_data = 8
|
||||
# count = 0
|
||||
# for cell_data in icelldata_of_dir("./invivo_data/"):
|
||||
# count += 1
|
||||
# if count < start_data:
|
||||
# continue
|
||||
# fit_cell_parallel(cell_data, start_parameters)
|
||||
|
||||
cell_data = CellData("data/invivo/2013-04-17-ac-invivo-1/")
|
||||
test_single_cell("data/invivo/2015-01-20-ad-invivo-1/")
|
||||
# start_parameters = [p for p in iget_start_parameters()]
|
||||
# cell_data = CellData("data/invivo/2013-04-17-ac-invivo-1/")
|
||||
# fit_cell_parallel(cell_data, start_parameters)
|
||||
|
||||
|
||||
@ -59,7 +48,7 @@ def test_single_cell(path):
|
||||
cell_path = os.path.basename(cell_data.get_data_path())
|
||||
|
||||
error = fitter.calculate_errors(model=LifacNoiseModel(res_par))
|
||||
save_path = "results/invivo_results/" + cell_path + "/start_parameter_{:}_err_{:.2f}/".format(i, sum(error))
|
||||
save_path = "results/invivo_bursty_results/" + cell_path + "/start_parameter_{:}_err_{:.2f}/".format(i, sum(error))
|
||||
save_fitting_run_info(cell_data, res_par, p, plot=True, save_path=save_path)
|
||||
print("Done with start parameters {}".format(str(i)))
|
||||
|
||||
@ -86,18 +75,6 @@ def fit_cell_base(parameters):
|
||||
"\n error: {:.2f}".format(sum(error)))
|
||||
|
||||
|
||||
def fit_all_cells_parallel_sync(cells, start_parameters, thread_pool, results_base_folder):
|
||||
parameter = []
|
||||
for cell in cells:
|
||||
for i, s_pars in enumerate(start_parameters):
|
||||
parameter.append((cell, i, s_pars, results_base_folder))
|
||||
|
||||
time1 = time.time()
|
||||
thread_pool.map(fit_cell_base, parameter)
|
||||
time2 = time.time()
|
||||
print("Time taken for all ({:}): {:.2f}s".format(len(parameter)*len(cells), time2 - time1))
|
||||
|
||||
|
||||
def fit_cell_parallel(cell_data, start_parameters):
|
||||
cell_path = os.path.basename(cell_data.get_data_path())
|
||||
save_directory = "./results/invivo_results/"
|
||||
@ -125,49 +102,7 @@ def fit_cell_parallel(cell_data, start_parameters):
|
||||
min_err = cur_fit.comparable_error()
|
||||
best_fit = cur_fit
|
||||
|
||||
best_fit.generate_master_plot("./results/invivo_best/singles/")
|
||||
|
||||
|
||||
|
||||
def test_fit_routines():
|
||||
fitter = Fitter()
|
||||
names = ("routine_1", "routine_2")
|
||||
global FIT_ROUTINE
|
||||
for i, routine in enumerate([fitter.fit_routine_1, fitter.fit_routine_2]):
|
||||
FIT_ROUTINE = names[i]
|
||||
run_with_real_data(fitter, routine)
|
||||
|
||||
best = []
|
||||
cells = sorted(os.listdir("test_routines/" + names[0] + "/"))
|
||||
for name in names:
|
||||
|
||||
save_path = "test_routines/" + name + "/"
|
||||
cell_best = []
|
||||
for directory in sorted(os.listdir(save_path)):
|
||||
path = os.path.join(save_path, directory)
|
||||
if os.path.isdir(path):
|
||||
cell_best.append(find_best_run(path))
|
||||
best.append(cell_best)
|
||||
|
||||
with open("test_routines/comparision.csv", "w") as res_file:
|
||||
res_file.write("routine")
|
||||
for cell in cells:
|
||||
res_file.write("," + cell)
|
||||
|
||||
for i, routine_results in enumerate(best):
|
||||
res_file.write(names[i])
|
||||
for cell_best in routine_results:
|
||||
res_file.write("," + str(cell_best))
|
||||
|
||||
|
||||
def find_best_run(cell_path):
|
||||
values = []
|
||||
for directory in sorted(os.listdir(cell_path)):
|
||||
start_par_path = os.path.join(cell_path, directory)
|
||||
if os.path.isdir(start_par_path):
|
||||
values.append(float(start_par_path.split("_")[-1]))
|
||||
|
||||
return min(values)
|
||||
best_fit.generate_master_plot("./results/invivo_best/")
|
||||
|
||||
|
||||
def iget_start_parameters():
|
||||
@ -175,12 +110,12 @@ def iget_start_parameters():
|
||||
# expand by tau_a, delta_a ?
|
||||
|
||||
mem_tau_list = [0.01]
|
||||
input_scaling_list = [60]
|
||||
input_scaling_list = [100]
|
||||
noise_strength_list = [0.03] # [0.02, 0.06]
|
||||
dend_tau_list = [0.001, 0.002]
|
||||
delta_a_list = [0.035, 0.065]
|
||||
dend_tau_list = [0.0015]
|
||||
delta_a_list = [0.035, 0.065, 0.1]
|
||||
tau_a_list = [0.1, 0.4]
|
||||
ref_time_list = [0.00065]
|
||||
ref_time_list = [0.00065, 0.0012]
|
||||
|
||||
for mem_tau in mem_tau_list:
|
||||
for input_scaling in input_scaling_list:
|
||||
@ -194,64 +129,6 @@ def iget_start_parameters():
|
||||
"delta_a": delta_a, "tau_a": tau_a, "refractory_period": ref_time}
|
||||
|
||||
|
||||
def run_with_real_data(fitter, fit_routine_func, parallel=False):
|
||||
count = 0
|
||||
for cell_data in icelldata_of_dir("./data/"):
|
||||
count += 1
|
||||
if count < 7:
|
||||
pass
|
||||
#continue
|
||||
|
||||
print("cell:", cell_data.get_data_path())
|
||||
trace = cell_data.get_base_traces(trace_type=cell_data.V1)
|
||||
if len(trace) == 0:
|
||||
print("NO V1 TRACE FOUND")
|
||||
continue
|
||||
|
||||
global FIT_ROUTINE
|
||||
# results_path = "results/" + os.path.split(cell_data.get_data_path())[-1] + "/"
|
||||
results_path = "test_routines/" + FIT_ROUTINE + "/" + os.path.split(cell_data.get_data_path())[-1] + "/"
|
||||
print("results at:", results_path)
|
||||
|
||||
if not os.path.exists(results_path):
|
||||
os.makedirs(results_path)
|
||||
|
||||
# plot cell images:
|
||||
cell_save_path = results_path + "cell/"
|
||||
if not os.path.exists(cell_save_path):
|
||||
os.makedirs(cell_save_path)
|
||||
data_baseline = get_baseline_class(cell_data)
|
||||
data_baseline.plot_baseline(cell_save_path)
|
||||
data_baseline.plot_interspike_interval_histogram(cell_save_path)
|
||||
data_baseline.plot_serial_correlation(6, cell_save_path)
|
||||
|
||||
data_fi_curve = get_fi_curve_class(cell_data, cell_data.get_fi_contrasts())
|
||||
data_fi_curve.plot_fi_curve(cell_save_path)
|
||||
|
||||
start_par_count = 0
|
||||
for start_parameters in iget_start_parameters():
|
||||
start_par_count += 1
|
||||
print("START PARAMETERS:", start_par_count)
|
||||
|
||||
start_time = time.time()
|
||||
# fitter = Fitter()
|
||||
fmin, parameters = fitter.fit_model_to_data(cell_data, start_parameters, fit_routine_func)
|
||||
|
||||
print(fmin)
|
||||
print(parameters)
|
||||
end_time = time.time()
|
||||
parameter_set_path = results_path + "start_par_set_{}_fmin_{:.2f}".format(start_par_count, fmin["fun"]) + "/"
|
||||
|
||||
print('Fitting of cell took function took {:.3f} s'.format((end_time - start_time)))
|
||||
# print(results_path)
|
||||
save_fitting_run_info(cell_data, parameters, start_parameters,
|
||||
plot=True, save_path=parameter_set_path)
|
||||
|
||||
# from Sounds import play_finished_sound
|
||||
# play_finished_sound()
|
||||
pass
|
||||
|
||||
|
||||
def save_fitting_run_info(cell_data, parameters, start_parameters, plot=False, save_path=None):
|
||||
if save_path is not None:
|
||||
if not os.path.exists(save_path):
|
||||
@ -343,32 +220,5 @@ def save_fitting_run_info(cell_data, parameters, start_parameters, plot=False, s
|
||||
model_ficurve.plot_fi_curve_comparision(data_fi_curve, model_ficurve, save_path)
|
||||
|
||||
|
||||
def test_effect_of_refractory_period():
|
||||
ref_periods = [0.0006, 0.001, 0.0015]
|
||||
counter = 0
|
||||
core_count = mp.cpu_count()
|
||||
|
||||
for cell in icelldata_of_dir("./data/"):
|
||||
pool = mp.Pool(core_count - 1)
|
||||
counter += 1
|
||||
if counter < 10:
|
||||
continue
|
||||
elif counter >= 14:
|
||||
return
|
||||
start_parameters_base = [p for p in iget_start_parameters()]
|
||||
for ref_period in ref_periods:
|
||||
print(cell.get_data_path())
|
||||
print("ref period: {:.4f}".format(ref_period))
|
||||
results_base_folder = "./test_routines/ref_period_{:.4f}/".format(ref_period)
|
||||
all_start_parameters = copy.deepcopy(start_parameters_base)
|
||||
|
||||
for par_set in all_start_parameters:
|
||||
par_set["refractory_period"] = ref_period
|
||||
fit_all_cells_parallel_sync([cell], all_start_parameters, pool, results_base_folder)
|
||||
|
||||
del cell
|
||||
del pool
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user