How to save the threshold (adaptive) of a neuron group and load it later

I define a neuron group with adaptive threshold and need to save the threshold after the training. Could you instruct on how to save those thresholds into a file and load it later when testing?

Here are some more details:

    self.eqs_neuron = '''
        dv/dt = (ge*(Ee-v) + gi*(Ei-v)+ El - v)/tau_m : volt (unless refractory)
        dvt/dt = (v_thres-vt)/tau_adpt : volt 
        dge/dt = -ge/tau_ge : 1 (unless refractory)
        dgi/dt = -gi/tau_gi : 1 (unless refractory)
        delta_vt: volt (constant)
        v_rest: volt (constant)
        v_thres: volt (constant)
        v_reset: volt (constant)
        refrac_time: second (constant)
        label : integer 
        is_correct : boolean
        correct_label : integer (shared)
        x: 1
        y: 1
        tau_m: second (constant)
        Ee: volt (constant)
        Ei: volt (constant)
        El: volt (constant)
 neurons = NeuronGroup(n, self.eqs_neuron, threshold='v>vt',  reset=self.reset, refractory='refrac_time')
 neurons.vt = self.v_thres 

I need to save the “vt” and load it later.


Hi. I’m not 100% sure which value you want to save. The last value of vt after the simulation? You can get that by accessing neurons.vt[:] after the simulation, or with neurons.vt_[:] to get the value as a numpy array without any unit information. You can then store it on disk with any standard Python/numpy method, e.g. by pickling it or using Likewise, you can then load it and assign at the start of another simulation.

1 Like