improve search for v-offset
This commit is contained in:
parent
cef2f7a016
commit
c841bed77e
@ -244,9 +244,9 @@ class LifacNoiseModel(AbstractModel):
|
||||
test_model = self.get_model_copy()
|
||||
simulation_length = 5
|
||||
|
||||
v_search_step_size = 1000
|
||||
v_search_step_size = 100
|
||||
|
||||
current_v_offset = 0
|
||||
current_v_offset = -400
|
||||
|
||||
current_freq = test_v_offset(test_model, current_v_offset, base_stimulus, simulation_length)
|
||||
|
||||
@ -256,9 +256,6 @@ 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
|
||||
|
||||
lower_bound = current_v_offset - v_search_step_size
|
||||
upper_bound = current_v_offset
|
||||
|
||||
@ -275,26 +272,33 @@ def binary_search_base_freq(model: LifacNoiseModel, base_stimulus, goal_frequenc
|
||||
frequency = test_v_offset(model, middle, base_stimulus, simulation_length)
|
||||
|
||||
# print('{:.1f}, {:.1f}, {:.1f}, {:.1f} vs {:.1f} '.format(lower_bound, middle, upper_bound, frequency, goal_frequency))
|
||||
|
||||
if abs(frequency - goal_frequency) < threshold:
|
||||
return middle
|
||||
elif frequency < goal_frequency:
|
||||
lower_bound = middle
|
||||
elif frequency > goal_frequency:
|
||||
upper_bound = middle
|
||||
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))
|
||||
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!")
|
||||
return middle
|
||||
|
||||
|
||||
def test_v_offset(model: LifacNoiseModel, v_offset, base_stimulus, simulation_length):
|
||||
model.set_variable("v_offset", v_offset)
|
||||
_, spiketimes = model.simulate_fast(base_stimulus, simulation_length)
|
||||
v, spiketimes = model.simulate_fast(base_stimulus, simulation_length)
|
||||
|
||||
freq = hF.mean_freq_of_spiketimes_after_time_x(spiketimes, simulation_length / 3)
|
||||
|
||||
# if freq > 10000:
|
||||
# from IPython import embed
|
||||
# import matplotlib.pyplot as plt
|
||||
# embed()
|
||||
|
||||
return freq
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user