norse.torch.functional.adjoint.lif_adjoint module

class norse.torch.functional.adjoint.lif_adjoint.LIFAdjointFunction(*args, **kwargs)[source]

Bases: torch.autograd.function.Function

static backward(ctx, doutput, lambda_v, lambda_i)[source]

Defines a formula for differentiating the operation.

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_tensor, z, v, i, input_weights, recurrent_weights, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[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.

Return type

Tuple[Tensor, Tensor, Tensor]

class norse.torch.functional.adjoint.lif_adjoint.LIFFeedForwardAdjointFunction(*args, **kwargs)[source]

Bases: torch.autograd.function.Function

static backward(ctx, doutput, lambda_v, lambda_i)[source]

Defines a formula for differentiating the operation.

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, v, i, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[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.

Return type

Tuple[Tensor, Tensor, Tensor]

class norse.torch.functional.adjoint.lif_adjoint.LIFFeedForwardSparseAdjointFunction(*args, **kwargs)[source]

Bases: torch.autograd.function.Function

static backward(ctx, doutput, lambda_v, lambda_i)[source]

Defines a formula for differentiating the operation.

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, v, i, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[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.

Return type

Tuple[Tensor, Tensor, Tensor]

class norse.torch.functional.adjoint.lif_adjoint.LIFSparseAdjointFunction(*args, **kwargs)[source]

Bases: torch.autograd.function.Function

static backward(ctx, doutput, lambda_v, lambda_i)[source]

Defines a formula for differentiating the operation.

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, z, v, i, input_weights, recurrent_weights, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[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.

Return type

Tuple[Tensor, Tensor, Tensor]

norse.torch.functional.adjoint.lif_adjoint.lif_adjoint_step(input, s, input_weights, recurrent_weights, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Implementes a single euler forward and adjoint backward step of a leaky integrate and fire neuron with current based exponential synapses.

Parameters
  • input (torch.Tensor) – input spikes from other cells

  • s (LIFState) – state of the lif neurons

  • input_weights (torch.Tensor) – synaptic weights for input spikes

  • recurrent_weights (torch.Tensor) – recurrent weights for recurrent spikes

  • p (LIFParameters) – parameters of the lif neurons

  • dt (float) – time step of integration

Return type

Tuple[Tensor, LIFState]

norse.torch.functional.adjoint.lif_adjoint.lif_adjoint_step_sparse(input, s, input_weights, recurrent_weights, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Implementes a single euler forward and adjoint backward step of a leaky integrate and fire neuron with current based exponential synapses.

Parameters
  • input (torch.Tensor) – input spikes from other cells

  • s (LIFState) – state of the lif neurons

  • input_weights (torch.Tensor) – synaptic weights for input spikes

  • recurrent_weights (torch.Tensor) – recurrent weights for recurrent spikes

  • p (LIFParameters) – parameters of the lif neurons

  • dt (float) – time step of integration

Return type

Tuple[Tensor, LIFState]

norse.torch.functional.adjoint.lif_adjoint.lif_feed_forward_adjoint_step(input, s, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Implementes a single euler forward and adjoint backward step of a leaky integrate and fire neuron with current based exponential synapses.

Parameters
Return type

Tuple[Tensor, LIFFeedForwardState]

norse.torch.functional.adjoint.lif_adjoint.lif_feed_forward_adjoint_step_sparse(input, s, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Implementes a single euler forward and adjoint backward step of a leaky integrate and fire neuron with current based exponential synapses.

Parameters
Return type

Tuple[Tensor, LIFFeedForwardState]