spaic.Neuron package

Submodules

spaic.Neuron.Decoders module

@author: Yuan Mengwen @contact: mwyuan94@gmail.com @project: PyCharm @filename: Decoders.py @time:2021/5/7 14:50 @description:

class spaic.Neuron.Decoders.Spike_Rate(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

numpy_coding(record, target, device)[source]
torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.Spike_Counts(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

numpy_coding(record, target, device)[source]
torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.Spike_Rates(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

numpy_coding(record, target, device)[source]
torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.Final_Step_Voltage(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

Get label that has the highest voltage.

torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.First_Spike(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.TimeSpike_Counts(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

numpy_coding(record, target, device)[source]
torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.NullDeocder(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.V_Trajectory(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.Time_Softmax(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

numpy_coding(record, target, device)[source]
torch_coding1(record: Tensor, target, device)[source]
torch_coding(record: Tensor, target, device)[source]
torch_coding3(record: Tensor, target, device)[source]
property loss
class spaic.Neuron.Decoders.Voltage_Sum(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

numpy_coding(record, target, device)[source]
torch_coding(record, target, device)[source]
class spaic.Neuron.Decoders.Complex_Count(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

torch_coding(record: Tensor, target, device)[source]
class spaic.Neuron.Decoders.Complex_Phase(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

torch_coding(record: Tensor, target, device)[source]
torch_coding2(record, target, device)[source]
class spaic.Neuron.Decoders.Complex_Latency(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

torch_coding(record: Tensor, target, device)[source]
class spaic.Neuron.Decoders.Complex_TimingDistance(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

build(backend)[source]
torch_coding(record: Tensor, target: Tensor, device: str)[source]
class spaic.Neuron.Decoders.Complex_Trajectory(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

build(backend)[source]
torch_coding(record: Tensor, target=None, device='cpu')[source]
class spaic.Neuron.Decoders.Complex_Spike_Conv(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

torch_coding(source, target, device='cpu')[source]
class spaic.Neuron.Decoders.Spike_Conv(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Decoder

torch_coding(source, target, device='cpu')[source]

spaic.Neuron.Encoders module

@author: Yuan Mengwen @contact: mwyuan94@gmail.com @project: PyCharm @filename: Encoders.py @time:2021/5/7 14:50 @description:

class spaic.Neuron.Encoders.NullEncoder(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

Pass the encoded data.

torch_coding(source, device)[source]
class spaic.Neuron.Encoders.FloatEncoding(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

torch_coding(source, device)[source]
class spaic.Neuron.Encoders.SigleSpikeToBinary(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

Transform the spike train (each neuron firing one spike) into a binary matrix The source is the encoded time value in the range of [0,time]. The shape of encoded source should be [batch_size, shape].

torch_coding(source, device)[source]
class spaic.Neuron.Encoders.MultipleSpikeToBinary(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

Transform the spike train (each neuron firing multiple spikes) into a binary matrix The source is the encoded time value in the range of [0,time]. The shape of encoded source should be [time_step, batch_size, neuron_shape].

torch_coding(source, device)[source]
class spaic.Neuron.Encoders.PoissonEncoding(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

泊松频率编码,发放脉冲的概率即为刺激强度,刺激强度需被归一化到[0, 1]。 Generate a poisson spike train. time: encoding window ms dt: time step

numpy_coding(source, device)[source]
torch_coding(source, device)[source]
next_stage()[source]
class spaic.Neuron.Encoders.bernoulli(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

伯努利分布。 Generate a bernoulli spike train. time: encoding window ms dt: time step

torch_coding(source, device)[source]
class spaic.Neuron.Encoders.Latency(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

延迟编码,刺激强度越大,脉冲发放越早。刺激强度被归一化到[0, 1]。 Generate a latency encoding spike train. time: encoding window ms dt: time step

torch_coding(source, device)[source]
class spaic.Neuron.Encoders.Relative_Latency(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

相对延迟编码,在一个样本中,其相对强度越大,放电越靠前

torch_coding(source, device)[source]
class spaic.Neuron.Encoders.Constant_Current(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

torch_coding(source, device)[source]
class spaic.Neuron.Encoders.UniformEncoding(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Encoder

torch_coding(source, device)[source]

spaic.Neuron.Generators module

@author: Yuan Mengwen @contact: mwyuan94@gmail.com @project: PyCharm @filename: Generators.py @time:2021/6/21 16:35 @description:

class spaic.Neuron.Generators.Poisson_Generator(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson_generator', 'cc_generator', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Generator

泊松生成器,根据输入脉冲速率生成。 Generate a poisson spike train according input rate. time: encoding window ms dt: time step HZ: cycles/s

torch_coding(source, device)[source]
next_stage()[source]
class spaic.Neuron.Generators.Poisson_Generator2(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson_generator', 'cc_generator', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Generator

泊松生成器,根据输入脉冲速率生成。 Generate a poisson spike train according input rate. time: encoding window ms dt: time step

torch_coding(source, device)[source]
class spaic.Neuron.Generators.CC_Generator(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson_generator', 'cc_generator', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Generator

恒定电流生成器。 Generate a constant current input. time: encoding window ms dt: time step

torch_coding(source, device)[source]
class spaic.Neuron.Generators.Sin_Generator(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson_generator', 'cc_generator', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Generator

Generate a sin current input. time: encoding window ms dt: time step

torch_coding(source, device)[source]
class spaic.Neuron.Generators.Ramp_Generator(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson_generator', 'cc_generator', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Generator

torch_coding(source, device)[source]

spaic.Neuron.Module module

Created on 2021/4/12 @project: SPAIC @filename: Module @author: Hong Chaofei @contact: hongchf@gmail.com

@description: wrap around deep learning module such as a cnn network lstm cell

class spaic.Neuron.Module.Module(module=None, name=None, input_targets=[], input_var_names=['O[updated]'], output_targets=None, output_var_names=['Isyn'], module_backend='pytorch')[source]

Bases: Assembly

standalone_run(*args)[source]
init_variable(var_names=None, var_shapes=None, var_value_dict=None)[source]
build(backend)[source]
property parameters
property state_dict
load_state_dict(state)[source]
train(mode=True)[source]

spaic.Neuron.Neuron module

Created on 2020/8/5 @project: SPAIC @filename: Neuron @author: Hong Chaofei @contact: hongchf@gmail.com

@description: 定义神经集群和神经元模型。 神经元集群保存神经元数目、神经元编号、类型、模型、模型参数、神经元位置等信息,参与网络构建

class spaic.Neuron.Neuron.NeuronGroup(num=None, model=None, shape=None, neuron_type=('excitatory', 'inhibitory', 'pyramidal', '...'), neuron_position='x, y, z', name=None, parameter_variables: list | None = None, varible_ranges: dict | None = None, prefer_device=None, **kwargs)[source]

Bases: Assembly

Class for a group of neurons.

set_num_shape(num, shape)[source]
set_parameter()[source]
get_model()[source]
add_neuron_label(key: str)[source]
add_variable_kwargs(key)[source]
build(backend)[source]
Parameters:

backend (Backend.Backend) –

static custom_model(input_vars, output_vars, new_vars_dict, equation_type=('iterative', 'euler_iterative', 'exp_euler_iterative', 'ode'), backend='torch', custom_function_name='custom', base_model=None, add_threshold=True)[source]

Examples

@NeuronGroup.custom_model(input_vars=[‘M’, ‘S’, ‘WgtSum’], output_vars=[‘V’, ‘M’, ‘S’], new_vars_dict={‘V’:0, ‘M’:0, ‘S’:0, ‘WgtSum’:0}, equation_type=’exp_euler_iterative’) def func(M, S, WgtSum):

M = (WgtSum-M)/tau S = (WgtSum-S)/tau V = M - S return V, M, S

NeuronGroup(…., model=func)

sequence_to_tensor(var)[source]
class spaic.Neuron.Neuron.NeuronModel(**kwargs)[source]

Bases: ABC

op -> (return_name, operation_name, input_name1, input_name2…)

neuron_models = {'aclif': <class 'spaic.Neuron.Neuron.AdaptiveCLIFModel'>, 'adex': <class 'spaic.Neuron.Neuron.aEIFModel'>, 'aeif': <class 'spaic.Neuron.Neuron.aEIFModel'>, 'alifstdp_ex': <class 'spaic.Neuron.Neuron.ALIFSTDPEXModel'>, 'cann_field': <class 'spaic.Neuron.Neuron.CANN_MeanFieldModel'>, 'clif': <class 'spaic.Neuron.Neuron.CLIFModel'>, 'clif2k': <class 'spaic.Neuron.Neuron.CLIF2kModel'>, 'constantcurrentlif': <class 'spaic.Neuron.Neuron.ConstantCurrentLIFModel'>, 'darwin_alif': <class 'spaic.Neuron.Neuron.Darwin_ALIF'>, 'darwin_clif': <class 'spaic.Neuron.Neuron.Darwin_CLIF'>, 'darwin_random': <class 'spaic.Neuron.Neuron.Darwin_Random'>, 'diehlandcook': <class 'spaic.Neuron.Neuron.DiehlAndCookModelInt'>, 'glif': <class 'spaic.Neuron.Neuron.GLIFModel'>, 'hh': <class 'spaic.Neuron.Neuron.HodgkinHuxleyModel'>, 'if': <class 'spaic.Neuron.Neuron.IFModel'>, 'ifb': <class 'spaic.Neuron.Neuron.IFBModel'>, 'ifsoftreset': <class 'spaic.Neuron.Neuron.IFSoftModel'>, 'izh': <class 'spaic.Neuron.Neuron.IZHModel'>, 'lif': <class 'spaic.Neuron.Neuron.LIFModel'>, 'lifint': <class 'spaic.Neuron.Neuron.LIFInt'>, 'lifm': <class 'spaic.Neuron.Neuron.LIFMModel'>, 'lifstdp_ex': <class 'spaic.Neuron.Neuron.LIFSTDPEXModel'>, 'lifstdp_ih': <class 'spaic.Neuron.Neuron.LIFSTDPIHModel'>, 'meanfield': <class 'spaic.Neuron.Neuron.MeanFieldModel'>, 'nonspikingifb': <class 'spaic.Neuron.Neuron.NonSpikingIFBModel'>, 'nonspikinglif': <class 'spaic.Neuron.Neuron.NonSpikingLIFModel'>, 'null': <class 'spaic.Neuron.Neuron.NullModel'>, 'pclif': <class 'spaic.Neuron.Neuron.PLIF2kModel'>, 'plif': <class 'spaic.Neuron.Neuron.PLIFModel'>, 'qlif': <class 'spaic.Neuron.Neuron.QLIFModel'>, 'selif': <class 'spaic.Neuron.Neuron.SELIFModel'>, 'slif': <class 'spaic.Neuron.Neuron.SLIFModel'>}

A dictionary mapping neuron model names to Model objects

static register(name, model)[source]

Register a neuron model. Registered neuron models can be referred to # via their name. :param name: A short name for the state updater (e.g. ‘lif’) :type name: str :param model: The neuron model object, e.g. an CLIFModel, ‘SLIFModel’. :type model: NeuronModel

static apply_model(model_name)[source]
Parameters:

model_name (str) –

class spaic.Neuron.Neuron.CLIFModel(**kwargs)[source]

Bases: NeuronModel

Current LIF 3-kernel model: V(t) = M(t) − S(t) − E(t) I^n[t] = V0 * Isyn^n[t-1] #sum(w * O^(n-1)[t]) M^n[t] = betaM * M^n[t-1] + I^n[t-1] S^n[t] = betaS * S^n[t-1] + I^n[t-1] E^n[t] = betaM * E^n[t-1] + Vth * O^n[t-1] O^n[t] = spike_func(V^n[t-1])

name = 'clif'
class spaic.Neuron.Neuron.CLIF2kModel(**kwargs)[source]

Bases: NeuronModel

Current LIF 2-kernel model: V(t) = M(t) − S(t) − E(t) I^n[t] = V0 * Isyn^n[t-1] #sum(w * O^(n-1)[t]) M^n[t] = betaM * M^n[t-1] + I^n[t-1] S^n[t] = betaS * S^n[t-1] + I^n[t-1] E^n[t] = betaM * E^n[t-1] + Vth * O^n[t-1] O^n[t] = spike_func(V^n[t-1])

name = 'clif2k'
class spaic.Neuron.Neuron.PLIF2kModel(**kwargs)[source]

Bases: NeuronModel

Current LIF 2-kernel model: V(t) = M(t) − S(t) − E(t) I^n[t] = V0 * Isyn^n[t-1] #sum(w * O^(n-1)[t]) M^n[t] = betaM * M^n[t-1] + I^n[t-1] S^n[t] = betaS * S^n[t-1] + I^n[t-1] E^n[t] = betaM * E^n[t-1] + Vth * O^n[t-1] O^n[t] = spike_func(V^n[t-1])

name = 'pclif'
class spaic.Neuron.Neuron.AdaptiveCLIFModel(**kwargs)[source]

Bases: NeuronModel

Current LIF 3-kernel model: V(t) = M(t) − S(t) − E(t) I^n[t] = V0 * Isyn^n[t-1] #sum(w * O^(n-1)[t]) M^n[t] = betaM * M^n[t-1] + I^n[t-1] S^n[t] = betaS * S^n[t-1] + I^n[t-1] E^n[t] = betaM * E^n[t-1] + Vth * O^n[t-1] O^n[t] = spike_func(V^n[t-1])

name = 'aclif'
class spaic.Neuron.Neuron.IFModel(**kwargs)[source]

Bases: NeuronModel

IF model: V(t) = V(t-1) * (1 - O(t-1)) + Isyn[t] - ConstantDecay

O^n[t] = spike_func(V^n[t-1])

name = 'if'
class spaic.Neuron.Neuron.IFSoftModel(**kwargs)[source]

Bases: NeuronModel

IF soft reset model: V(t) = V(t-1) * (1 - O(t-1)) + Isyn[t] - ConstantDecay O^n[t] = spike_func(V^n[t-1])

name = 'ifsoftreset'
class spaic.Neuron.Neuron.IFBModel(**kwargs)[source]

Bases: NeuronModel

IF model: V(t) = V(t-1) * (1 - O(t-1)) + Isyn[t] - ConstantDecay

O^n[t] = spike_func(V^n[t-1])

name = 'ifb'
class spaic.Neuron.Neuron.NonSpikingIFBModel(**kwargs)[source]

Bases: NeuronModel

IFB model: V(t) = V(t-1) * (1 - O(t-1)) + Isyn[t] - ConstantDecay

O^n[t] = spike_func(V^n[t-1])

name = 'nonspikingifb'
class spaic.Neuron.Neuron.NullModel(**kwargs)[source]

Bases: NeuronModel

return ‘O’

name = 'null'
class spaic.Neuron.Neuron.QLIFModel(**kwargs)[source]

Bases: NeuronModel

LIF neuron model for Q-Backprop learning

E[t] = beta_m*E[t-1] + Vth*O[t-1] V[t] = WgtSum(PSP[t]) - E[t] O[t] = spike_function(V[t])

# Q for non-spiking Mp[t] = beta_m*Mp[t-1] + WpSum[t] Sp[t] = beta_s*Sp[t-1] + WpSum[t] P[t] = Mp[t] - Sp[t]

# Q for spiking Mq[t] = beta_m*Mq[t-1] + WqSum[t] Sq[t] = beta_s*Sq[t-1] + WqSum[t] Q[t] = Mq[t] - Sq[t]

R[t] = ~O[t]*beta_s*R[t-1] + O[t] F[t] = 1 - R[t] QP[t] = Q[t] - P[t] BQ[t] = R[t]*Q[t] + F[t]*P[t]

TP[t] = R[t]*P[t] + F[t]*Reward - P[t-1] TQ[t] = F[t]*Q[t] + R[t]*Reward - Q[t-1]

name = 'qlif'
class spaic.Neuron.Neuron.SELIFModel(tau_m=12.0, tau_p=6.0, tau_q=2.0, tau_r=16.0, v_th=1.0, v_reset=2.0, outlayer=False, **kwargs)[source]

Bases: NeuronModel

SpikeProp LIF 3-kernel model:

V[t] = WgtSum[t-1] - E[t-1] I[t] = spike_func(V[t]) M[t] = betaM * M[t-1] + I[t] S[t] = betaS * S[t-1] + I[t] E[t] = betaM * E[t-1] + Vth * I[t] O[t] = M[t] − S[t]

initial_op_code

V(t) = M(t) − S(t) − E(t) I^n[t] = V0 * WgtSum^n[t-1] #sum(w * O^(n-1)[t]) M^n[t] = betaM * M^n[t-1] + I^n[t-1] S^n[t] = betaS * S^n[t-1] + I^n[t-1] E^n[t] = betaM * E^n[t-1] + Vth * O^n[t-1]

O^n[t] = spike_func(V^n[t-1])

attach_learner(learner)[source]
build(shape, backend)[source]
initial()[source]
norm_hook(grad)[source]
update(WgtSum)[source]
return_V()[source]
return_M()[source]
return_S()[source]
return_dV()[source]
property E_values
property E_grads
name = 'selif'
class spaic.Neuron.Neuron.SLIFModel(tau_m=20.0, tau_p=20.0, tau_q=8.0, v_th=1.0, v_reset=2.0, outlayer=False)[source]

Bases: NeuronModel

SpikeProp LIF 3-kernel model:

V[t] = WgtSum[t-1] - E[t-1] I[t] = spike_func(V[t]) M[t] = betaM * M[t-1] + I[t] S[t] = betaS * S[t-1] + I[t] E[t] = betaM * E[t-1] + Vth * I[t] O[t] = M[t] − S[t]

initial_op_code

V(t) = M(t) − S(t) − E(t) I^n[t] = V0 * WgtSum^n[t-1] #sum(w * O^(n-1)[t]) M^n[t] = betaM * M^n[t-1] + I^n[t-1] S^n[t] = betaS * S^n[t-1] + I^n[t-1] E^n[t] = betaM * E^n[t-1] + Vth * O^n[t-1]

O^n[t] = spike_func(V^n[t-1])

attach_learner(learner)[source]
build(shape, backend)[source]
initial()[source]
norm_hook(grad)[source]
update(WgtSum)[source]
return_V()[source]
return_M()[source]
return_S()[source]
return_dV()[source]
property E_values
property E_grads
name = 'slif'
class spaic.Neuron.Neuron.SELIFDebugModel(tau_m=20.0, tau_p=20.0, tau_q=8.0, v_th=1.0, outlayer=False)[source]

Bases: NeuronModel

attach_learner(learner)[source]
build(shape, backend)[source]
initial()[source]
update(WgtSum)[source]
return_V()[source]
class spaic.Neuron.Neuron.LIFModel(**kwargs)[source]

Bases: NeuronModel

LIF model: # V(t) = tuaM * V^n[t-1] + Isyn[t] # tauM: constant membrane time (tauM=RmCm) O^n[t] = spike_func(V^n[t-1])

name = 'lif'
class spaic.Neuron.Neuron.PLIFModel(**kwargs)[source]

Bases: NeuronModel

LIF model: # V(t) = tuaM * V^n[t-1] + Isyn[t] # tauM: constant membrane time (tauM=RmCm) O^n[t] = spike_func(V^n[t-1])

name = 'plif'
class spaic.Neuron.Neuron.ConstantCurrentLIFModel(**kwargs)[source]

Bases: NeuronModel

ConstantCurrentLIF model: V(t) = V^n[t-1] + (dt/taum) * (Ureset-V^n[t-1]+I) # tauM: constant membrane time (tauM=RmCm) Isyn = I*Weight O^n[t] = spike_func(V^n[t-1])

name = 'constantcurrentlif'
class spaic.Neuron.Neuron.NonSpikingLIFModel(**kwargs)[source]

Bases: NeuronModel

NonSpikingLIF model: # V(t) = -tuaM * V^n[t-1] + M^n[t] - S^n[t] # tauM: constant membrane time (tauM=RmCm) V(t) = V^n[t-1] + (dt/taum) * (PSP-V^n[t-1]) # tauM: constant membrane time (tauM=RmCm) I^n[t] = V0 * Isyn^n[t-1] # sum(w * O^(n-1)[t]) M^n[t] = tauP * M^n[t-1] + I^n[t-1] # tauP: decaying time constants of membrane integration S^n[t] = tauQ * S^n[t-1] + I^n[t-1] # tauQ: decaying time constants of synaptic currents PSP = M - S

name = 'nonspikinglif'
class spaic.Neuron.Neuron.LIFMModel(**kwargs)[source]

Bases: NeuronModel

LIF model: # I_che = tauP*I + Isyn^n[t-1] + b^n # sum(w * O^(n-1)[t]) # I = I_che + I_ele # F = tauM * exp(-O^n[t-1] / tauM) # V(t) = V^n[t-1] * F + I # O^(n)[t] = spike_func(V^n(t))

name = 'lifm'
class spaic.Neuron.Neuron.IZHModel(**kwargs)[source]

Bases: NeuronModel

IZH model:

\[ \begin{align}\begin{aligned}V = V + dt / tauM * (C1 * V * V + C2 * V + C3 - U + I) # tauM=1 此处加tauM是为了添加op时和LIF模型保存一致 \ V = V + dt / tauM * (V* (C1 * V + C2) + C3 - U + I) # 由上式拆分而来 \ U = U + a. * (b. * V - U) \\\O^n[t] = spike\_func(V^n[t-1])\\if V > Vth, \ then V = C, U = U + d\end{aligned}\end{align} \]

References

Izhikevich, E. M. (2003). Simple model of spiking neurons. IEEE Transactions on neural networks, 14(6), 1569-1572.

name = 'izh'
class spaic.Neuron.Neuron.aEIFModel(**kwargs)[source]

Bases: NeuronModel

aEIF model:

\[ \begin{align}\begin{aligned}V = V + dt / tauM * (EL - V + EXP - U + I^n[t]) \ U = U + dt / tauW * (a * (V - EL) - U) \ EXP = delta\_t * delta\_t2 * exp(dv\_th/delta\_t2) \ dv = V - EL \ dv\_th = V - Vth\\O^n[t] = spike\_func(V^n[t-1]) \\\If V > 20: \ then V = EL, U = U + b\end{aligned}\end{align} \]

References

Brette, R., & Gerstner, W. (2005). Adaptive exponential integrate-and-fire model as an effective description of neuronal activity. Journal of neurophysiology, 94(5), 3637-3642.

name = 'adex'
class spaic.Neuron.Neuron.GLIFModel(**kwargs)[source]

Bases: NeuronModel

Current GLIF5 model:

V = V + dt / C * (I + I1 + I2 - (V - E_L) / R) Theta_s = Theta_s - dt * b_s * Theta_s I_j = I_j - dt * k_j * I_j (j = 1,2) Theta_v = Theta_v + dt * (a_v * (V - E_L) - b_v * Theta_v)

v_th = Theta_v + Theta_s + Theta_inf O = spike_func(V)

Reset function:

V = E_L + f_v * (V - E_L) - delta_v Theta_s = Theta_s + delta_Theta_s I_j = f_j * I_j + delta_I_j (j = 1, 2) Theta_v = Theta_v

References

Teeter, C., Iyer, R., Menon, V., Gouwens, N., Feng, D., Berg, J., … & Mihalas, S. (2018). Generalized leaky integrate-and-fire models classify multiple neuron types. Nature communications, 9(1), 1-15.

name = 'glif'
class spaic.Neuron.Neuron.HodgkinHuxleyModel(**kwargs)[source]

Bases: NeuronModel

Hodgkin-Huxley model:

V = V + dt/tau_v * (I - Ik) Ik = NA + K + L NA = g_NA * m^3 * h * (V - V_NA) K = g_K * n^4 * (V - V_K) L = g_L * (V - V_L)

Na activation: m = m + dt/tau_m * (alpha_m * (1-m) - beta_m * m)

K activation: n = n + dt/tau_n * (alpha_n * (1-n) - beta_n * n)

Na inactivation: h = h + dt/tau_h * (alpha_h * (1-h) - beta_h * h)

original function1: alpha_m = 0.1 * (-V + 25) / (exp((-V+25)/10) - 1) beta_m = 4 * exp(-V/18) alpha_n = 0.01 * (-V + 10) / (exp((-V+10)/10) - 1) beta_n = 0.125 * exp(-V/80) alpha_h = 0.07 * exp(-V/20) beta_h = 1/(exp((-V+30)/10) + 1)

O^n[t] = spike_func(V^n[t-1])

name = 'hh'
class spaic.Neuron.Neuron.LIFSTDPEXModel(**kwargs)[source]

Bases: NeuronModel

LIF model: V(t) = decay_v * (v - v_rest) + v_rest + I^n[t] I^n[t] = V0 * Isyn^n[t] #V0 = 1 theta(t) = decay_th * theta[t-1] if v >= (vth + theta) then s_out = 1; else s_out = 0; Reset: V(t) = s_out * v_reset + (1 - s_out) * v; theta = theta + s_out * th_inc O^n[t] = spike_func(V^n[t-1])

name = 'lifstdp_ex'
class spaic.Neuron.Neuron.ALIFSTDPEXModel(**kwargs)[source]

Bases: NeuronModel

LIF model: V(t) = decay_v * (v - v_rest) + v_rest + I^n[t] I^n[t] = V0 * Isyn^n[t] #V0 = 1 theta(t) = decay_th * theta[t-1] if v >= (vth + theta) then s_out = 1; else s_out = 0; Reset: V(t) = s_out * v_reset + (1 - s_out) * v; theta = theta + s_out * th_inc

O^n[t] = spike_func(V^n[t-1])

name = 'alifstdp_ex'
class spaic.Neuron.Neuron.LIFSTDPIHModel(**kwargs)[source]

Bases: NeuronModel

LIF model: V(t) = decay_v * (v - v_rest) + v_rest + I^n[t] I^n[t] = V0 * Isyn^n[t] #V0 = 1

Reset: V(t) = s_out * v_reset + (1 - s_out) * v;

O^n[t] = spike_func(V^n[t-1])

name = 'lifstdp_ih'
class spaic.Neuron.Neuron.DiehlAndCookModelInt(**kwargs)[source]

Bases: NeuronModel

Layer of leaky integrate-and-fire (LIF) neurons with adaptive thresholds (modified for Diehl & Cook 2015 replication), based on integer arithmetic: if thresh > max_threshold: thresh = thresh/2 # Decay voltages. V(t) = ((self.decay * (v - self.rest)) >> shift_voltage) + self.rest # decay = 1013; v_rest = 0; shift_voltage = 10 # Integrate inputs. V(t) = V(t) + (self.refrac_count <= 0).int() * ((Isyn^n[t] * self.weight_sum_coef) >> self.shift_weight_sum_coef) refrac_count=0; weight_sum_coef = 154; shift_weight_sum_coef = 10 # Decrement refractory counters. self.refrac_count -= 1 # Check for spiking neurons. O^n[t] = spike_func(V^n[t-1]) # Refractoriness, voltage reset, and adaptive thresholds. self.refrac_count.masked_fill_(self.s, self.reset_refrac) self.reset_refrac = 5 self.v.masked_fill_(self.s, self.reset) self.thresh = self.thresh + self.thresh_plus * self.s.int().sum(0) # Voltage clipping to lower bound. if self.lbound is not None:

self.v.masked_fill_(self.v < self.lbound, self.lbound)

update(x, v, thresh, refrac_count, decay, rest, shift_voltage, max_threshold, weight_sum_coef, shift_weight_sum_coef, refrac, reset, thresh_plus, lbound, weight_sum_min, weight_sum_max)[source]
name = 'diehlandcook'
class spaic.Neuron.Neuron.LIFInt(**kwargs)[source]

Bases: NeuronModel

Layer of leaky integrate-and-fire (LIF) neurons based on integer arithmetic:

update(x, v, thresh, refrac_count, decay, rest, refrac, reset)[source]
name = 'lifint'
class spaic.Neuron.Neuron.CANN_MeanFieldModel(**kwargs)[source]

Bases: NeuronModel

Mean Field Model used in “Fung CC, Wong KY, Wu S. A moving bump in a continuous manifold: a comprehensive study of the tracking dynamics of continuous attractor neural networks. Neural Comput. 2010 Mar;22(3):752-92. doi: 10.1162/neco.2009.07-08-824. ” “Wu S, Wong KY, Fung CC, Mi Y, Zhang W. Continuous Attractor Neural Networks: Candidate of a Canonical Model for Neural Information Representation.F1000Res. 2016 Feb 10;5:F1000 Faculty Rev-156. doi: 10.12688/f1000research.7387.1. “

U = U + dt/tau * (Iext + rho*WgtSum - U) O = U^2/(1 + k*rho*sum(U^2)) (WgtSum = weight*O_pre)

name = 'cann_field'
class spaic.Neuron.Neuron.MeanFieldModel(**kwargs)[source]

Bases: NeuronModel

Mean Field Model of LIF neuron “

U = U + dt/tau * (rho*(Iext + Isyn) - U) O = relu(U) (WgtSum = weight*O_pre)

name = 'meanfield'
class spaic.Neuron.Neuron.SimpleRateModel(**kwargs)[source]

Bases: NeuronModel

Rate model “

U = U + dt/tau * (sigmoid(Iext + WgtSum) - U) (WgtSum = weight*O_pre)

class spaic.Neuron.Neuron.Darwin_CLIF(**kwargs)[source]

Bases: NeuronModel

I = I*P4 + Wgt_sum V = V*P0 + I + P1

update(V, I, Isyn, P0, P4, P1, Vth)[source]
quantize_16(x)[source]
name = 'darwin_clif'
class spaic.Neuron.Neuron.Darwin_ALIF(**kwargs)[source]

Bases: NeuronModel

Adaptive threshold LIF I = I*P4 + Wgt_sum V = V*P0 + I + P1 Vth = Vth*P2 + C1 if spike: Vth = Vth + C2

name = 'darwin_alif'
update(V, I, Isyn, P0, P4, P1, Vth, P2, C1, C2)[source]
quantize_16(x)[source]
class spaic.Neuron.Neuron.Darwin_Random(**kwargs)[source]

Bases: NeuronModel

name = 'darwin_random'
update(V, P0, bias, std, Vth)[source]

spaic.Neuron.Node module

Created on 2020/8/11 @project: SPAIC @filename: Node @author: Hong Chaofei @contact: hongchf@gmail.com

@description: 定义神经网络的输入输出接口

class spaic.Neuron.Node.Node(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Assembly

Base class for input encoder and output decoders.

init_state()[source]
property dt
property time_step
property time
get_var_names()[source]
static register(name, coding_class)[source]

Register a coding class. Registered encoding or decoding classes can be referred to # via their name. :param name: A short name for the state updater (e.g. ‘poisson’, ‘spike_counts’) :type name: str :param coding_class: The subclass of coding object, e.g. an ‘PoissonEncoding’, ‘Spike_Counts’.

torch_coding(source: Tensor, target: Tensor, device: str) Tensor[source]
Parameters:
  • source – It is input spike trains for encoding class and output spike trains for decoding class.

  • target – It is None for encodoing class and labels for decoding class.

  • device – CPU or CUDA, this parameter is taken from backend

Returns:

numpy_coding(source, target, device)[source]
tensorflow_coding(source, target, device)[source]
build(backend)[source]
class spaic.Neuron.Node.Encoder(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Node

Five encoding method are provided, as shown below (key: class): 1. ‘sstb’: SigleSpikeToBinary, 2. ‘mstb’: MultipleSpikeToBinary 3. ‘poisson’: PoissonEncoding 4. ‘latency’: Latency 5. ‘relative_latency’: Relative_Latency

static register(name, coding_class)[source]

Register a coding class. Registered encoding or decoding classes can be referred to # via their name. :param name: A short name for the state updater (e.g. ‘poisson’, ‘spike_counts’) :type name: str :param coding_class: The subclass of coding object, e.g. an ‘PoissonEncoding’, ‘Spike_Counts’.

init_state()[source]
get_input()[source]
next_stage()[source]
reset()[source]
build(backend)[source]
class spaic.Neuron.Node.Decoder(num=None, dec_target=None, dt=None, coding_method='spike_counts', coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Node

Five decoding method are provided, as shown below (key: class): 1. ‘spike_counts’: Spike_Counts 2. ‘first_spike’: First_Spike 3. ‘time_spike_counts’: TimeSpike_Counts 4. ‘time_softmax’: Time_Softmax 5. ‘final_step_voltage’: Final_Step_Voltage

static register(name, coding_class)[source]

Register a coding class. Registered encoding or decoding classes can be referred to # via their name. :param name: A short name for the state updater (e.g. ‘poisson’, ‘spike_counts’) :type name: str :param coding_class: The subclass of coding object, e.g. an ‘PoissonEncoding’, ‘Spike_Counts’.

init_state()[source]
get_output(output)[source]
reset()[source]
build(backend)[source]
class spaic.Neuron.Node.Reward(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Node

Three reward method are provided, as shown below (key: class): 1. ‘global_reward’, Global_Reward 2. ‘xor_reward’: XOR_Reward 3. ‘da_reward’: DA_Reward 4. ‘environment_reward’: Environment_Reward

static register(name, coding_class)[source]

Register a Reward class. Registered reward classes can be referred to # via their name. :param name: A short name for the state updater (e.g. ‘step_reward’) :type name: str :param coding_class: The subclass of coding object, e.g. an ‘Step_Reward’.

init_state()[source]
get_reward(output=array([], dtype=float64))[source]
build(backend)[source]
class spaic.Neuron.Node.Generator(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson_generator', 'cc_generator', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Node

Two generator method are provided, as shown below (key: class): 1. ‘poisson_generator’: Poisson_Generator, 2. ‘cosine_generator’: Cosine_Generator

static register(name, coding_class)[source]

Register a coding class. Registered encoding or decoding classes can be referred to # via their name. :param name: A short name for the state updater (e.g. ‘poisson’, ‘spike_counts’) :type name: str :param coding_class: The subclass of coding object, e.g. an ‘PoissonEncoding’, ‘Spike_Counts’.

init_state()[source]
torch_coding(source, device)[source]
Parameters:
  • () (device) – It is input spike trains for encoding class and output spike trains for decoding class.

  • () – CPU or CUDA, this parameter is taken from backend

Returns:

get_input()[source]
next_stage()[source]
build(backend)[source]
class spaic.Neuron.Node.Action(shape=None, num=None, dec_target=None, dt=None, coding_method=('poisson', 'spike_counts', '...'), coding_var_name='O', node_type=('excitatory', 'inhibitory', 'pyramidal', '...'), **kwargs)[source]

Bases: Node

Six action method are provided, as shown below (key: class): 1. ‘pop_rate_action’: PopulationRate_Action 2. ‘softmax_action’: Softmax_Action 3. ‘highest_spikes_action’: Highest_Spikes_Action 4. ‘highest_voltage_action’, Highest_Voltage_Action 5. ‘first_spike_action’: First_Spike_Action 6. ‘random_action’: Random_Action

static register(name, coding_class)[source]

Register an action class. Registered action classes can be referred to # via their name. :param name: A short name for the state updater (e.g. ‘pop_rate_action’) :type name: str :param coding_class: The subclass of coding object, e.g. an ‘PopulationRate_Action’.

init_state()[source]
get_action(output)[source]
build(backend)[source]

Module contents

Created on 2020/8/11 @project: SPAIC @author: Hong Chaofei @contact: hongchf@gmail.com

@description: