general changes in search for relation
This commit is contained in:
parent
6cd4e13da4
commit
d274f19f3c
@ -10,21 +10,21 @@ import functions as fu
|
||||
|
||||
|
||||
def main():
|
||||
values = np.arange(2, 18, 1)
|
||||
parameter = "threshold"
|
||||
values = [1] # np.arange(5, 40, 1)
|
||||
parameter = "currently not active"
|
||||
for value in values:
|
||||
lifac_model = LIFACModel({"delta_a": 0})
|
||||
lifac_model.set_variable(parameter, value)
|
||||
# lifac_model.set_variable(parameter, value)
|
||||
stimulus_strengths = np.arange(50, 60, 1)
|
||||
|
||||
line_vars, boltzmann_vars = find_fitting_boltzmann(lifac_model, stimulus_strengths)
|
||||
relation = find_relation(lifac_model, line_vars, boltzmann_vars, stimulus_strengths)
|
||||
line_vars = find_fitting_line(lifac_model, stimulus_strengths)
|
||||
relation = find_relation(lifac_model, line_vars, stimulus_strengths, confirm=True)
|
||||
|
||||
print("threshold:", value)
|
||||
print(parameter, value)
|
||||
print(relation)
|
||||
|
||||
|
||||
def find_fitting_boltzmann(lifac_model, stimulus_strengths):
|
||||
def find_fitting_line(lifac_model, stimulus_strengths):
|
||||
# Requires a lifac model with adaption delta_a = 0, so just the base is fit
|
||||
frequencies = []
|
||||
|
||||
@ -41,31 +41,32 @@ def find_fitting_boltzmann(lifac_model, stimulus_strengths):
|
||||
frequencies.append(freq[-1])
|
||||
|
||||
popt, pcov = curve_fit(fu.line, stimulus_strengths, frequencies)
|
||||
popt2, pcov = curve_fit(fu.full_boltzmann, stimulus_strengths, frequencies, p0=[700, 0, 5, 25], bounds=([0, 0, -np.inf, -np.inf], [3000, 0.001, np.inf, np.inf]))
|
||||
print("line:", popt)
|
||||
print("boltzmann:", popt2)
|
||||
# popt2, pcov = curve_fit(fu.full_boltzmann, stimulus_strengths, frequencies, p0=[700, 0, 5, 25], bounds=([0, 0, -np.inf, -np.inf], [3000, 0.001, np.inf, np.inf]))
|
||||
# print("boltzmann:", popt2)
|
||||
# plt.plot(stimulus_strengths, frequencies)
|
||||
# plt.plot(stimulus_strengths, [fu.line(x, popt[0], popt[1]) for x in stimulus_strengths], '.')
|
||||
# plt.plot(stimulus_strengths, [fu.full_boltzmann(x, popt2[0], popt2[1], popt2[2], popt2[3]) for x in stimulus_strengths], 'o')
|
||||
# plt.show()
|
||||
return popt, popt2
|
||||
return popt # , popt2
|
||||
|
||||
|
||||
def find_relation(lifac, line_vars, boltzmann_vars, stimulus_strengths, use_line=True):
|
||||
def find_relation(lifac, line_vars, stimulus_strengths, parameter="", value=0, confirm=False):
|
||||
# boltzmann_vars = [2.00728705e+02, 1.09905953e-12, 1.03639686e-01, 2.55002788e+01]
|
||||
# line_vars = [5.10369405, -29.79774806]
|
||||
# example values for base lifac (15.1.20) and stimulus 20-32
|
||||
|
||||
duration = 0.1
|
||||
duration = 0.4
|
||||
|
||||
lifac_adaption_strength_range = np.arange(0, 3.1, 0.5)
|
||||
lifac_adaption_strength_range = np.arange(0, 0.31, 0.05)
|
||||
firerate_adaption_variables = []
|
||||
for lifac_adaption_strength in lifac_adaption_strength_range:
|
||||
print(lifac_adaption_strength)
|
||||
lifac.set_variable("delta_a", lifac_adaption_strength)
|
||||
lifac.set_variable("tau_a", 10)
|
||||
lifac.set_variable("tau_a", 40)
|
||||
|
||||
adapted_frequencies = []
|
||||
firerate_adaption_strengths = []
|
||||
for stim in stimulus_strengths:
|
||||
#print("stim:", stim)
|
||||
stimulus = StepStimulus(0, duration, stim)
|
||||
@ -74,25 +75,20 @@ def find_relation(lifac, line_vars, boltzmann_vars, stimulus_strengths, use_line
|
||||
time, freq = hf.calculate_isi_frequency(spiketimes, 0, lifac.get_sampling_interval()/1000)
|
||||
|
||||
adapted_frequencies.append(freq[-1])
|
||||
goal_adapted_freq = freq[-1]
|
||||
|
||||
firerate_adaption_strengths = []
|
||||
for i in range(len(adapted_frequencies)):
|
||||
goal_adapted_freq = adapted_frequencies[i]
|
||||
|
||||
if use_line:
|
||||
# assume fitted linear firing rate as basis of the fire-rate model:
|
||||
stimulus_strength_after_adaption = fu.inverse_line(goal_adapted_freq, line_vars[0], line_vars[1])
|
||||
else:
|
||||
# assume fitted boltzmann firing rate as basis of the fire-rate model:
|
||||
stimulus_strength_after_adaption = fu.inverse_full_boltzmann(goal_adapted_freq,
|
||||
boltzmann_vars[0],
|
||||
boltzmann_vars[1],
|
||||
boltzmann_vars[2],
|
||||
boltzmann_vars[3],)
|
||||
|
||||
adaption_strength = stimulus_strengths[i] - stimulus_strength_after_adaption
|
||||
# assume fitted linear firing rate as basis of the fire-rate model:
|
||||
stimulus_strength_after_adaption = fu.inverse_line(goal_adapted_freq, line_vars[0], line_vars[1])
|
||||
|
||||
# needed adaption strength
|
||||
adaption_strength = stim - stimulus_strength_after_adaption
|
||||
# adaption variable in model:
|
||||
firerate_adaption = adaption_strength / goal_adapted_freq
|
||||
|
||||
# test in model if calculated
|
||||
if confirm:
|
||||
test_adaption_strength_in_firerate_model(line_vars, firerate_adaption, stimulus, goal_adapted_freq)
|
||||
|
||||
firerate_adaption_strengths.append(firerate_adaption)
|
||||
|
||||
firerate_adaption_variables.append(firerate_adaption_strengths)
|
||||
@ -101,15 +97,20 @@ def find_relation(lifac, line_vars, boltzmann_vars, stimulus_strengths, use_line
|
||||
# plt.show()
|
||||
|
||||
for i in range(len(lifac_adaption_strength_range)):
|
||||
plt.plot([lifac_adaption_strength_range[i]+p*0.01 for p in range(len(stimulus_strengths))], firerate_adaption_variables[i])
|
||||
plt.plot([lifac_adaption_strength_range[i]+p*0.001 for p in range(len(stimulus_strengths))], firerate_adaption_variables[i])
|
||||
|
||||
mean_firerate_adaption_value = [np.mean(strengths) for strengths in firerate_adaption_variables]
|
||||
mean_firerate_adaption_value = [np.median(strengths) for strengths in firerate_adaption_variables]
|
||||
|
||||
plt.plot(lifac_adaption_strength_range, mean_firerate_adaption_value)
|
||||
plt.title("Relation of adaption strength variables:\n Small 'subplots' value for different stimulus strength")
|
||||
l_vars, x = curve_fit(fu.line, lifac_adaption_strength_range, mean_firerate_adaption_value)
|
||||
plt.plot(lifac_adaption_strength_range, mean_firerate_adaption_value, label="slope:" + str(round(l_vars[0], 5)))
|
||||
plt.title("Relation of adaption strength variables:\n Colored points values for different stimulus strengths")
|
||||
plt.xlabel("lifac adaption strength: delta_a")
|
||||
plt.ylabel("firerate adaption strength: alpha")
|
||||
plt.savefig("figures/adaption_relation_threshold_" + str(lifac.get_parameters()["threshold"]) + ".png")
|
||||
plt.legend()
|
||||
if parameter != "":
|
||||
plt.savefig("figures/adaption_relation_" + parameter + "_" + str(value) + ".png")
|
||||
else:
|
||||
plt.savefig("figures/adaption_relation.png")
|
||||
plt.close()
|
||||
popt, pcov = curve_fit(fu.line, lifac_adaption_strength_range, mean_firerate_adaption_value)
|
||||
|
||||
@ -117,6 +118,17 @@ def find_relation(lifac, line_vars, boltzmann_vars, stimulus_strengths, use_line
|
||||
return popt
|
||||
|
||||
|
||||
def test_adaption_strength_in_firerate_model(line_vars, adaption_strength, stimulus, expected_freq):
|
||||
params = {"function_params": line_vars, "adaptation_factor": adaption_strength, "a_tau": 10}
|
||||
model = FirerateModel(params)
|
||||
|
||||
model.simulate(stimulus, 0.2)
|
||||
freq = model.get_frequency()[-1]
|
||||
diff = expected_freq - freq
|
||||
if diff > 0.00001 * expected_freq:
|
||||
print("expected freq:", expected_freq, "=?=", str(freq), ":", str(diff < 0.00001 * expected_freq))
|
||||
|
||||
|
||||
def test_firerate_model( boltzmann_vars):
|
||||
fr_model = FirerateModel(params={"function_params": boltzmann_vars, "adaptation_factor": 0})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user