add tests for sinusoidalStep, add FiCurve plot possibilities (temp), add initial simplex generation
This commit is contained in:
@@ -21,7 +21,7 @@ class LifacNoiseModel(AbstractModel):
|
||||
"input_scaling": 60,
|
||||
"delta_a": 0.08,
|
||||
"tau_a": 0.1,
|
||||
"a_zero": 10,
|
||||
"a_zero": 2,
|
||||
"noise_strength": 0.05,
|
||||
"step_size": 0.00005}
|
||||
|
||||
@@ -157,14 +157,14 @@ class LifacNoiseModel(AbstractModel):
|
||||
def get_model_copy(self):
|
||||
return LifacNoiseModel(self.parameters)
|
||||
|
||||
def calculate_baseline_markers(self, base_stimulus_freq, max_lag=1):
|
||||
def calculate_baseline_markers(self, stimulus_freq, max_lag=1):
|
||||
"""
|
||||
calculates the baseline markers baseline frequency, vector strength and serial correlation
|
||||
based on simulated 30 seconds with a standard Sinusoidal stimulus with the given frequency
|
||||
|
||||
:return: baseline_freq, vs, sc
|
||||
"""
|
||||
base_stimulus = SinusoidalStepStimulus(base_stimulus_freq, 0)
|
||||
base_stimulus = SinusoidalStepStimulus(stimulus_freq, 0)
|
||||
_, spiketimes = self.simulate_fast(base_stimulus, 30)
|
||||
time_x = 5
|
||||
baseline_freq = hF.mean_freq_of_spiketimes_after_time_x(spiketimes, time_x)
|
||||
@@ -181,7 +181,7 @@ class LifacNoiseModel(AbstractModel):
|
||||
|
||||
return baseline_freq, vector_strength, serial_correlation
|
||||
|
||||
def calculate_fi_markers(self, contrasts, base_freq, modulation_frequency):
|
||||
def calculate_fi_markers(self, contrasts, stimulus_freq):
|
||||
"""
|
||||
calculates the fi markers f_infinity, f_infinity_slope for given contrasts
|
||||
based on simulated 2 seconds for each contrast
|
||||
@@ -190,7 +190,7 @@ class LifacNoiseModel(AbstractModel):
|
||||
|
||||
f_infinities = []
|
||||
for contrast in contrasts:
|
||||
stimulus = SinusoidalStepStimulus(base_freq, contrast)
|
||||
stimulus = SinusoidalStepStimulus(stimulus_freq, contrast)
|
||||
_, spiketimes = self.simulate_fast(stimulus, 1)
|
||||
|
||||
f_infinity = hF.mean_freq_of_spiketimes_after_time_x(spiketimes, 0.3)
|
||||
@@ -202,7 +202,45 @@ class LifacNoiseModel(AbstractModel):
|
||||
|
||||
return f_infinities, f_infinities_slope
|
||||
|
||||
def find_v_offset(self, goal_baseline_frequency, base_stimulus, threshold=10, border=50000):
|
||||
def calculate_fi_curve(self, contrasts, stimulus_freq):
|
||||
stim_duration = 1
|
||||
stim_start = 1
|
||||
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, 3.5)
|
||||
|
||||
time, frequency = hF.calculate_time_and_frequency_trace(spiketimes, sampling_interval)
|
||||
|
||||
f_inf = hF.detect_f_infinity_in_freq_trace(time, frequency, stim_start, stim_duration, sampling_interval)
|
||||
f_infinities.append(f_inf)
|
||||
|
||||
f_zero = hF.detect_f_zero_in_frequency_trace(time, frequency, stim_start, sampling_interval)
|
||||
f_zeros.append(f_zero)
|
||||
|
||||
f_baseline = hF.detect_f_baseline_in_freq_trace(time, frequency, stim_start, sampling_interval)
|
||||
f_baselines.append(f_baseline)
|
||||
|
||||
|
||||
# fig, axes = plt.subplots(2, 1, sharex="all")
|
||||
# stim_time = np.arange(0,3.5, sampling_interval)
|
||||
# axes[0].set_title("Contrast: " + str(c))
|
||||
# axes[0].plot(stim_time, [stimulus.value_at_time_in_s(t) for t in stim_time]) # stimulus.as_array(0, 3.5, sampling_interval))
|
||||
#
|
||||
# axes[1].plot(time, frequency)
|
||||
# axes[1].plot((time[0], time[-1]), (f_inf, f_inf), label="inf")
|
||||
# axes[1].plot((time[0], time[-1]), (f_zero, f_zero), label="zero")
|
||||
# axes[1].plot((time[0], time[-1]), (f_baseline, f_baseline), label="base")
|
||||
# plt.legend()
|
||||
# plt.show()
|
||||
|
||||
return f_baselines, f_zeros, f_infinities
|
||||
|
||||
def find_v_offset(self, goal_baseline_frequency, base_stimulus, threshold=2, border=50000):
|
||||
test_model = self.get_model_copy()
|
||||
simulation_length = 5
|
||||
|
||||
@@ -218,8 +256,8 @@ class LifacNoiseModel(AbstractModel):
|
||||
current_v_offset += v_search_step_size
|
||||
current_freq = test_v_offset(test_model, current_v_offset, base_stimulus, simulation_length)
|
||||
|
||||
if current_v_offset == 0:
|
||||
return -1000
|
||||
# if current_v_offset == 0:
|
||||
# return -1000
|
||||
|
||||
lower_bound = current_v_offset - v_search_step_size
|
||||
upper_bound = current_v_offset
|
||||
@@ -235,8 +273,7 @@ def binary_search_base_freq(model: LifacNoiseModel, base_stimulus, goal_frequenc
|
||||
counter += 1
|
||||
middle = upper_bound - (upper_bound - lower_bound)/2
|
||||
frequency = test_v_offset(model, middle, base_stimulus, simulation_length)
|
||||
if counter > 100:
|
||||
print("meep")
|
||||
|
||||
# print('{:.1f}, {:.1f}, {:.1f}, {:.1f} vs {:.1f} '.format(lower_bound, middle, upper_bound, frequency, goal_frequency))
|
||||
if abs(frequency - goal_frequency) < threshold:
|
||||
return middle
|
||||
@@ -244,7 +281,8 @@ def binary_search_base_freq(model: LifacNoiseModel, base_stimulus, goal_frequenc
|
||||
lower_bound = middle
|
||||
elif frequency > goal_frequency:
|
||||
upper_bound = middle
|
||||
elif abs(upper_bound-lower_bound) < 0.01 * threshold:
|
||||
elif abs(upper_bound-lower_bound) < 0.001:
|
||||
warn("Search was stopped no value was found!")
|
||||
return middle
|
||||
else:
|
||||
print('lower bound: {:.1f}, middle: {:.1f}, upper_bound: {:.1f}, frequency: {:.1f} vs goal: {:.1f} '.format(lower_bound, middle, upper_bound, frequency, goal_frequency))
|
||||
|
||||
Reference in New Issue
Block a user