fit without ref period

This commit is contained in:
a.ott 2020-09-12 14:35:17 +02:00
parent f8a8e87f04
commit f1268b291c
10 changed files with 61 additions and 23 deletions

View File

@ -179,7 +179,8 @@ class Fitter:
def fit_routine_no_dend_tau(self, start_parameters, error_weights=None):
self.counter = 0
# fit only v_offset, mem_tau, input_scaling, dend_tau
# fit all except dend_tau
self.base_model.parameters["dend_tau"] = 0
x0 = np.array([start_parameters["mem_tau"], start_parameters["noise_strength"],
start_parameters["input_scaling"], start_parameters["tau_a"],
@ -189,7 +190,7 @@ class Fitter:
# error_list = [error_bf, error_vs, error_sc, error_cv, error_bursty,
# error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope_at_straight, error_f0_curve]
fmin = minimize(fun=self.cost_function_all,
fmin = minimize(fun=self.cost_function_no_dend_tau,
args=(error_weights,), x0=x0, method="Nelder-Mead",
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 600, "maxiter": 400})
@ -208,9 +209,9 @@ class Fitter:
print("tried negative parameter value")
return 1000 + abs(X[i]) * 10000
if X[6] > 1.05/self.eod_freq: # refractory period shouldn't be larger than one eod period
if X[5] > 1.05/self.eod_freq: # refractory period shouldn't be larger than one eod period
print("tried too large ref period")
return 1000 + abs(X[6]) * 10000
return 1000 + abs(X[5]) * 10000
self.base_model.set_variable("mem_tau", X[0])
self.base_model.set_variable("noise_strength", X[1])
self.base_model.set_variable("input_scaling", X[2])
@ -238,7 +239,7 @@ class Fitter:
def fit_routine_no_ref_period(self, start_parameters, error_weights=None):
self.counter = 0
# fit only v_offset, mem_tau, input_scaling, dend_tau
# fit all except ref_period
self.base_model.set_variable("refractory_period", 0)
@ -250,7 +251,7 @@ class Fitter:
# error_list = [error_bf, error_vs, error_sc, error_cv, error_bursty,
# error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope_at_straight, error_f0_curve]
fmin = minimize(fun=self.cost_function_all,
fmin = minimize(fun=self.cost_function_no_ref_period,
args=(error_weights,), x0=x0, method="Nelder-Mead",
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 600, "maxiter": 400})
@ -269,9 +270,6 @@ class Fitter:
print("tried negative parameter value")
return 1000 + abs(X[i]) * 10000
if X[6] > 1.05/self.eod_freq: # refractory period shouldn't be larger than one eod period
print("tried too large ref period")
return 1000 + abs(X[6]) * 10000
self.base_model.set_variable("mem_tau", X[0])
self.base_model.set_variable("noise_strength", X[1])
self.base_model.set_variable("input_scaling", X[2])
@ -299,9 +297,10 @@ class Fitter:
def fit_routine_no_dend_tau_and_no_ref_period(self, start_parameters, error_weights=None):
self.counter = 0
# fit only v_offset, mem_tau, input_scaling, dend_tau
self.base_model.set_variable("refractory_period", 0)
# fit all except dend_tau and ref_period
self.base_model.parameters["refractory_period"] = 0
self.base_model.parameters["dend_tau"] = 0
x0 = np.array([start_parameters["mem_tau"], start_parameters["noise_strength"],
start_parameters["input_scaling"], start_parameters["tau_a"], start_parameters["delta_a"]])
initial_simplex = create_init_simples(x0, search_scale=3)
@ -309,7 +308,7 @@ class Fitter:
# error_list = [error_bf, error_vs, error_sc, error_cv, error_bursty,
# error_f_inf, error_f_inf_slope, error_f_zero, error_f_zero_slope_at_straight, error_f0_curve]
fmin = minimize(fun=self.cost_function_all,
fmin = minimize(fun=self.cost_function_no_dend_tau_and_no_ref_period,
args=(error_weights,), x0=x0, method="Nelder-Mead",
options={"initial_simplex": initial_simplex, "xatol": 0.001, "maxfev": 600, "maxiter": 400})
@ -328,9 +327,6 @@ class Fitter:
print("tried negative parameter value")
return 1000 + abs(X[i]) * 10000
if X[6] > 1.05/self.eod_freq: # refractory period shouldn't be larger than one eod period
print("tried too large ref period")
return 1000 + abs(X[6]) * 10000
self.base_model.set_variable("mem_tau", X[0])
self.base_model.set_variable("noise_strength", X[1])
self.base_model.set_variable("input_scaling", X[2])

View File

@ -229,7 +229,8 @@ def binary_search_base_freq(model: LifacNoiseModel, base_stimulus, goal_frequenc
raise ValueError("binary_search_base_freq() - LifacNoiseModel: Goal frequency might be nan?")
if abs(upper_bound - lower_bound) < 0.0001:
print("v_offset search stopped. bounds converged")
print("v_offset search stopped. bounds converged! freq: {:.2f}, lower {:.1f}, upper: {:.1f}"
.format(frequency, lower_bound, upper_bound))
warn("Search was stopped. Upper and lower bounds converged without finding a value closer than threshold!")
return middle

View File

@ -13,23 +13,64 @@ def main():
param_values = get_parameter_distributions(folder)
plot_distributions(param_values)
get_gauss_fits(param_values)
pass
def get_gauss_fits(param_values):
gauss_fits = {}
num_of_bins = 30
# keys = ['delta_a', 'dend_tau', 'input_scaling', 'mem_tau', 'noise_strength', 'refractory_period', 'tau_a', 'v_offset']
key = 'v_offset'
values = param_values[key]
bins = calculate_bins(values, num_of_bins)
normal, n_bins, patches = plt.hist(values, bins=bins, density=True)
plt.close()
# fit gauss:
bin_width = np.mean(np.diff(n_bins))
middle_of_bins = n_bins + bin_width / 2
# try:
# n_gauss_pars = fit_gauss(middle_of_bins[:-1], normal)
# x = np.arange(min(param_values[key]), max(param_values[key]),
# (max(param_values[key]) - min(param_values[key])) / 100)
# axes[i, 0].plot(x, fu.gauss(x, n_gauss_pars[0], n_gauss_pars[1], n_gauss_pars[2]))
# pass
def calculate_bins(values, num_of_bins):
minimum = np.min(values)
maximum = np.max(values)
step = (maximum - minimum) / (num_of_bins-1)
bins = np.arange(minimum-0.5*step, maximum + step, step)
print(minimum, maximum)
print(bins)
return bins
def plot_distributions(param_values):
bin_number = 30
fig, axes = plt.subplots(len(param_values.keys()), 2)
print(sorted(param_values.keys()))
for i, key in enumerate(sorted(param_values.keys())):
# normal hist:
values = param_values[key]
normal, n_bins, patches = axes[i, 0].hist(values, bins=bin_number, density=True)
bins = calculate_bins(values, bin_number)
print("bins:", len(bins))
normal, n_bins, patches = axes[i, 0].hist(values, bins=calculate_bins(values, bin_number), density=True)
axes[i, 0].set_title(key)
# fit gauss:
bin_width = np.mean(np.diff(n_bins))
middle_of_bins = n_bins + bin_width / 2
print("mid_bins:", len(middle_of_bins))
axes[i, 0].plot(middle_of_bins[:-1], normal, 'o')
try:
n_gauss_pars = fit_gauss(middle_of_bins[:-1], normal)

View File

@ -14,8 +14,8 @@ from helperFunctions import plot_errors
import multiprocessing as mp
SAVE_DIRECTORY = "./results/final_3/"
SAVE_DIRECTORY_BEST = "./results/final_3_best/"
SAVE_DIRECTORY = "./results/ref_and_tau/no_ref_period"
SAVE_DIRECTORY_BEST = "./results/ref_and_tau/nrp_best"
# [vs, sc, cv, isi_hist, bursty, f_inf, f_inf_slope, f_zero, f_zero_slope, f0_curve]
ERROR_WEIGHTS = (1, 1, 1, 1, 1, 1, 1, 1, 0, 1)
@ -31,7 +31,7 @@ def main():
quit()
# test_single_cell("data/invivo/2010-11-08-al-invivo-1/")
test_single_cell("data/invivo_bursty/2013-04-09-ac-invivo-1/")
test_single_cell("data/ref_and_dend_set/2012-12-21-am-invivo-1/")
# start_parameters = [p for p in iget_start_parameters()]
# cell_data = CellData("data/invivo_bursty/2014-03-19-ae-invivo-1/")
@ -60,7 +60,7 @@ def fit_cell_base(parameters):
time1 = time.time()
fitter = Fitter()
fitter.set_data_reference_values(parameters[0])
fmin, res_par = fitter.fit_routine(parameters[2], ERROR_WEIGHTS)
fmin, res_par = fitter.fit_routine_no_ref_period(parameters[2], ERROR_WEIGHTS)
cell_data = parameters[0]
cell_name = os.path.split(cell_data.get_data_path())[-1]

View File

@ -1,5 +1,5 @@
for file in data/final/*; do
for file in data/ref_and_dend_set/*; do
if [ -d "$file" ]; then
nice python3 run_Fitter.py --cell $file
fi

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 15 KiB