This commit is contained in:
alexanderott 2020-06-14 13:47:37 +02:00
commit 7f0c89b65f
4 changed files with 56 additions and 17 deletions

View File

@ -226,7 +226,7 @@ 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:
warn("Search was stopped no value was found!")
warn("Search was stopped. Upper and lower bounds converged without finding a value closer than threshold!")
return middle

View File

@ -49,16 +49,14 @@ def fit_cell_base(parameter):
"\n error: {:.2f}".format(sum(error)))
def fit_all_cells_parallel_sync(cells, start_parameters, results_base_folder):
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))
core_count = mp.cpu_count()
pool = mp.Pool(core_count - 1)
time1 = time.time()
pool.map(fit_cell_base, parameter)
thread_pool.map(fit_cell_base, parameter)
time2 = time.time()
print("Time taken for all cells and start parameters ({:}): {:.2f}s".format(len(parameter), time2 - time1))
@ -273,17 +271,29 @@ def save_fitting_run_info(cell_data, parameters, start_parameters, plot=False, s
def test_effect_of_refractory_period():
ref_periods = np.arange(0.0006, 0.001, 0.0015)
ref_periods = [0.0006, 0.001, 0.0015]
counter = 0
core_count = mp.cpu_count()
pool = mp.Pool(core_count - 1)
for cell in icelldata_of_dir("./data/"):
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)
cells = [c for c in icelldata_of_dir("./data/")]
start_parameters_base = [p for p in iget_start_parameters()]
for ref_period in ref_periods:
results_base_folder = "./test_routines/ref_period_{:.3f}/".format(ref_period)
all_start_parameters = copy.deepcopy(start_parameters_base)
del cell
for par_set in all_start_parameters:
par_set["refractory_period"] = ref_period
fit_all_cells_parallel_sync(cells, all_start_parameters, results_base_folder)
if __name__ == '__main__':
main()

View File

@ -4,6 +4,7 @@ from models.LIFACnoise import LifacNoiseModel
import numpy as np
import matplotlib.pyplot as plt
import helperFunctions as hF
from CellData import CellData
def main():
@ -12,8 +13,23 @@ def main():
'v_base': 0, 'step_size': 5e-05, 'dend_tau': 0.0008667253013050408, 'v_zero': 0, 'v_offset': -6.25,
'noise_strength': 0.03337309379328535, 'a_zero': 2, 'threshold': 1, 'delta_a': 0.0726267312975076}
eod_freq = 658
cell_data = CellData("./data/2012-12-13-ao-invivo-1/")
model = LifacNoiseModel(parameters)
mean_duration = np.mean(cell_data.get_sam_durations())
contrasts = cell_data.get_sam_contrasts()
spiketimes = cell_data.get_sam_spiketimes()
for i, m_freq in enumerate(cell_data.get_sam_delta_frequencies()):
stimulus = SAM(eod_freq, contrasts[i], m_freq)
prob_desnity_function_model = generate_pdf(model, stimulus, sim_length=mean_duration)
for spikes in spiketimes[i]:
prob_density_cell = spiketimes_calculate_pdf(spikes, cell_data.get_sampling_interval())
plt.plot(prob_density_cell)
plt.plot(prob_desnity_function_model)
plt.show()
plt.close()
# __init__(carrier_frequency, contrast, modulation_frequency, start_time=0, duration=np.inf, amplitude=1)
mod_freqs = np.arange(-60, eod_freq*4 + 61, 10)
@ -58,6 +74,19 @@ def generate_pdf(model, stimulus, trials=4, sim_length=3, kernel_width=0.005):
return mean_rate
def spiketimes_calculate_pdf(spikes, step_size, kernel_width=0.005):
length = int(spikes[-1] / step_size)+1
binary = np.zeros(length)
spikes = [int(s / step_size) for s in spikes]
for s_idx in spikes:
binary[s_idx] = 1
kernel = gaussian_kernel(kernel_width, step_size)
rate = np.convolve(binary, kernel, mode='same')
return rate
def gaussian_kernel(sigma, dt):
x = np.arange(-4. * sigma, 4. * sigma, dt)
y = np.exp(-0.5 * (x / sigma) ** 2) / np.sqrt(2. * np.pi) / sigma

View File

@ -46,8 +46,8 @@ def main():
def test_effect_of_two_variables():
eod_freqs = np.arange(100, 1001, 20)
ref_periods = np.arange(0, 0.00201, 0.0001)
eod_freqs = np.arange(100, 1001, 50)
ref_periods = np.arange(0, 0.00201, 0.0002)
variables = ("bf", "vs", "sc", "cv", "burst", "f_inf_s", "f_zero_s")
colorbar_labels = ("Frequency in Hz", "Vector strength", "serial correlation lag=1", "Coefficient of Variation",
"Burstiness", "f_inf slope", "f_zero slope")