add new fit routine which includes dend_tau
This commit is contained in:
parent
4d8e1be4d9
commit
f9d4838b71
49
Fitter.py
49
Fitter.py
@ -17,11 +17,7 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
def run_with_real_data():
|
def run_with_real_data():
|
||||||
count = 0
|
|
||||||
for cell_data in icelldata_of_dir("./data/"):
|
for cell_data in icelldata_of_dir("./data/"):
|
||||||
count += 1
|
|
||||||
if count <= 3:
|
|
||||||
continue
|
|
||||||
|
|
||||||
print("cell:", cell_data.get_data_path())
|
print("cell:", cell_data.get_data_path())
|
||||||
trace = cell_data.get_base_traces(trace_type=cell_data.V1)
|
trace = cell_data.get_base_traces(trace_type=cell_data.V1)
|
||||||
@ -46,9 +42,10 @@ def run_with_real_data():
|
|||||||
with open(results_path + "fit_parameters.txt", "w") as file:
|
with open(results_path + "fit_parameters.txt", "w") as file:
|
||||||
file.writelines([str(parameters)])
|
file.writelines([str(parameters)])
|
||||||
|
|
||||||
results_path += "fit_routine_2_"
|
results_path += "fit_routine_3_"
|
||||||
print('Fitting of cell took function took {:.3f} s'.format((end_time - start_time)))
|
print('Fitting of cell took function took {:.3f} s'.format((end_time - start_time)))
|
||||||
print_comparision_cell_model(cell_data, parameters, plot=True, savepath=results_path)
|
print_comparision_cell_model(cell_data, parameters, plot=True, savepath=results_path)
|
||||||
|
break
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -126,11 +123,15 @@ class Fitter:
|
|||||||
self.f_zero_values = fi_curve.f_zeros
|
self.f_zero_values = fi_curve.f_zeros
|
||||||
self.f_zero_fit = fi_curve.boltzmann_fit_vars
|
self.f_zero_fit = fi_curve.boltzmann_fit_vars
|
||||||
self.f_zero_slope = fi_curve.get_fi_curve_slope_of_straight()
|
self.f_zero_slope = fi_curve.get_fi_curve_slope_of_straight()
|
||||||
self.delta_a = (self.f_zero_slope / self.f_inf_slope) / 1000
|
self.f_zero_slope = fi_curve.get_fi_curve_slope_at(fi_curve.get_f_zero_and_f_inf_intersection()) # around 1/3 of the value at straight
|
||||||
|
self.delta_a = (self.f_zero_slope / self.f_inf_slope) / 1000 # seems to work if divided by 1000...
|
||||||
|
|
||||||
adaption = Adaption(data, fi_curve)
|
adaption = Adaption(data, fi_curve)
|
||||||
self.tau_a = adaption.get_tau_real()
|
self.tau_a = adaption.get_tau_real()
|
||||||
return self.fit_routine_2(data)
|
|
||||||
|
print("delta_a: {:.3f}".format(self.delta_a), "tau_a: {:.3f}".format(self.tau_a))
|
||||||
|
|
||||||
|
return self.fit_routine_3(data)
|
||||||
# return self.fit_model(fit_adaption=False)
|
# return self.fit_model(fit_adaption=False)
|
||||||
|
|
||||||
def fit_routine_1(self, cell_data=None):
|
def fit_routine_1(self, cell_data=None):
|
||||||
@ -179,6 +180,19 @@ class Fitter:
|
|||||||
|
|
||||||
return fmin, res_parameters
|
return fmin, res_parameters
|
||||||
|
|
||||||
|
def fit_routine_3(self, cell_data=None):
|
||||||
|
# errors: [error_bf, error_vs, error_sc, error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope]
|
||||||
|
self.counter = 0
|
||||||
|
# fit only v_offset, mem_tau, noise_strength, input_scaling, dend_tau
|
||||||
|
x0 = np.array([0.02, 0.03, 70, 0.001])
|
||||||
|
initial_simplex = create_init_simples(x0, search_scale=2)
|
||||||
|
error_weights = (1, 1, 5, 1, 2, 0, 0)
|
||||||
|
fmin = minimize(fun=self.cost_function_with_fixed_adaption_with_dend_tau,
|
||||||
|
args=(self.tau_a, self.delta_a, error_weights), x0=x0, method="Nelder-Mead",
|
||||||
|
options={"initial_simplex": initial_simplex})
|
||||||
|
res_parameters = self.base_model.get_parameters()
|
||||||
|
|
||||||
|
return fmin, res_parameters
|
||||||
|
|
||||||
def fit_model(self, x0=None, initial_simplex=None, fit_adaption=False):
|
def fit_model(self, x0=None, initial_simplex=None, fit_adaption=False):
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
@ -262,6 +276,27 @@ class Fitter:
|
|||||||
|
|
||||||
return sum(error_list)
|
return sum(error_list)
|
||||||
|
|
||||||
|
def cost_function_with_fixed_adaption_with_dend_tau(self, X, tau_a, delta_a, error_weights=None):
|
||||||
|
# set model parameters:
|
||||||
|
model = self.base_model
|
||||||
|
model.set_variable("mem_tau", X[0])
|
||||||
|
model.set_variable("noise_strength", X[1])
|
||||||
|
model.set_variable("input_scaling", X[2])
|
||||||
|
model.set_variable("dend_tau", X[3])
|
||||||
|
model.set_variable("tau_a", tau_a)
|
||||||
|
model.set_variable("delta_a", delta_a)
|
||||||
|
|
||||||
|
base_stimulus = SinusoidalStepStimulus(self.eod_freq, 0)
|
||||||
|
# find right v-offset
|
||||||
|
test_model = model.get_model_copy()
|
||||||
|
test_model.set_variable("noise_strength", 0)
|
||||||
|
v_offset = test_model.find_v_offset(self.baseline_freq, base_stimulus)
|
||||||
|
model.set_variable("v_offset", v_offset)
|
||||||
|
|
||||||
|
error_list = self.calculate_errors(error_weights)
|
||||||
|
|
||||||
|
return sum(error_list)
|
||||||
|
|
||||||
def calculate_errors(self, error_weights=None):
|
def calculate_errors(self, error_weights=None):
|
||||||
baseline_freq, vector_strength, serial_correlation = self.base_model.calculate_baseline_markers(self.eod_freq,
|
baseline_freq, vector_strength, serial_correlation = self.base_model.calculate_baseline_markers(self.eod_freq,
|
||||||
self.sc_max_lag)
|
self.sc_max_lag)
|
||||||
|
Loading…
Reference in New Issue
Block a user