def test_recording(): """ tests if the shape of recording is correct """ import numpy as np from rockpool import timeseries as ts from rockpool.layers import FFIAFNest # - Generic parameters weights = np.array([[-0.1, 0.02, 0.4], [0.2, -0.3, -0.15]]) bias = 0.01 tau_mem = [0.02, 0.05, 0.1] # - Layer generation fl0 = FFIAFNest( weights=weights, dt=0.0001, bias=bias, tau_mem=tau_mem, refractory=0.001, record=True, ) # - Input signal tsInCont = ts.TSContinuous(times=np.arange(15) * 0.01, samples=np.ones((15, 2))) # - Compare states before and after vStateBefore = np.copy(fl0.state) dFl0 = fl0.evolve(tsInCont, duration=0.1) assert np.shape(fl0.recorded_states.samples) == (1000, 3) fl0.terminate()
def test_FFNestLayer(): """ Test FFIAFNest""" from rockpool import timeseries as ts from rockpool.layers import FFIAFNest # - Generic parameters weights = np.array([[-0.1, 0.02, 0.4], [0.2, -0.3, -0.15]]) bias = 0.01 tau_mem = [0.02, 0.05, 0.1] # - Layer generation fl0 = FFIAFNest( weights=weights, dt=0.001, bias=bias, tau_mem=tau_mem, refractory=0.001, record=True, ) # - Input signal tsInCont = ts.TSContinuous(times=np.arange(15) * 0.01, samples=np.ones((15, 2))) # - Compare states before and after vStateBefore = np.copy(fl0.state) dFl0 = fl0.evolve(tsInCont, duration=0.1) dFl0 = fl0.evolve(tsInCont, duration=0.1) assert fl0.t == 0.2 assert (vStateBefore != fl0.state).any() fl0.reset_all() assert fl0.t == 0 assert (vStateBefore == fl0.state).all() fl0.terminate()
def test_chargeAndSpikeSingleNeuron(): """ single neuron test charge neuron exactly to threshold without crossing using the bias add small input to make it spike """ from rockpool import timeseries as ts from rockpool.layers import FFIAFNest weights = [[1.0]] bias = [0.375] tau_mem = [0.01] vReset = -0.07 vRest = -0.07 vTh = -0.055 fC = 0.25 dt = 0.001 refractory = 0.002 fl0 = FFIAFNest( weights=weights, dt=dt, bias=bias, tau_mem=tau_mem, v_reset=vReset, v_rest=vRest, v_thresh=vTh, capacity=fC, refractory=refractory, record=True, name="test", ) # - Input signal vTime = np.arange(0, 1, dt) vVal = np.zeros([len(vTime), 1]) vVal[500] = 0.001 tsInCont = ts.TSContinuous(vTime, vVal) dFl0 = fl0.evolve(tsInCont, duration=1.0) assert not dFl0.isempty() fl0.terminate()
def test_chargeSingleNeuron(): """ single neuron test charge neuron exactly to threshold without crossing using the bias """ from rockpool.layers import FFIAFNest weights = [[1.0]] epsilon = 1e-5 bias = [0.375 - epsilon] tau_mem = [0.01] vReset = -0.07 vRest = -0.07 vTh = -0.055 fC = 0.25 dt = 0.001 refractory = 0.002 fl0 = FFIAFNest( weights=weights, dt=dt, bias=bias, tau_mem=tau_mem, v_reset=vReset, v_rest=vRest, v_thresh=vTh, capacity=fC, refractory=refractory, record=True, name="test", ) dFl0 = fl0.evolve(duration=1.0) assert fl0.state[0] > vTh - 0.00001 assert fl0.state[0] <= vTh assert dFl0.isempty() fl0.terminate()
def test_setWeightsIn(): """ Test weight setting""" from rockpool.layers import FFIAFNest, RecIAFSpkInNest, RecAEIFSpkInNest from rockpool import TSEvent, TSContinuous import numpy as np # - Generic parameters weights_in = np.array([[-0.5, 0.02, 0.4], [0.2, -0.3, -0.15]]) weights_rec = np.random.rand(3, 3) * 0.01 bias = 0.01 tau_mem = [0.02, 0.05, 0.1] tau_syn_exc = [0.2, 0.01, 0.01] tau_syn_inh = tau_syn_exc # - Different input weights for initialization of fl1 weights_in1 = np.array([[-0.1, 0.02, 0.4], [0.2, -0.3, -0.15]]) # - Input time series tsInpCont = TSContinuous(np.arange(15) * 0.01, np.ones(15) * 0.1) tsInp = TSEvent([0.1], [0]) ## -- FFIAFNEst # - Layer generation fl0 = FFIAFNest( weights=weights_in, dt=0.001, bias=bias, tau_mem=tau_mem, refractory=0.001 ) fl1 = FFIAFNest( weights=weights_in1, dt=0.001, bias=bias, tau_mem=tau_mem, refractory=0.001 ) # - Set input weights to same as fl0 fl1.weights = weights_in assert (fl1.weights_ == weights_in).all() # - Compare states before and after fl0.evolve(tsInpCont, duration=0.12) fl1.evolve(tsInpCont, duration=0.12) assert (fl0.state == fl1.state).all() fl0.terminate() fl1.terminate() ## -- RecIAFSpkInNest # - Layer generation fl0 = RecIAFSpkInNest( weights_in=weights_in, weights_rec=weights_rec, dt=0.001, bias=bias, tau_mem=tau_mem, tau_syn_exc=tau_syn_exc, tau_syn_inh=tau_syn_inh, refractory=0.001, record=True, ) fl1 = RecIAFSpkInNest( weights_in=weights_in1, weights_rec=weights_rec, dt=0.001, bias=bias, tau_mem=tau_mem, tau_syn_exc=tau_syn_exc, tau_syn_inh=tau_syn_inh, refractory=0.001, record=True, ) # - Set input weights to same as fl0 fl1.weights_in = weights_in assert (fl1.weights_in_ == weights_in).all() # - Compare states before and after fl0.evolve(tsInp, duration=0.12) fl1.evolve(tsInp, duration=0.12) assert (fl0.state == fl1.state).all() fl0.terminate() fl1.terminate() ## -- RecAEIFSpkInNest # - Layer generation fl0 = RecAEIFSpkInNest( weights_in=weights_in, weights_rec=weights_rec, dt=0.001, bias=bias, tau_mem=tau_mem, tau_syn_exc=tau_syn_exc, tau_syn_inh=tau_syn_inh, refractory=0.001, record=True, ) fl1 = RecAEIFSpkInNest( weights_in=weights_in1, weights_rec=weights_rec, dt=0.001, bias=bias, tau_mem=tau_mem, tau_syn_exc=tau_syn_exc, tau_syn_inh=tau_syn_inh, refractory=0.001, record=True, ) # - Set input weights to same as fl0 fl1.weights_in[0, 0] = weights_in[0, 0] assert (fl1.weights_in_ == weights_in).all() # - Compare states before and after fl0.evolve(tsInp, duration=0.12) fl1.evolve(tsInp, duration=0.12) assert (fl0.state == fl1.state).all() fl0.terminate() fl1.terminate()