LoadedStimulus

class spikeometric.stimulus.LoadedStimulus(path: str, batch_size: int = 1)[source]

Bases: spikeometric.stimulus.base_stimulus.BaseStimulus

Stimulus loaded from a file. The file should be a .pt file containing a torch.Tensor of shape (n_neurons, n_steps, n_networks), where n_neurons is the number of neurons in the network and n_steps is the number of time steps in the stimulus. At each time step, the stimulus is a torch.Tensor of length n_neurons, indicating the stimulus to each neuron.

Example

>>> from spikeometric.stimulus import LoadedStimulus
>>> stimulus = LoadedStimulus("example_directory/stimulus_file.pt", batch_size=3)
>>> stimulus(0).shape
torch.Size([60])
>>> stimulus.set_batch(3)
>>> stimulus(0).shape
torch.Size([20])
>>> stimulus.reset()
>>> model.add_stimulus(stimulus)
Parameters
  • path (str) – Path to the file containing the stimulus.

  • batch_size (int, optional) – Number of networks in each batch. If the number of networks in the stimulus is not a multiple of the batch size, the last batch will contain fewer networks. Default: 1.

property stimulus
__call__(t: Union[float, torch.Tensor]) torch.Tensor[source]

If \(t\) is a float, returns the stimulus at time \(t\). If \(t\) is a torch.Tensor, returns the stimulus at each time step in \(t\), and the returned tensor has shape (n_neurons, t.shape[0])

Parameters

t (torch.Tensor or float) – Time \(t\) at which to compute the stimulus.

Returns

Stimulus at time \(t\).

Return type

torch.Tensor [n_neurons, t.shape[0]] or [n_neurons]