138 lines
5.7 KiB
Python
138 lines
5.7 KiB
Python
|
|
from models.FirerateModel import FirerateModel
|
|
from models.LIFAC import LIFACModel
|
|
from stimuli.StepStimulus import StepStimulus
|
|
import helperFunctions as hf
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
from scipy.optimize import curve_fit
|
|
import functions as fu
|
|
|
|
|
|
def main():
|
|
values = np.arange(2, 18, 1)
|
|
parameter = "threshold"
|
|
for value in values:
|
|
lifac_model = LIFACModel({"delta_a": 0})
|
|
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)
|
|
|
|
print("threshold:", value)
|
|
print(relation)
|
|
|
|
|
|
def find_fitting_boltzmann(lifac_model, stimulus_strengths):
|
|
# Requires a lifac model with adaption delta_a = 0, so just the base is fit
|
|
frequencies = []
|
|
|
|
duration = 0.2
|
|
for stim_strength in stimulus_strengths:
|
|
lifac_model.simulate(StepStimulus(0, duration, stim_strength), duration)
|
|
|
|
spiketimes = lifac_model.get_spiketimes()
|
|
if len(spiketimes) == 0:
|
|
frequencies.append(0)
|
|
continue
|
|
time, freq = hf.calculate_isi_frequency(spiketimes, 0, lifac_model.get_sampling_interval() / 1000)
|
|
|
|
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)
|
|
# 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
|
|
|
|
|
|
def find_relation(lifac, line_vars, boltzmann_vars, stimulus_strengths, use_line=True):
|
|
# 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
|
|
|
|
lifac_adaption_strength_range = np.arange(0, 3.1, 0.5)
|
|
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)
|
|
|
|
adapted_frequencies = []
|
|
for stim in stimulus_strengths:
|
|
#print("stim:", stim)
|
|
stimulus = StepStimulus(0, duration, stim)
|
|
lifac.simulate(stimulus, duration)
|
|
spiketimes = lifac.get_spiketimes()
|
|
time, freq = hf.calculate_isi_frequency(spiketimes, 0, lifac.get_sampling_interval()/1000)
|
|
|
|
adapted_frequencies.append(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
|
|
|
|
firerate_adaption = adaption_strength / goal_adapted_freq
|
|
firerate_adaption_strengths.append(firerate_adaption)
|
|
|
|
firerate_adaption_variables.append(firerate_adaption_strengths)
|
|
|
|
# plt.plot(stimulus_range, firerate_adaption_strength, label=str(lifac_adaption_strength))
|
|
# 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])
|
|
|
|
mean_firerate_adaption_value = [np.mean(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")
|
|
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.close()
|
|
popt, pcov = curve_fit(fu.line, lifac_adaption_strength_range, mean_firerate_adaption_value)
|
|
|
|
# print(popt)
|
|
return popt
|
|
|
|
|
|
def test_firerate_model( boltzmann_vars):
|
|
fr_model = FirerateModel(params={"function_params": boltzmann_vars, "adaptation_factor": 0})
|
|
|
|
frequencies = []
|
|
stim_strengths = np.arange(0, 50, 0.5)
|
|
duration = 0.5
|
|
for stim_strength in stim_strengths:
|
|
fr_model.simulate(StepStimulus(0, duration, stim_strength), duration)
|
|
|
|
frequencies.append(fr_model.get_frequency()[-1])
|
|
|
|
plt.plot(stim_strengths, frequencies)
|
|
plt.plot(np.arange(20, 32, 1), [fu.line(x, 5.10369, -29.7977481) for x in np.arange(20, 32, 1)], 'o')
|
|
plt.show()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|