123 lines
4.9 KiB
Python
123 lines
4.9 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():
|
|
#boltzmann_vars = find_fitting_boltzmann()
|
|
#test_firerate_model(boltzmann_vars)
|
|
find_relation()
|
|
|
|
def find_fitting_boltzmann():
|
|
lifac = LIFACModel({"delta_a": 0})
|
|
|
|
frequencies = []
|
|
stim_strengths = np.arange(20, 32, 0.5)
|
|
duration = 0.5
|
|
for stim_strength in stim_strengths:
|
|
lifac.simulate(StepStimulus(0, duration, stim_strength), duration)
|
|
|
|
spiketimes = lifac.get_spiketimes()
|
|
if len(spiketimes) == 0:
|
|
frequencies.append(0)
|
|
continue
|
|
time, freq = hf.calculate_isi_frequency(spiketimes, 0, lifac.get_sampling_interval()/1000)
|
|
|
|
frequencies.append(freq[-1])
|
|
|
|
popt, pcov = curve_fit(fu.line, stim_strengths, frequencies)
|
|
popt2, pcov = curve_fit(fu.full_boltzmann, stim_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(stim_strengths, frequencies)
|
|
# plt.plot(stim_strengths, [fu.line(x, popt[0], popt[1]) for x in stim_strengths], '.')
|
|
# plt.plot(stim_strengths, [fu.full_boltzmann(x, popt2[0], popt2[1], popt2[2], popt2[3]) for x in stim_strengths], 'o')
|
|
# plt.show()
|
|
return popt2
|
|
|
|
|
|
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()
|
|
|
|
|
|
def find_relation():
|
|
stimulus_step_size = 1
|
|
stimulus_range = np.arange(20, 32, stimulus_step_size)
|
|
boltzmann_vars = [2.00728705e+02, 1.09905953e-12, 1.03639686e-01, 2.55002788e+01]
|
|
line_vars = [5.10369405, -29.79774806]
|
|
duration = 0.5
|
|
|
|
lifac_adaption_strength_range = np.arange(0, 3, 0.2)
|
|
firerate_adaption_variables = []
|
|
for lifac_adaption_strength in lifac_adaption_strength_range:
|
|
lifac = LIFACModel({"delta_a": lifac_adaption_strength, "tau_a": 20}, "")
|
|
|
|
adapted_frequencies = []
|
|
for stim in stimulus_range:
|
|
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]
|
|
|
|
# stimulus_strength_after_adaption = fu.inverse_full_boltzmann(goal_adapted_freq,
|
|
# boltzmann_vars[0],
|
|
# boltzmann_vars[1],
|
|
# boltzmann_vars[2],
|
|
# boltzmann_vars[3],)
|
|
|
|
# assume fitted line as basis of the fire-rate model:
|
|
stimulus_strength_after_adaption = fu.inverse_line(goal_adapted_freq, line_vars[0], line_vars[1])
|
|
|
|
adaption_strength = stimulus_range[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_range))], 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_stimulus_strength.png")
|
|
plt.close()
|
|
popt, pcov = curve_fit(fu.line, lifac_adaption_strength_range, mean_firerate_adaption_value)
|
|
|
|
print(popt)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|