hnn-core
hnn-core copied to clipboard
Cell specific drive cell event times are identical across trials (assigned gid changes)
Came across this while analyzing spiking in simulation. For cell_specific
drives simulated with multiple trials, it seems that the spike times are all identical, but the gid they are assigned to gets changed. Is this the intended behavior? It leads to stochasticity in the final simulation, but this was somewhat unexpected to me. Thoughts?
import hnn_core
from hnn_core import jones_2009_model, simulate_dipole
import numpy as np
net = jones_2009_model()
weights_ampa_p2 = {'L2_basket': 0.000003, 'L2_pyramidal': 1.438840,
'L5_basket': 0.008958, 'L5_pyramidal': 0.684013}
synaptic_delays_prox = {'L2_basket': 0.1, 'L2_pyramidal': 0.1,
'L5_basket': 1., 'L5_pyramidal': 1.}
# all NMDA weights are zero; omit weights_nmda (defaults to None)
net.add_evoked_drive(
'prox1', mu=40, sigma=8.33, numspikes=1,
weights_ampa=weights_ampa_p2, location='proximal',
synaptic_delays=synaptic_delays_prox, seedcore=4)
dpl = simulate_dipole(net, tstop=100, dt=0.05, n_trials=2)
print('Artifical Cell Spike Times Match')
spike_times = [np.array(st) for st in net.cell_response.spike_times]
spike_types = [np.array(st) for st in net.cell_response.spike_types]
print(sorted(spike_times[0][spike_types[0] == 'prox1'])[:5])
print(sorted(spike_times[1][spike_types[1] == 'prox1'])[:5])
print('Model Cells Have Variable Times')
print(sorted(spike_times[0][spike_types[0] == 'L2_pyramidal'])[:5])
print(sorted(spike_times[1][spike_types[1] == 'L2_pyramidal'])[:5])
print('External Drives Seem Variable')
print(net.external_drives['prox1']['events'][0][:5])
print(net.external_drives['prox1']['events'][1][:5])
print('External Drives Match After Sorting')
print(sorted(net.external_drives['prox1']['events'][0])[:5])
print(sorted(net.external_drives['prox1']['events'][1])[:5])
Artifical Cell Spike Times Match
[20.616243397076424, 21.698725791281795, 22.07852744133209, 22.937801675688206, 22.98657972337079]
[20.616243397076424, 21.698725791281795, 22.07852744133209, 22.937801675688206, 22.98657972337079]
Model Cells Have Variable Times
[23.400000000099737, 24.000000000099703, 25.8000000000996, 27.20000000009952, 27.800000000099487]
[24.200000000099692, 24.40000000009968, 27.20000000009952, 27.6000000000995, 29.15000000009941]
External Drives Seem Variable
[[46.00405471280794], [52.94980360927816], [40.06469047595444], [22.937801675688206], [54.26991370416734]]
[[52.94980360927816], [40.06469047595444], [22.937801675688206], [54.26991370416734], [38.23979917262779]]
External Drives Match After Sorting
[[20.616243397076424], [21.698725791281795], [22.07852744133209], [22.937801675688206], [22.98657972337079]]
[[20.616243397076424], [21.698725791281795], [22.07852744133209], [22.937801675688206], [22.98657972337079]]
This is true for both backends, the sorting is necessary because the spike times may be appended differently depending on the backend.
Also to better explain, this persists when num_spikes = 10
. As in the same 10 spike times are assigned to different gids across trials.
Additionally, if you set cell_specific = False
and n_drive_cells=3
you should in theory be sampling 10 spikes for 3 different cells on each trial. However, only one set of spike times differs across trials, the other two are identical.
I'm assuming this is coming down to the random seed being gid based? As in when we run multiple trials, the random seed needs to be incremented by the total number of cells in the network to avoid identical spike times.
Do model cells have variable timing after sorting them as well? Could it be that the discrepancy between model and drive cell spike times is due to the fact that, as you pointed out, drive cell spike times get sorted?
Good question. No after sorting there is still variability in the models cells. Also there is no discrepancy between cell_response
and external_drives
like we had discussed being a possibility. This happens right when the drives are instantiated so it is definitely a seeding issue.
I think the culprit is here:
https://github.com/jonescompneurolab/hnn-core/blob/7c48e69292a801d20b8ae070e9376284866e1c7e/hnn_core/drives.py#L249
Could we pass n_trials
to _drive_cell_event_times
and down to _create_gauss
, _create _bursty_input
etc. Then use the size
arguments in numpy functions to get completely random uncorrelated values
I think a stopgap solution where we increment the seed by something other than trial_idx may be fine before we implement the "proper" solution
Probably something like you've proposed earlier? Have the increment itself be generated by an RNG
I was thinking seed = event_seed + trial_idx * n_cells
so you avoid another seed ... we have already too many
@ntolley is this still an issue? Move issue to 0.4 milestone if so?