model

How to use model

class dynapsetorch.model.ADM(N: int, threshold_up: float, threshold_down: float, refractory: int, activation_fn: ~torch.autograd.function.Function = <built-in method apply of FunctionMeta object>)[source]

Bases: Module

Adaptive Delta Modulation (ADM) module Converts an analog signal into UP and DOWN spikes using the Adaptive Delta Modulation scheme.

forward(input_signal)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

reconstruct(spikes, initial_value=0)[source]

Reconstruct an analog signal based on the UP and DOWN spikes produced by the ADM module. Everytime the algorithm receives an UP/DOWN spike, the reconstructed signal is increment/decrement by the UP/DOWN threshold amount.

class dynapsetorch.model.AdexLIF(n_in: int, n_out: int, tau_soma: float = 5.0, tau_ampa: float = 20.0, tau_gaba_b: float = 5.0, tau_ahp: float = 2.0, dt: float = 0.001, activation_fn: ~torch.autograd.function.Function = <built-in method apply of FunctionMeta object>)[source]

Bases: Module

class AdexLIFState(Isoma_mem, Iampa, Igaba_b, Isoma_ahp, refractory)

Bases: tuple

Iampa

Alias for field number 1

Igaba_b

Alias for field number 2

Isoma_ahp

Alias for field number 3

Isoma_mem

Alias for field number 0

refractory

Alias for field number 4

forward(input_ampa, input_gaba_b)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class dynapsetorch.model.AdexLIFfull(num_neurons: int = 1, input_per_synapse: ~typing.Sequence[int] = [1, 1, 1, 1], activation_fn: ~torch.autograd.function.Function = <built-in method apply of FunctionMeta object>)[source]

Bases: Module

class AdexLIFState(Isoma_mem, Isoma_ahp, refractory, Inmda, Iampa, Igaba_a, Igaba_b)

Bases: tuple

Iampa

Alias for field number 4

Igaba_a

Alias for field number 5

Igaba_b

Alias for field number 6

Inmda

Alias for field number 3

Isoma_ahp

Alias for field number 1

Isoma_mem

Alias for field number 0

refractory

Alias for field number 2

forward(input_nmda=None, input_ampa=None, input_gaba_a=None, input_gaba_b=None)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class dynapsetorch.model.LIF(n_in: int, n_out: int, thr: float = 1.0, tau: float = 20.0, tau_I: float = 10.0, dt: float = 1.0, activation_fn: ~torch.autograd.function.Function = <built-in method apply of FunctionMeta object>)[source]

Bases: Module

class LIFState(V, I, S)

Bases: tuple

I

Alias for field number 1

S

Alias for field number 2

V

Alias for field number 0

forward(input)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class dynapsetorch.model.Rate(dt=1.0)[source]

Bases: Module

forward(rate)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class dynapsetorch.model.Round(inplace=False)[source]

Bases: InplaceFunction

static backward(ctx, grad_output)[source]

Defines a formula for differentiating the operation with backward mode automatic differentiation (alias to the vjp function).

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by as many outputs as the forward() returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs to forward(). Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.

The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E.g., backward() will have ctx.needs_input_grad[0] = True if the first input to forward() needs gradient computated w.r.t. the output.

static forward(ctx, input)[source]

Performs the operation.

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

The context can be used to store arbitrary data that can be then retrieved during the backward pass. Tensors should not be stored directly on ctx (though this is not currently enforced for backward compatibility). Instead, tensors should be saved either with ctx.save_for_backward() if they are intended to be used in backward (equivalently, vjp) or ctx.save_for_forward() if they are intended to be used for in jvp.