class sinabs.Network(analog_model=None, spiking_model=None, input_shape: Optional[Union[numpy.ndarray, List, Tuple]] = None, synops: bool = False, batch_size: int = 1, num_timesteps: int = 1)#

Class of a spiking neural network


torch.nn.Module, a spiking neural network model


torch.nn.Module, an artifical neural network model


Tuple, size of input


If True (default: False), register hooks for counting synaptic operations during forward passes, instantiating sinabs.SNNSynOpCounter.

compare_activations(data, name_list: Optional[Union[numpy.ndarray, List, Tuple]] = None, compute_rate: bool = False, verbose: bool = False) Tuple[numpy.ndarray, numpy.ndarray, str]#

Compare activations of the analog model and the SNN for a given data sample

  • data (np.ndarray) – Data to process

  • name_list (List[str]) – list of all layer names (str) whose activations need to be compared

  • compute_rate (bool) – True if you want to compute firing rate. By default spike count is returned

  • verbose (bool) – print debugging logs to the terminal


A tuple of lists (ann_activity, snn_activity, name_list)
  • ann_activity: output activity of the ann layers

  • snn_activity: output activity of the snn layers

  • name_list: spiking layers’ name list for plotting comparison

Return type


forward(tsrInput) torch.Tensor#

Forward pass for this model

get_synops(num_evs_in=None) pandas.core.frame.DataFrame#

Please see docs for sinabs.SNNSynOpCounter.get_synops().

plot_comparison(data, name_list: Optional[Union[numpy.ndarray, List, Tuple]] = None, compute_rate=False)#

Plots a scatter plot of all the activations

  • data – Data to be processed

  • name_list – ArrayLike with names of all the layers of interest to be compared

  • compute_rate – Compare firing rates instead of spike count


A tuple of lists (ann_activity, snn_activity)
  • ann_activity: output activity of the ann layers

  • snn_activity: output activity of the snn layers

Return type


reset_states(randomize: bool = False, value_ranges: Optional[List[Dict[str, Tuple[float, float]]]] = None)#

Reset all neuron states in the submodules.

  • randomize (Bool) – If true, reset the states between a range provided. Else, the states are reset to zero.

  • value_ranges (Optional[List[Dict[str, Tuple[float, float]]]]) – A list of value_range dictionaries with the same length as the total stateful layers in the module. Each dictionary is a key value pair: buffer_name -> (min, max) for each state that needs to be reset. The states are reset with a uniform distribution between the min and max values specified. Any state with an undefined key in this dictionary will be reset between 0 and 1 This parameter is only used if randomize is set to true.