change a_delta to start_parameter
This commit is contained in:
parent
92119373c1
commit
e84ac53657
44
Fitter.py
44
Fitter.py
@ -24,20 +24,28 @@ def iget_start_parameters():
|
|||||||
# expand by tau_a, delta_a ?
|
# expand by tau_a, delta_a ?
|
||||||
|
|
||||||
mem_tau_list = [0.01]
|
mem_tau_list = [0.01]
|
||||||
input_scaling_list = [40, 60, 80]
|
input_scaling_list = [40, 60]
|
||||||
noise_strength_list = [0.03] # [0.02, 0.06]
|
noise_strength_list = [0.03] # [0.02, 0.06]
|
||||||
dend_tau_list = [0.001, 0.002]
|
dend_tau_list = [0.001, 0.002]
|
||||||
|
delta_a_list = [0.035, 0.065]
|
||||||
|
|
||||||
for mem_tau in mem_tau_list:
|
for mem_tau in mem_tau_list:
|
||||||
for input_scaling in input_scaling_list:
|
for input_scaling in input_scaling_list:
|
||||||
for noise_strength in noise_strength_list:
|
for noise_strength in noise_strength_list:
|
||||||
for dend_tau in dend_tau_list:
|
for dend_tau in dend_tau_list:
|
||||||
|
for delta_a in delta_a_list:
|
||||||
yield {"mem_tau": mem_tau, "input_scaling": input_scaling,
|
yield {"mem_tau": mem_tau, "input_scaling": input_scaling,
|
||||||
"noise_strength": noise_strength, "dend_tau": dend_tau}
|
"noise_strength": noise_strength, "dend_tau": dend_tau,
|
||||||
|
"delta_a": delta_a}
|
||||||
|
|
||||||
|
|
||||||
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 < 7:
|
||||||
|
pass
|
||||||
|
#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)
|
||||||
@ -181,7 +189,6 @@ class Fitter:
|
|||||||
self.f_zero_fit = []
|
self.f_zero_fit = []
|
||||||
|
|
||||||
self.tau_a = 0
|
self.tau_a = 0
|
||||||
self.delta_a = 0
|
|
||||||
|
|
||||||
# counts how often the cost_function was called
|
# counts how often the cost_function was called
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
@ -209,14 +216,9 @@ class Fitter:
|
|||||||
# around 1/3 of the value at straight
|
# around 1/3 of the value at straight
|
||||||
# self.f_zero_slope = fi_curve.get_fi_curve_slope_at(fi_curve.get_f_zero_and_f_inf_intersection())
|
# self.f_zero_slope = fi_curve.get_fi_curve_slope_at(fi_curve.get_f_zero_and_f_inf_intersection())
|
||||||
|
|
||||||
# seems to work if divided by 1000...
|
adaption = Adaption(fi_curve)
|
||||||
self.delta_a = (fi_curve.get_f_zero_fit_slope_at_straight() / self.f_inf_slope) / 1000
|
|
||||||
|
|
||||||
adaption = Adaption(data, fi_curve)
|
|
||||||
self.tau_a = adaption.get_tau_real()
|
self.tau_a = adaption.get_tau_real()
|
||||||
|
|
||||||
# print("delta_a: {:.3f}".format(self.delta_a), "tau_a: {:.3f}".format(self.tau_a))
|
|
||||||
|
|
||||||
return self.fit_routine_5(data, start_parameters)
|
return self.fit_routine_5(data, start_parameters)
|
||||||
|
|
||||||
def fit_routine_5(self, cell_data=None, start_parameters=None):
|
def fit_routine_5(self, cell_data=None, start_parameters=None):
|
||||||
@ -226,7 +228,8 @@ class Fitter:
|
|||||||
x0 = np.array([0.02, 70, 0.001])
|
x0 = np.array([0.02, 70, 0.001])
|
||||||
else:
|
else:
|
||||||
x0 = np.array([start_parameters["mem_tau"], start_parameters["noise_strength"],
|
x0 = np.array([start_parameters["mem_tau"], start_parameters["noise_strength"],
|
||||||
start_parameters["input_scaling"], self.tau_a, self.delta_a, start_parameters["dend_tau"]])
|
start_parameters["input_scaling"], self.tau_a, start_parameters["delta_a"],
|
||||||
|
start_parameters["dend_tau"]])
|
||||||
initial_simplex = create_init_simples(x0, search_scale=2)
|
initial_simplex = create_init_simples(x0, search_scale=2)
|
||||||
|
|
||||||
# error_list = [error_bf, error_vs, error_sc, error_cv,
|
# error_list = [error_bf, error_vs, error_sc, error_cv,
|
||||||
@ -234,7 +237,7 @@ class Fitter:
|
|||||||
error_weights = (0, 1, 1, 1, 1, 1, 1, 1)
|
error_weights = (0, 1, 1, 1, 1, 1, 1, 1)
|
||||||
fmin = minimize(fun=self.cost_function_all,
|
fmin = minimize(fun=self.cost_function_all,
|
||||||
args=(error_weights,), x0=x0, method="Nelder-Mead",
|
args=(error_weights,), x0=x0, method="Nelder-Mead",
|
||||||
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 400, "maxiter": 400})
|
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 200, "maxiter": 400})
|
||||||
|
|
||||||
if cell_data is not None:
|
if cell_data is not None:
|
||||||
print("##### After step 1: (Everything)")
|
print("##### After step 1: (Everything)")
|
||||||
@ -247,7 +250,7 @@ class Fitter:
|
|||||||
|
|
||||||
if fit_adaption:
|
if fit_adaption:
|
||||||
if x0 is None:
|
if x0 is None:
|
||||||
x0 = np.array([0.02, 0.03, 70, self.tau_a, self.delta_a])
|
x0 = np.array([0.02, 0.03, 70, self.tau_a, 0.05])
|
||||||
if initial_simplex is None:
|
if initial_simplex is None:
|
||||||
initial_simplex = create_init_simples(x0)
|
initial_simplex = create_init_simples(x0)
|
||||||
|
|
||||||
@ -255,11 +258,11 @@ class Fitter:
|
|||||||
method="Nelder-Mead", options={"initial_simplex": initial_simplex})
|
method="Nelder-Mead", options={"initial_simplex": initial_simplex})
|
||||||
else:
|
else:
|
||||||
if x0 is None:
|
if x0 is None:
|
||||||
x0 = np.array([0.02, 0.03, 70])
|
x0 = np.array([0.02, 0.03, 70, 0.05])
|
||||||
if initial_simplex is None:
|
if initial_simplex is None:
|
||||||
initial_simplex = create_init_simples(x0)
|
initial_simplex = create_init_simples(x0)
|
||||||
|
|
||||||
fmin = minimize(fun=self.cost_function_with_fixed_adaption, x0=x0, args=(self.tau_a, self.delta_a),
|
fmin = minimize(fun=self.cost_function_with_fixed_adaption_tau, x0=x0, args=(self.tau_a,),
|
||||||
method="Nelder-Mead", options={"initial_simplex": initial_simplex})
|
method="Nelder-Mead", options={"initial_simplex": initial_simplex})
|
||||||
|
|
||||||
return fmin, self.base_model.get_parameters()
|
return fmin, self.base_model.get_parameters()
|
||||||
@ -320,14 +323,15 @@ class Fitter:
|
|||||||
|
|
||||||
return sum(error_list)
|
return sum(error_list)
|
||||||
|
|
||||||
def cost_function_with_fixed_adaption(self, X, tau_a, delta_a, error_weights=None):
|
def cost_function_with_fixed_adaption_tau(self, X, tau_a, error_weights=None):
|
||||||
# set model parameters:
|
# set model parameters:
|
||||||
model = self.base_model
|
model = self.base_model
|
||||||
model.set_variable("mem_tau", X[0])
|
model.set_variable("mem_tau", X[0])
|
||||||
model.set_variable("noise_strength", X[1])
|
model.set_variable("noise_strength", X[1])
|
||||||
model.set_variable("input_scaling", X[2])
|
model.set_variable("input_scaling", X[2])
|
||||||
|
model.set_variable("delta_a", X[3])
|
||||||
model.set_variable("tau_a", tau_a)
|
model.set_variable("tau_a", tau_a)
|
||||||
model.set_variable("delta_a", delta_a)
|
|
||||||
|
|
||||||
base_stimulus = SinusoidalStepStimulus(self.eod_freq, 0)
|
base_stimulus = SinusoidalStepStimulus(self.eod_freq, 0)
|
||||||
# find right v-offset
|
# find right v-offset
|
||||||
@ -398,12 +402,12 @@ class Fitter:
|
|||||||
|
|
||||||
# calculate errors with reference values
|
# calculate errors with reference values
|
||||||
error_bf = abs((baseline_freq - self.baseline_freq) / self.baseline_freq)
|
error_bf = abs((baseline_freq - self.baseline_freq) / self.baseline_freq)
|
||||||
error_vs = abs((vector_strength - self.vector_strength) / self.vector_strength)
|
error_vs = abs((vector_strength - self.vector_strength) / 0.1)
|
||||||
error_cv = abs((coefficient_of_variation - self.coefficient_of_variation) / self.coefficient_of_variation)
|
error_cv = abs((coefficient_of_variation - self.coefficient_of_variation) / 0.1)
|
||||||
|
|
||||||
error_sc = 0
|
error_sc = 0
|
||||||
for i in range(self.sc_max_lag):
|
for i in range(self.sc_max_lag):
|
||||||
error_sc = abs((serial_correlation[i] - self.serial_correlation[i]) / (self.serial_correlation[i]/10))
|
error_sc = abs((serial_correlation[i] - self.serial_correlation[i]) / 0.1)
|
||||||
error_sc = error_sc / self.sc_max_lag
|
error_sc = error_sc / self.sc_max_lag
|
||||||
|
|
||||||
error_f_inf_slope = abs((f_infinities_slope - self.f_inf_slope) / (self.f_inf_slope/20))
|
error_f_inf_slope = abs((f_infinities_slope - self.f_inf_slope) / (self.f_inf_slope/20))
|
||||||
@ -411,7 +415,7 @@ class Fitter:
|
|||||||
|
|
||||||
# error_f_zero_slopes = calculate_list_error(f_zero_slopes, self.f_zero_slopes)
|
# error_f_zero_slopes = calculate_list_error(f_zero_slopes, self.f_zero_slopes)
|
||||||
error_f_zero_slope_at_straight = abs(self.f_zero_slope_at_straight - f_zero_slope_at_straight) \
|
error_f_zero_slope_at_straight = abs(self.f_zero_slope_at_straight - f_zero_slope_at_straight) \
|
||||||
/ (self.f_zero_slope_at_straight / 20)
|
/ (self.f_zero_slope_at_straight / 10)
|
||||||
error_f_zero = calculate_list_error(f_zeros, self.f_zero_values)
|
error_f_zero = calculate_list_error(f_zeros, self.f_zero_values)
|
||||||
|
|
||||||
error_list = [error_bf, error_vs, error_sc, error_cv,
|
error_list = [error_bf, error_vs, error_sc, error_cv,
|
||||||
|
Loading…
Reference in New Issue
Block a user