Specifies synapses between one or two populations of neurons.
| 400 | |
| 401 | |
| 402 | class MulticompartmentConnection(AbstractMulticompartmentConnection): |
| 403 | # language=rst |
| 404 | """ |
| 405 | Specifies synapses between one or two populations of neurons. |
| 406 | """ |
| 407 | |
| 408 | def __init__( |
| 409 | self, |
| 410 | source: Nodes, |
| 411 | target: Nodes, |
| 412 | device: device, |
| 413 | pipeline: list = [], |
| 414 | manual_update: bool = False, |
| 415 | traces: bool = False, |
| 416 | **kwargs, |
| 417 | ) -> None: |
| 418 | # language=rst |
| 419 | """ |
| 420 | Instantiates a :code:`Connection` object. |
| 421 | |
| 422 | :param source: A layer of nodes from which the connection originates. |
| 423 | :param target: A layer of nodes to which the connection connects. |
| 424 | :param device: The device the connection will be run on. |
| 425 | :param list: Pipeline of features for the connection signals to be run through |
| 426 | :param manual_update: Set to :code:`True` to disable automatic updates (applying learning rules) to connection features. |
| 427 | False by default, updates called after each time step |
| 428 | :param traces: Set to :code:`True` to record history of connection activity (for monitors) |
| 429 | """ |
| 430 | |
| 431 | super().__init__(source, target, device, pipeline, **kwargs) |
| 432 | self.traces = traces |
| 433 | self.manual_update = manual_update |
| 434 | if self.traces: |
| 435 | self.activity = None |
| 436 | |
| 437 | def compute(self, s: torch.Tensor) -> torch.Tensor: |
| 438 | # language=rst |
| 439 | """ |
| 440 | Compute pre-activations given spikes using connection weights. |
| 441 | |
| 442 | :param s: Incoming spikes. |
| 443 | :return: Incoming spikes multiplied by synaptic weights (with or without |
| 444 | decaying spike activation). |
| 445 | """ |
| 446 | |
| 447 | # Change to numeric type (torch doesn't like booleans for matrix ops) |
| 448 | # Note: .float() is an expensive operation. Use as minimally as possible! |
| 449 | # if s.dtype != torch.float32: |
| 450 | # s = s.float() |
| 451 | |
| 452 | # Prepare broadcast from incoming spikes to all output neurons |
| 453 | # |conn_spikes| = [batch_size, source.n * target.n] |
| 454 | conn_spikes = s.view(s.size(0), self.source.n, 1).repeat(1, 1, self.target.n) |
| 455 | # TODO: ^ This could probably be optimized |
| 456 | |
| 457 | # Run through pipeline |
| 458 | for f in self.pipeline: |
| 459 | conn_spikes = f.compute(conn_spikes) |
no outgoing calls
no test coverage detected