Simulate network for given inputs and time. :param inputs: Dictionary of ``Tensor``s of shape ``[time, *input_shape]`` or ``[time, batch_size, *input_shape]``. :param time: Simulation time. :param one_step: Whether to run the network in "feed-f
(
self, inputs: Dict[str, torch.Tensor], time: int, one_step=False, **kwargs
)
| 250 | return inputs |
| 251 | |
| 252 | def run( |
| 253 | self, inputs: Dict[str, torch.Tensor], time: int, one_step=False, **kwargs |
| 254 | ) -> None: |
| 255 | # language=rst |
| 256 | """ |
| 257 | Simulate network for given inputs and time. |
| 258 | |
| 259 | :param inputs: Dictionary of ``Tensor``s of shape ``[time, *input_shape]`` or |
| 260 | ``[time, batch_size, *input_shape]``. |
| 261 | :param time: Simulation time. |
| 262 | :param one_step: Whether to run the network in "feed-forward" mode, where inputs |
| 263 | propagate all the way through the network in a single simulation time step. |
| 264 | Layers are updated in the order they are added to the network. |
| 265 | |
| 266 | Keyword arguments: |
| 267 | |
| 268 | :param Dict[str, torch.Tensor] clamp: Mapping of layer names to boolean masks if |
| 269 | neurons should be clamped to spiking. The ``Tensor``s have shape |
| 270 | ``[n_neurons]`` or ``[time, n_neurons]``. |
| 271 | :param Dict[str, torch.Tensor] unclamp: Mapping of layer names to boolean masks |
| 272 | if neurons should be clamped to not spiking. The ``Tensor``s should have |
| 273 | shape ``[n_neurons]`` or ``[time, n_neurons]``. |
| 274 | :param Dict[str, torch.Tensor] injects_v: Mapping of layer names to boolean |
| 275 | masks if neurons should be added voltage. The ``Tensor``s should have shape |
| 276 | ``[n_neurons]`` or ``[time, n_neurons]``. |
| 277 | :param Union[float, torch.Tensor] reward: Scalar value used in reward-modulated |
| 278 | learning. |
| 279 | :param Dict[Tuple[str], torch.Tensor] masks: Mapping of connection names to |
| 280 | boolean masks determining which weights to clamp to zero. |
| 281 | :param Bool progress_bar: Show a progress bar while running the network. |
| 282 | |
| 283 | **Example:** |
| 284 | |
| 285 | .. code-block:: python |
| 286 | |
| 287 | import torch |
| 288 | import matplotlib.pyplot as plt |
| 289 | |
| 290 | from bindsnet.network import Network |
| 291 | from bindsnet.network.nodes import Input |
| 292 | from bindsnet.network.monitors import Monitor |
| 293 | |
| 294 | # Build simple network. |
| 295 | network = Network() |
| 296 | network.add_layer(Input(500), name='I') |
| 297 | network.add_monitor(Monitor(network.layers['I'], state_vars=['s']), 'I') |
| 298 | |
| 299 | # Generate spikes by running Bernoulli trials on Uniform(0, 0.5) samples. |
| 300 | spikes = torch.bernoulli(0.5 * torch.rand(500, 500)) |
| 301 | |
| 302 | # Run network simulation. |
| 303 | network.run(inputs={'I' : spikes}, time=500) |
| 304 | |
| 305 | # Look at input spiking activity. |
| 306 | spikes = network.monitors['I'].get('s') |
| 307 | plt.matshow(spikes, cmap='binary') |
| 308 | plt.xticks(()); plt.yticks(()); |
| 309 | plt.xlabel('Time'); plt.ylabel('Neuron index') |