model#
- class arcana.model.ADM(N: int, threshold_up: float, threshold_down: float, refractory: int, surrogate_fn: ~typing.Callable = <bound method Function.apply of <class 'arcana.surrogate.FastSigmoid'>>)[source]#
Bases:
ModuleAdaptive Delta Modulation (ADM) module Converts an analog signal into UP and DOWN spikes using the Adaptive Delta Modulation scheme.
- forward(input_signal)[source]#
Define 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
Moduleinstance 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.
- Parameters:
spikes (Input spikes from where the signal is reconstructed.)
initial_value (Initial reconstructed signal value.)
- class arcana.model.DPINeuron(n_in: int, n_out: int, dt: float = 0.001, surrogate_fn: ~typing.Callable = <bound method Function.apply of <class 'arcana.surrogate.FastSigmoid'>>, train_Itau_mem: bool = False, train_Igain_mem: bool = False, train_Idc: bool = False, train_ampa: bool = False, train_gabab: bool = False, **kwargs)[source]#
Bases:
ModuleDPI neuron model used in Dynap-SE chip, including AMPA, NMDA, GABAa and GABAb synapses. The bias parameters of the neurons areÑ | Parameter | Description | | :——– | :———- | | Itau_mem | Soma leakage current | | Igain_mem | Soma gain current | | Ipfb_th | Positive feedback bias | | Ipfb_norm | Positive feedback normalization | | refractory | Refractory period | | Ith | Firing threshold | | Idc | Input constant current | | Itau_ampa | AMPA synapse leakage current | | Igain_ampa | AMPA synapse gain current | | Iw_ampa | AMPA synapse base weight | | Inmda_thr | NMDA synapse threshold | | Itau_nmda | NMDA synapse leakage current | | Igain_nmda | NMDA synapse gain current | | Iw_nmda | NMDA synapse base weight | | Itau_gabaa | GABAa synapse leakage current | | Igain_gabaa | GABAa synapse gain current | | Iw_gabaa | GABAa synapse base weight | | Itau_gabab | GABAb synapse leakage current | | Igain_gabab | GABAb synapse gain current | | Iw_gabab | GABAb synapse base weight |
- Parameters:
n_in (int) – Number of input synapses
n_out (int) – Number of neuron in the layer
dt (float) – Simulation timestep in seconds
surrogate_fn (Callable) – Surrogate gradient function for spiking
train_Itau_mem (bool) – Flag to train the membrane leakage current bias
train_Igain_mem (bool) – Flag to train the membrane input gain bias
train_Idc (bool) – Flag to train the input constant current
train_ampa (bool) – Flag to train the ampa weight matrix
train_gabab (bool) – Flag to train the gaba_b weight matrix
- static I2V(current: float) float[source]#
Convert a current value into a voltage based on the parameters of the DPINeuron
- UpdateParams(optimizer, args, kwargs)[source]#
Call each time to gradient optimization is called to update correctly the neuron parameters.
- static V2I(voltage: float) float[source]#
Convert a voltage value into a current based on the parameters of the DPINeuron
- add_mismatch(param: str, mismatch: float = 0.1)[source]#
The DPINeuron can include mismatch in the biases by calling this function with the name of the bias and the percentage of variability. :param param: :type param: Bias name to apply the mismatch. :param mismatch: :type mismatch: Percentage of variability to apply [0-1]
- forward(X, state=None)[source]#
Define 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class arcana.model.Round(inplace=False)[source]#
Bases:
InplaceFunctionRound operation with straight through stimator surrogate gradient.
- static backward(ctx, grad_output)[source]#
Define a formula for differentiating the operation with backward mode automatic differentiation.
This function is to be overridden by all subclasses. (Defining this function is equivalent to defining the
vjpfunction.)It must accept a context
ctxas the first argument, followed by as many outputs as theforward()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 toforward(). 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_gradas a tuple of booleans representing whether each input needs gradient. E.g.,backward()will havectx.needs_input_grad[0] = Trueif the first input toforward()needs gradient computed w.r.t. the output.
- static forward(ctx, input)[source]#
Define the forward of the custom autograd Function.
This function is to be overridden by all subclasses. There are two ways to define forward:
Usage 1 (Combined forward and ctx):
@staticmethod def forward(ctx: Any, *args: Any, **kwargs: Any) -> Any: pass
It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).
See combining-forward-context for more details
Usage 2 (Separate forward and ctx):
@staticmethod def forward(*args: Any, **kwargs: Any) -> Any: pass @staticmethod def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None: pass
The forward no longer accepts a ctx argument.
Instead, you must also override the
torch.autograd.Function.setup_context()staticmethod to handle setting up thectxobject.outputis the output of the forward,inputsare a Tuple of inputs to the forward.See extending-autograd for more details
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 inbackward(equivalently,vjp) orctx.save_for_forward()if they are intended to be used for injvp.