commit all..
This commit is contained in:
@@ -32,6 +32,7 @@ class LifacNoiseModel(AbstractModel):
|
||||
if self.parameters["step_size"] > 0.0001:
|
||||
warn("LifacNoiseModel: The step size is quite big simulation could fail.")
|
||||
self.voltage_trace = []
|
||||
self.input_voltage = []
|
||||
self.adaption_trace = []
|
||||
self.spiketimes = []
|
||||
self.stimulus = None
|
||||
@@ -43,18 +44,19 @@ class LifacNoiseModel(AbstractModel):
|
||||
time = np.arange(0, total_time_s, self.parameters["step_size"])
|
||||
output_voltage = np.zeros(len(time), dtype='float64')
|
||||
adaption = np.zeros(len(time), dtype='float64')
|
||||
input_voltage = np.zeros(len(time), dtype='float64')
|
||||
spiketimes = []
|
||||
|
||||
current_v = self.parameters["v_zero"]
|
||||
current_a = self.parameters["a_zero"]
|
||||
input_voltage[0] = fu.rectify(stimulus.value_at_time_in_s(time[0]))
|
||||
output_voltage[0] = current_v
|
||||
adaption[0] = current_a
|
||||
|
||||
for i in range(1, len(time), 1):
|
||||
time_point = time[i]
|
||||
# rectified input:
|
||||
stimulus_strength = fu.rectify(stimulus.value_at_time_in_s(time_point)) * self.parameters["input_scaling"]
|
||||
|
||||
stimulus_strength = self._calculate_input_voltage_step(input_voltage[i-1], fu.rectify(stimulus.value_at_time_in_s(time_point)))
|
||||
v_next = self._calculate_voltage_step(current_v, stimulus_strength - current_a)
|
||||
a_next = self._calculate_adaption_step(current_a)
|
||||
|
||||
@@ -65,6 +67,7 @@ class LifacNoiseModel(AbstractModel):
|
||||
|
||||
output_voltage[i] = v_next
|
||||
adaption[i] = a_next
|
||||
input_voltage[i] = stimulus_strength
|
||||
|
||||
current_v = v_next
|
||||
current_a = a_next
|
||||
@@ -72,6 +75,7 @@ class LifacNoiseModel(AbstractModel):
|
||||
self.voltage_trace = output_voltage
|
||||
self.adaption_trace = adaption
|
||||
self.spiketimes = spiketimes
|
||||
self.input_voltage = input_voltage
|
||||
|
||||
return output_voltage, spiketimes
|
||||
|
||||
@@ -91,6 +95,10 @@ class LifacNoiseModel(AbstractModel):
|
||||
step_size = self.parameters["step_size"]
|
||||
return current_a + (step_size * (-current_a)) / self.parameters["tau_a"]
|
||||
|
||||
def _calculate_input_voltage_step(self, current_i, rectified_input):
|
||||
# input_voltage[i] = input_voltage[i - 1] + (-input_voltage[i - 1] + rectified_stimulus_array[i] * input_scaling) / dend_tau
|
||||
return current_i + ((-current_i + rectified_input * self.parameters["input_scaling"]) / self.parameters["dend_tau"]) * self.parameters["step_size"]
|
||||
|
||||
def simulate_fast(self, stimulus: AbstractStimulus, total_time_s, time_start=0):
|
||||
|
||||
v_zero = self.parameters["v_zero"]
|
||||
@@ -109,9 +117,10 @@ class LifacNoiseModel(AbstractModel):
|
||||
rectified_stimulus = rectify_stimulus_array(stimulus.as_array(time_start, total_time_s, step_size))
|
||||
parameters = np.array([v_zero, a_zero, step_size, threshold, v_base, delta_a, tau_a, v_offset, mem_tau, noise_strength, time_start, input_scaling, dend_tau])
|
||||
|
||||
voltage_trace, adaption, spiketimes = simulate_fast(rectified_stimulus, total_time_s, parameters)
|
||||
voltage_trace, adaption, spiketimes, input_voltage = simulate_fast(rectified_stimulus, total_time_s, parameters)
|
||||
|
||||
self.stimulus = stimulus
|
||||
self.input_voltage = input_voltage
|
||||
self.voltage_trace = voltage_trace
|
||||
self.adaption_trace = adaption
|
||||
self.spiketimes = spiketimes
|
||||
@@ -207,32 +216,36 @@ class LifacNoiseModel(AbstractModel):
|
||||
|
||||
def calculate_fi_curve(self, contrasts, stimulus_freq):
|
||||
|
||||
max_time_constant = max([self.parameters["tau_a"], self.parameters["mem_tau"]])
|
||||
factor_to_equilibrium = 5
|
||||
stim_duration = max_time_constant * factor_to_equilibrium
|
||||
stim_start = max_time_constant * factor_to_equilibrium
|
||||
total_simulation_time = max_time_constant * factor_to_equilibrium * 3
|
||||
|
||||
stim_duration = 0.5
|
||||
stim_start = 0.5
|
||||
total_simulation_time = stim_duration + 2 * stim_start
|
||||
# print("Total simulation time (vs 2.5) {:.2f}".format(total_simulation_time))
|
||||
|
||||
sampling_interval = self.get_sampling_interval()
|
||||
f_infinities = []
|
||||
f_zeros = []
|
||||
f_baselines = []
|
||||
import matplotlib.pyplot as plt
|
||||
for c in contrasts:
|
||||
stimulus = SinusoidalStepStimulus(stimulus_freq, c, stim_start, stim_duration)
|
||||
_, spiketimes = self.simulate_fast(stimulus, total_simulation_time)
|
||||
|
||||
# if len(spiketimes) > 0:
|
||||
# print("min:", min(spiketimes), "max:", max(spiketimes), "len:", len(spiketimes))
|
||||
# else:
|
||||
# print("spiketimes empty")
|
||||
time, frequency = hF.calculate_time_and_frequency_trace(spiketimes, sampling_interval)
|
||||
# if c == contrasts[0] or c == contrasts[-1]:
|
||||
# plt.plot(frequency)
|
||||
# plt.show()
|
||||
|
||||
if len(time) == 0 or time[0] >= stim_start or len(spiketimes) < 5:
|
||||
if len(spiketimes) < 10 or len(time) == 0 or min(time) > stim_start or max(time) < stim_start+stim_duration:
|
||||
print("Too few spikes to calculate f_inf, f_0 and f_base")
|
||||
f_infinities.append(0)
|
||||
f_zeros.append(0)
|
||||
f_baselines.append(0)
|
||||
continue
|
||||
|
||||
f_inf = hF.detect_f_infinity_in_freq_trace(time, frequency, stim_start, stim_duration, sampling_interval)
|
||||
f_infinities.append(f_inf)
|
||||
|
||||
@@ -242,7 +255,7 @@ class LifacNoiseModel(AbstractModel):
|
||||
f_baseline = hF.detect_f_baseline_in_freq_trace(time, frequency, stim_start, sampling_interval)
|
||||
f_baselines.append(f_baseline)
|
||||
|
||||
|
||||
# import matplotlib.pyplot as plt
|
||||
# fig, axes = plt.subplots(2, 1, sharex="all")
|
||||
# stim_time = np.arange(0,3.5, sampling_interval)
|
||||
# axes[0].set_title("Contrast: " + str(c))
|
||||
@@ -359,8 +372,8 @@ def simulate_fast(rectified_stimulus_array, total_time_s, parameters: np.ndarray
|
||||
noise_value = np.random.normal()
|
||||
noise = noise_strength * noise_value / np.sqrt(step_size)
|
||||
|
||||
input_voltage[i] = input_voltage[i - 1] + (-input_voltage[i - 1] + rectified_stimulus_array[i] * input_scaling) / dend_tau
|
||||
output_voltage[i] = output_voltage[i-1] + ((v_base - output_voltage[i-1] + v_offset + (rectified_stimulus_array[i] * input_scaling) - adaption[i-1] + noise) / mem_tau) * step_size
|
||||
input_voltage[i] = input_voltage[i - 1] + ((-input_voltage[i - 1] + rectified_stimulus_array[i]) / dend_tau) * step_size
|
||||
output_voltage[i] = output_voltage[i-1] + ((v_base - output_voltage[i-1] + v_offset + (input_voltage[i] * input_scaling) - adaption[i-1] + noise) / mem_tau) * step_size
|
||||
adaption[i] = adaption[i-1] + ((-adaption[i-1]) / tau_a) * step_size
|
||||
|
||||
if output_voltage[i] > threshold:
|
||||
@@ -368,7 +381,7 @@ def simulate_fast(rectified_stimulus_array, total_time_s, parameters: np.ndarray
|
||||
spiketimes.append(i*step_size)
|
||||
adaption[i] += delta_a / tau_a
|
||||
|
||||
return output_voltage, adaption, spiketimes
|
||||
return output_voltage, adaption, spiketimes, input_voltage
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user