• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / sPyNNaker / 8784757783

22 Apr 2024 01:16PM UTC coverage: 69.531%. Remained the same
8784757783

push

github

Christian-B
mattnotmitt/doxygen-action@v1.9.8 and  JamesIves/github-pages-deploy-action@v4.5.0

7334 of 10026 branches covered (73.15%)

Branch coverage included in aggregate %.

12791 of 18918 relevant lines covered (67.61%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.33
/spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_utils.py
1
# Copyright (c) 2017 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
from typing import Tuple
1✔
16
import numpy
1✔
17
from numpy import integer, uint32
1✔
18
from numpy.typing import NDArray
1✔
19

20

21
def _calculate_stdp_times(
1✔
22
        pre_spikes: NDArray[integer], post_spikes: NDArray[integer],
23
        plastic_delay: int) -> Tuple[NDArray[integer], NDArray[integer]]:
24
    """
25
    :rtype: tuple(~numpy.ndarray, ~numpy.ndarray)
26
    """
27
    # If no post spikes, no changes
28
    if len(post_spikes) == 0:
×
29
        return numpy.zeros(0, dtype=uint32), numpy.zeros(0, dtype=uint32)
×
30

31
    # Get the spikes and time differences that will be considered by
32
    # the simulation (as the last pre-spike will be considered differently)
33
    last_pre_spike_delayed = pre_spikes[-1] - plastic_delay
×
34
    considered_post_spikes = post_spikes[post_spikes < last_pre_spike_delayed]
×
35
    if len(considered_post_spikes) == 0:
×
36
        return numpy.zeros(0, dtype=uint32), numpy.zeros(0, dtype=uint32)
×
37
    potentiation_time_diff = numpy.ravel(numpy.subtract.outer(
×
38
        considered_post_spikes + plastic_delay, pre_spikes[:-1]))
39
    potentiation_times = (
×
40
        potentiation_time_diff[potentiation_time_diff > 0] * -1)
41
    depression_time_diff = numpy.ravel(numpy.subtract.outer(
×
42
        considered_post_spikes + plastic_delay, pre_spikes))
43
    depression_times = depression_time_diff[depression_time_diff < 0]
×
44
    return potentiation_times, depression_times
×
45

46

47
def calculate_spike_pair_additive_stdp_weight(
1✔
48
        pre_spikes: NDArray[integer], post_spikes: NDArray[integer],
49
        initial_weight: float, plastic_delay: int,
50
        a_plus: float, a_minus: float,
51
        tau_plus: float, tau_minus: float) -> float:
52
    """
53
    Calculates the expected STDP weight for SpikePair Additive STDP.
54

55
    :param iterable(int) pre_spikes:
56
    :param iterable(int) post_spikes:
57
    :param float initial_weight:
58
    :param int plastic_delay: parameter of the STDP model
59
    :param float a_plus: parameter of the STDP model
60
    :param float a_minus: parameter of the STDP model
61
    :param float tau_plus: parameter of the STDP model
62
    :param float tau_minus: parameter of the STDP model
63
    :return: overall weight
64
    :rtype: float
65
    """
66
    potentiation_times, depression_times = _calculate_stdp_times(
×
67
        pre_spikes, post_spikes, plastic_delay)
68

69
    # Work out the weight according to the additive rule
70
    potentiations = a_plus * numpy.exp(potentiation_times / tau_plus)
×
71
    depressions = a_minus * numpy.exp(depression_times / tau_minus)
×
72

73
    # print("Potentiations: ", potentiation_times, potentiations)
74
    # print("Depressions:", depression_times, depressions)
75
    return initial_weight + numpy.sum(potentiations) - numpy.sum(depressions)
×
76

77

78
def calculate_spike_pair_multiplicative_stdp_weight(
1✔
79
        pre_spikes: NDArray[integer], post_spikes: NDArray[integer],
80
        initial_weight: float, plastic_delay: int,
81
        min_weight: float, max_weight: float,
82
        a_plus: float, a_minus: float,
83
        tau_plus: float, tau_minus: float) -> float:
84
    """
85
    Calculates the expected STDP weight for SpikePair Multiplicative STDP.
86

87
    :param iterable(int) pre_spikes: Spikes going into the model
88
    :param iterable(int) post_spikes: Spikes recorded on the model
89
    :param float initial_weight: Starting weight for the model
90
    :param int plastic_delay: parameter of the STDP model
91
    :param float min_weight: parameter of the STDP model
92
    :param float max_weight: parameter of the STDP model
93
    :param float a_plus: parameter of the STDP model
94
    :param float a_minus: parameter of the STDP model
95
    :param float tau_plus: parameter of the STDP model
96
    :param float tau_minus: parameter of the STDP model
97
    :return: overall weight
98
    :rtype: float
99
    """
100
    potentiation_times, depression_times = _calculate_stdp_times(
×
101
        pre_spikes, post_spikes, plastic_delay)
102

103
    # Work out the weight according to the multiplicative rule
104
    potentiations = (max_weight - initial_weight) * a_plus * numpy.exp(
×
105
        potentiation_times / tau_plus)
106
    depressions = (initial_weight - min_weight) * a_minus * numpy.exp(
×
107
        depression_times / tau_minus)
108
    return initial_weight + numpy.sum(potentiations) - numpy.sum(depressions)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc