MCPcopy Create free account
hub / github.com/BindsNET/bindsnet / run

Method run

bindsnet/network/network.py:252–465  ·  view source on GitHub ↗

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
    )

Source from the content-addressed store, hash-verified

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')

Callers 15

test_emptyMethod · 0.95
test_hebbianMethod · 0.95
test_post_preMethod · 0.95
test_mstdpMethod · 0.95
test_mstdpetMethod · 0.95
test_rmaxMethod · 0.95
test_weightsMethod · 0.95
BindsNET_cpuFunction · 0.95
BindsNET_gpuFunction · 0.95
TestMonitorClass · 0.80

Calls 9

_get_inputsMethod · 0.95
getMethod · 0.45
computeMethod · 0.45
set_batch_sizeMethod · 0.45
reset_state_variablesMethod · 0.45
updateMethod · 0.45
forwardMethod · 0.45
recordMethod · 0.45
normalizeMethod · 0.45

Tested by 9

test_emptyMethod · 0.76
test_hebbianMethod · 0.76
test_post_preMethod · 0.76
test_mstdpMethod · 0.76
test_mstdpetMethod · 0.76
test_rmaxMethod · 0.76
test_weightsMethod · 0.76