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

SpiNNakerManchester / sPyNNaker / 6852594677

13 Nov 2023 04:06PM UTC coverage: 61.308%. First build
6852594677

push

github

Christian-B
weight and delay are properties

1929 of 4467 branches covered (0.0%)

Branch coverage included in aggregate %.

4 of 4 new or added lines in 2 files covered. (100.0%)

11736 of 17822 relevant lines covered (65.85%)

0.66 hits per line

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

13.79
/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
import numpy
1✔
16

17

18
def _calculate_stdp_times(pre_spikes, post_spikes, plastic_delay):
1✔
19
    """
20
    :rtype: tuple(~numpy.ndarray, ~numpy.ndarray)
21
    """
22
    # If no post spikes, no changes
23
    if len(post_spikes) == 0:
×
24
        return numpy.zeros(0), numpy.zeros(0)
×
25

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

41

42
def calculate_spike_pair_additive_stdp_weight(
1✔
43
        pre_spikes, post_spikes, initial_weight, plastic_delay,
44
        a_plus, a_minus, tau_plus, tau_minus):
45
    """
46
    Calculates the expected STDP weight for SpikePair Additive STDP.
47

48
    :param iterable(int) pre_spikes:
49
    :param iterable(int) post_spikes:
50
    :param float initial_weight:
51
    :param int plastic_delay: parameter of the STDP model
52
    :param float a_plus: parameter of the STDP model
53
    :param float a_minus: parameter of the STDP model
54
    :param float tau_plus: parameter of the STDP model
55
    :param float tau_minus: parameter of the STDP model
56
    :return: overall weight
57
    :rtype: float
58
    """
59
    potentiation_times, depression_times = _calculate_stdp_times(
×
60
        pre_spikes, post_spikes, plastic_delay)
61

62
    # Work out the weight according to the additive rule
63
    potentiations = a_plus * numpy.exp(
×
64
        (potentiation_times / tau_plus))
65
    depressions = a_minus * numpy.exp(
×
66
        (depression_times / tau_minus))
67

68
    print("Potentiations: ", potentiation_times, potentiations)
×
69
    print("Depressions:", depression_times, depressions)
×
70
    return initial_weight + numpy.sum(potentiations) - numpy.sum(depressions)
×
71

72

73
def calculate_spike_pair_multiplicative_stdp_weight(
1✔
74
        pre_spikes, post_spikes, initial_weight, plastic_delay, min_weight,
75
        max_weight, a_plus, a_minus, tau_plus, tau_minus):
76
    """
77
    Calculates the expected STDP weight for SpikePair Multiplicative STDP.
78

79
    :param iterable(int) pre_spikes: Spikes going into the model
80
    :param iterable(int) post_spikes: Spikes recorded on the model
81
    :param float initial_weight: Starting weight for the model
82
    :param int plastic_delay: parameter of the STDP model
83
    :param float min_weight: parameter of the STDP model
84
    :param float max_weight: parameter of the STDP model
85
    :param float a_plus: parameter of the STDP model
86
    :param float a_minus: parameter of the STDP model
87
    :param float tau_plus: parameter of the STDP model
88
    :param float tau_minus: parameter of the STDP model
89
    :return: overall weight
90
    :rtype: float
91
    """
92
    potentiation_times, depression_times = _calculate_stdp_times(
×
93
        pre_spikes, post_spikes, plastic_delay)
94

95
    # Work out the weight according to the multiplicative rule
96
    potentiations = (max_weight - initial_weight) * a_plus * numpy.exp(
×
97
        (potentiation_times / tau_plus))
98
    depressions = (initial_weight - min_weight) * a_minus * numpy.exp(
×
99
        (depression_times / tau_minus))
100
    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