spikingjelly.timing_based package#

Encoding#

class spikingjelly.timing_based.encoding.GaussianTuning(n, m, x_min, x_max)[源代码]#

基类:object

API Language - 中文 | English


  • 中文

使用高斯感受野将连续值编码为脉冲时间。每个输入维度由 m 个神经元 编码,公开属性 musigma2 分别保存感受野中心和方差。

参数:
  • n (int) -- 输入特征维度数量

  • m (int) -- 每个特征使用的神经元数量,必须大于 2

  • x_min (Tensor) -- 各输入特征的最小值,形状为 [n]

  • x_max (Tensor) -- 各输入特征的最大值,形状为 [n]

抛出:

ValueError -- nm 非法、输入范围形状不匹配,或任一 x_min 不小于对应的 x_max


  • English

Encode continuous values as spike times with Gaussian receptive fields. Each input dimension uses m neurons. Public attributes mu and sigma2 contain the receptive-field centers and variances.

参数:
  • n (int) -- Number of input feature dimensions

  • m (int) -- Number of neurons per feature; must be greater than 2

  • x_min (Tensor) -- Per-feature minimum values with shape [n]

  • x_max (Tensor) -- Per-feature maximum values with shape [n]

抛出:

ValueError -- If n or m is invalid, the range tensors have incompatible shapes, or any minimum is not smaller than its maximum

encode(x, max_spike_time=50)[源代码]#

API Language - 中文 | English


  • 中文

参数:
  • x (Tensor) -- 输入张量,形状为 [batch_size, n, samples_count]

  • max_spike_time (int) -- 非负编码时间窗长度;达到该值的神经元以 -1 表示不发放。 当其为 0 时,所有神经元均不发放

返回:

形状为 [batch_size, n, samples_count, m] 的脉冲时间

返回类型:

Tensor

抛出:

  • English

参数:
  • x (Tensor) -- Input tensor with shape [batch_size, n, samples_count]

  • max_spike_time (int) -- Non-negative encoding-window length; neurons reaching it are marked inactive with -1. When it is 0, all neurons are inactive

返回:

Spike times with shape [batch_size, n, samples_count, m]

返回类型:

Tensor

抛出:
  • AssertionError -- If the input is not three-dimensional or its feature dimension differs from n

  • ValueError -- If max_spike_time is negative

Neuron#

class spikingjelly.timing_based.neuron.Tempotron(in_features, out_features, T, tau=15.0, tau_s=3.75, v_threshold=1.0)[源代码]#

基类:Module

API Language - 中文 | English


  • 中文

实现 Tempotron 脉冲时序分类神经元。输入中的每个值表示对应输入神经元 的脉冲时刻,负值表示未发放。

参数:
  • in_features (int) -- 输入神经元数量

  • out_features (int) -- 输出神经元数量

  • T (int) -- 仿真时间窗口

  • tau (float) -- 膜电位时间常数

  • tau_s (float) -- 突触电流时间常数

  • v_threshold (float) -- 发放阈值

抛出:

ValueError -- 数量、时间常数或阈值非正,或两个时间常数相等


  • English

Implement a Tempotron neuron for spike-timing classification. Each input value is the spike time of one input neuron; a negative value means that neuron did not spike.

参数:
  • in_features (int) -- Number of input neurons

  • out_features (int) -- Number of output neurons

  • T (int) -- Simulation time window

  • tau (float) -- Membrane-potential time constant

  • tau_s (float) -- Synaptic-current time constant

  • v_threshold (float) -- Firing threshold

抛出:

ValueError -- If a size, time constant, or threshold is not positive, or if the two time constants are equal

mse_loss(v_max, label)[源代码]#

API Language - 中文 | English


  • 中文

参数:
  • v_max (Tensor) -- 各输出神经元在时间窗口内的最大电压,形状为 [batch_size, out_features]

  • label (Tensor) -- 分类标签,形状为 [batch_size]

返回:

仅计算错误发放神经元的均方误差

返回类型:

Tensor


  • English

参数:
  • v_max (Tensor) -- Maximum voltage of each output neuron with shape [batch_size, out_features]

  • label (Tensor) -- Class labels with shape [batch_size]

返回:

Mean squared error over incorrectly firing neurons

返回类型:

Tensor

forward(in_spikes, ret_type)[源代码]#

API Language - 中文 | English


  • 中文

参数:
  • in_spikes (Tensor) -- 输入脉冲时刻,形状为 [batch_size, in_features]

  • ret_type (str) -- "v""v_max""spikes"

返回:

完整电压轨迹、最大电压或输出脉冲时刻

返回类型:

Tensor

抛出:

ValueError -- ret_type 不受支持


  • English

参数:
  • in_spikes (Tensor) -- Input spike times with shape [batch_size, in_features]

  • ret_type (str) -- "v", "v_max", or "spikes"

返回:

Full voltage trace, maximum voltage, or output spike times

返回类型:

Tensor

抛出:

ValueError -- If ret_type is unsupported

Examples#