bindsnet.encoding package

Submodules

bindsnet.encoding.encoders module

class bindsnet.encoding.encoders.BernoulliEncoder(time: int, dt: float = 1.0, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable BernoulliEncoder which encodes as defined in bindsnet.encoding.bernoulli

Parameters:
  • time – Length of Bernoulli spike train per input variable.
  • dt – Simulation time step.

Keyword arguments:

Parameters:max_prob (float) – Maximum probability of spike per time step.
class bindsnet.encoding.encoders.Encoder(*args, **kwargs)[source]

Bases: object

Base class for spike encodings transforms.

Calls self.enc from the subclass and passes whatever arguments were provided. self.enc must be callable with torch.Tensor, *args, **kwargs

class bindsnet.encoding.encoders.NullEncoder[source]

Bases: bindsnet.encoding.encoders.Encoder

Pass through of the datum that was input.

Note

This is not a real spike encoder. Be careful with the usage of this class.

class bindsnet.encoding.encoders.PoissonEncoder(time: int, dt: float = 1.0, approx: bool = False, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable PoissonEncoder which encodes as defined in ``bindsnet.encoding.poisson`

Parameters:
  • time – Length of Poisson spike train per input variable.
  • dt – Simulation time step.
  • approx – Bool: use alternate faster, less accurate computation.
class bindsnet.encoding.encoders.RankOrderEncoder(time: int, dt: float = 1.0, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable RankOrderEncoder which encodes as defined in bindsnet.encoding.rank_order

Parameters:
  • time – Length of RankOrder spike train per input variable.
  • dt – Simulation time step.
class bindsnet.encoding.encoders.RepeatEncoder(time: int, dt: float = 1.0, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable RepeatEncoder which encodes as defined in bindsnet.encoding.repeat

Parameters:
  • time – Length of repeat spike train per input variable.
  • dt – Simulation time step.
class bindsnet.encoding.encoders.SingleEncoder(time: int, dt: float = 1.0, sparsity: float = 0.5, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable SingleEncoder which encodes as defined in bindsnet.encoding.single

Parameters:
  • time – Length of single spike train per input variable.
  • dt – Simulation time step.
  • sparsity – Sparsity of the input representation. 0 for no spikes and 1 for all spikes.

bindsnet.encoding.encodings module

bindsnet.encoding.encodings.bernoulli(datum: torch.Tensor, time: Optional[int] = None, dt: float = 1.0, device='cpu', **kwargs) → torch.Tensor[source]

Generates Bernoulli-distributed spike trains based on input intensity. Inputs must be non-negative. Spikes correspond to successful Bernoulli trials, with success probability equal to (normalized in [0, 1]) input value.

Parameters:
  • datum – Tensor of shape [n_1, ..., n_k].
  • time – Length of Bernoulli spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensor of shape [time, n_1, ..., n_k] of Bernoulli-distributed spikes.

Keyword arguments:

Parameters:max_prob (float) – Maximum probability of spike per Bernoulli trial.
bindsnet.encoding.encodings.poisson(datum: torch.Tensor, time: int, dt: float = 1.0, device='cpu', approx=False, **kwargs) → torch.Tensor[source]

Generates Poisson-distributed spike trains based on input intensity. Inputs must be non-negative, and give the firing rate in Hz. Inter-spike intervals (ISIs) for non-negative data incremented by one to avoid zero intervals while maintaining ISI distributions.

Parameters:
  • datum – Tensor of shape [n_1, ..., n_k].
  • time – Length of Poisson spike train per input variable.
  • dt – Simulation time step.
  • device – target destination of poisson spikes.
  • approx – Bool: use alternate faster, less accurate computation.
Returns:

Tensor of shape [time, n_1, ..., n_k] of Poisson-distributed spikes.

bindsnet.encoding.encodings.rank_order(datum: torch.Tensor, time: int, dt: float = 1.0, **kwargs) → torch.Tensor[source]

Encodes data via a rank order coding-like representation. One spike per neuron, temporally ordered by decreasing intensity. Inputs must be non-negative.

Parameters:
  • datum – Tensor of shape [n_samples, n_1, ..., n_k].
  • time – Length of rank order-encoded spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensor of shape [time, n_1, ..., n_k] of rank order-encoded spikes.

bindsnet.encoding.encodings.repeat(datum: torch.Tensor, time: int, dt: float = 1.0, **kwargs) → torch.Tensor[source]
Parameters:
  • datum – Repeats a tensor along a new dimension in the 0th position for int(time / dt) timesteps.
  • time – Tensor of shape [n_1, ..., n_k].
  • dt – Simulation time step.
Returns:

Tensor of shape [time, n_1, ..., n_k] of repeated data along the 0-th dimension.

bindsnet.encoding.encodings.single(datum: torch.Tensor, time: int, dt: float = 1.0, sparsity: float = 0.5, device='cpu', **kwargs) → torch.Tensor[source]

Generates timing based single-spike encoding. Spike occurs earlier if the intensity of the input feature is higher. Features whose value is lower than the threshold remain silent.

Parameters:
  • datum – Tensor of shape [n_1, ..., n_k].
  • time – Length of the input and output.
  • dt – Simulation time step.
  • sparsity – Sparsity of the input representation. 0 for no spikes and 1 for all spikes.
Returns:

Tensor of shape [time, n_1, ..., n_k].

bindsnet.encoding.loaders module

bindsnet.encoding.loaders.bernoulli_loader(data: Union[torch.Tensor, Iterable[torch.Tensor]], time: Optional[int] = None, dt: float = 1.0, **kwargs) → Iterator[torch.Tensor][source]

Lazily invokes bindsnet.encoding.bernoulli to iteratively encode a sequence of data.

Parameters:
  • data – Tensor of shape [n_samples, n_1, ..., n_k].
  • time – Length of Bernoulli spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensors of shape [time, n_1, ..., n_k] of Bernoulli-distributed spikes.

Keyword arguments:

Parameters:max_prob (float) – Maximum probability of spike per Bernoulli trial.
bindsnet.encoding.loaders.poisson_loader(data: Union[torch.Tensor, Iterable[torch.Tensor]], time: int, dt: float = 1.0, **kwargs) → Iterator[torch.Tensor][source]

Lazily invokes bindsnet.encoding.poisson to iteratively encode a sequence of data.

Parameters:
  • data – Tensor of shape [n_samples, n_1, ..., n_k].
  • time – Length of Poisson spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensors of shape [time, n_1, ..., n_k] of Poisson-distributed spikes.

bindsnet.encoding.loaders.rank_order_loader(data: Union[torch.Tensor, Iterable[torch.Tensor]], time: int, dt: float = 1.0, **kwargs) → Iterator[torch.Tensor][source]

Lazily invokes bindsnet.encoding.rank_order to iteratively encode a sequence of data.

Parameters:
  • data – Tensor of shape [n_samples, n_1, ..., n_k].
  • time – Length of rank order-encoded spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensors of shape [time, n_1, ..., n_k] of rank order-encoded spikes.

Module contents

bindsnet.encoding.single(datum: torch.Tensor, time: int, dt: float = 1.0, sparsity: float = 0.5, device='cpu', **kwargs) → torch.Tensor[source]

Generates timing based single-spike encoding. Spike occurs earlier if the intensity of the input feature is higher. Features whose value is lower than the threshold remain silent.

Parameters:
  • datum – Tensor of shape [n_1, ..., n_k].
  • time – Length of the input and output.
  • dt – Simulation time step.
  • sparsity – Sparsity of the input representation. 0 for no spikes and 1 for all spikes.
Returns:

Tensor of shape [time, n_1, ..., n_k].

bindsnet.encoding.repeat(datum: torch.Tensor, time: int, dt: float = 1.0, **kwargs) → torch.Tensor[source]
Parameters:
  • datum – Repeats a tensor along a new dimension in the 0th position for int(time / dt) timesteps.
  • time – Tensor of shape [n_1, ..., n_k].
  • dt – Simulation time step.
Returns:

Tensor of shape [time, n_1, ..., n_k] of repeated data along the 0-th dimension.

bindsnet.encoding.bernoulli(datum: torch.Tensor, time: Optional[int] = None, dt: float = 1.0, device='cpu', **kwargs) → torch.Tensor[source]

Generates Bernoulli-distributed spike trains based on input intensity. Inputs must be non-negative. Spikes correspond to successful Bernoulli trials, with success probability equal to (normalized in [0, 1]) input value.

Parameters:
  • datum – Tensor of shape [n_1, ..., n_k].
  • time – Length of Bernoulli spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensor of shape [time, n_1, ..., n_k] of Bernoulli-distributed spikes.

Keyword arguments:

Parameters:max_prob (float) – Maximum probability of spike per Bernoulli trial.
bindsnet.encoding.poisson(datum: torch.Tensor, time: int, dt: float = 1.0, device='cpu', approx=False, **kwargs) → torch.Tensor[source]

Generates Poisson-distributed spike trains based on input intensity. Inputs must be non-negative, and give the firing rate in Hz. Inter-spike intervals (ISIs) for non-negative data incremented by one to avoid zero intervals while maintaining ISI distributions.

Parameters:
  • datum – Tensor of shape [n_1, ..., n_k].
  • time – Length of Poisson spike train per input variable.
  • dt – Simulation time step.
  • device – target destination of poisson spikes.
  • approx – Bool: use alternate faster, less accurate computation.
Returns:

Tensor of shape [time, n_1, ..., n_k] of Poisson-distributed spikes.

bindsnet.encoding.rank_order(datum: torch.Tensor, time: int, dt: float = 1.0, **kwargs) → torch.Tensor[source]

Encodes data via a rank order coding-like representation. One spike per neuron, temporally ordered by decreasing intensity. Inputs must be non-negative.

Parameters:
  • datum – Tensor of shape [n_samples, n_1, ..., n_k].
  • time – Length of rank order-encoded spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensor of shape [time, n_1, ..., n_k] of rank order-encoded spikes.

bindsnet.encoding.bernoulli_loader(data: Union[torch.Tensor, Iterable[torch.Tensor]], time: Optional[int] = None, dt: float = 1.0, **kwargs) → Iterator[torch.Tensor][source]

Lazily invokes bindsnet.encoding.bernoulli to iteratively encode a sequence of data.

Parameters:
  • data – Tensor of shape [n_samples, n_1, ..., n_k].
  • time – Length of Bernoulli spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensors of shape [time, n_1, ..., n_k] of Bernoulli-distributed spikes.

Keyword arguments:

Parameters:max_prob (float) – Maximum probability of spike per Bernoulli trial.
bindsnet.encoding.poisson_loader(data: Union[torch.Tensor, Iterable[torch.Tensor]], time: int, dt: float = 1.0, **kwargs) → Iterator[torch.Tensor][source]

Lazily invokes bindsnet.encoding.poisson to iteratively encode a sequence of data.

Parameters:
  • data – Tensor of shape [n_samples, n_1, ..., n_k].
  • time – Length of Poisson spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensors of shape [time, n_1, ..., n_k] of Poisson-distributed spikes.

bindsnet.encoding.rank_order_loader(data: Union[torch.Tensor, Iterable[torch.Tensor]], time: int, dt: float = 1.0, **kwargs) → Iterator[torch.Tensor][source]

Lazily invokes bindsnet.encoding.rank_order to iteratively encode a sequence of data.

Parameters:
  • data – Tensor of shape [n_samples, n_1, ..., n_k].
  • time – Length of rank order-encoded spike train per input variable.
  • dt – Simulation time step.
Returns:

Tensors of shape [time, n_1, ..., n_k] of rank order-encoded spikes.

class bindsnet.encoding.Encoder(*args, **kwargs)[source]

Bases: object

Base class for spike encodings transforms.

Calls self.enc from the subclass and passes whatever arguments were provided. self.enc must be callable with torch.Tensor, *args, **kwargs

class bindsnet.encoding.NullEncoder[source]

Bases: bindsnet.encoding.encoders.Encoder

Pass through of the datum that was input.

Note

This is not a real spike encoder. Be careful with the usage of this class.

class bindsnet.encoding.SingleEncoder(time: int, dt: float = 1.0, sparsity: float = 0.5, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable SingleEncoder which encodes as defined in bindsnet.encoding.single

Parameters:
  • time – Length of single spike train per input variable.
  • dt – Simulation time step.
  • sparsity – Sparsity of the input representation. 0 for no spikes and 1 for all spikes.
class bindsnet.encoding.RepeatEncoder(time: int, dt: float = 1.0, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable RepeatEncoder which encodes as defined in bindsnet.encoding.repeat

Parameters:
  • time – Length of repeat spike train per input variable.
  • dt – Simulation time step.
class bindsnet.encoding.BernoulliEncoder(time: int, dt: float = 1.0, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable BernoulliEncoder which encodes as defined in bindsnet.encoding.bernoulli

Parameters:
  • time – Length of Bernoulli spike train per input variable.
  • dt – Simulation time step.

Keyword arguments:

Parameters:max_prob (float) – Maximum probability of spike per time step.
class bindsnet.encoding.PoissonEncoder(time: int, dt: float = 1.0, approx: bool = False, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable PoissonEncoder which encodes as defined in ``bindsnet.encoding.poisson`

Parameters:
  • time – Length of Poisson spike train per input variable.
  • dt – Simulation time step.
  • approx – Bool: use alternate faster, less accurate computation.
class bindsnet.encoding.RankOrderEncoder(time: int, dt: float = 1.0, **kwargs)[source]

Bases: bindsnet.encoding.encoders.Encoder

Creates a callable RankOrderEncoder which encodes as defined in bindsnet.encoding.rank_order

Parameters:
  • time – Length of RankOrder spike train per input variable.
  • dt – Simulation time step.