Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables inhibitory stdp #284

Merged
merged 17 commits into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions models/stdp_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

FirstVersion: March 2006
Author: Moritz Helias, Abigail Morrison
Adapted by: Philipp Weidel
SeeAlso: synapsedict, tsodyks_synapse, static_synapse
*/

Expand Down Expand Up @@ -327,6 +328,13 @@ STDPConnection< targetidentifierT >::set_status( const DictionaryDatum& d,
updateValue< double_t >( d, "mu_plus", mu_plus_ );
updateValue< double_t >( d, "mu_minus", mu_minus_ );
updateValue< double_t >( d, "Wmax", Wmax_ );

// check if weight_ and Wmax_ has the same sign
if ( not( ( ( weight_ >= 0 ) - ( weight_ < 0 ) )
== ( ( Wmax_ >= 0 ) - ( Wmax_ < 0 ) ) ) )
{
throw BadProperty( "Weight and Wmax must have same sign." );
}
}

} // of namespace nest
Expand Down
19 changes: 14 additions & 5 deletions models/stdp_triplet_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@

FirstVersion: Nov 2007
Author: Abigail Morrison, Eilif Muller, Alexander Seeholzer, Teo Stocco
Adapted by: Philipp Weidel
SeeAlso: stdp_triplet_synapse_hpc, synapsedict, stdp_synapse, static_synapse
*/

#include <cmath>
// C-header for math.h since copysign() is in C99 but not C++98
#include <math.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment why you include math.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.

#include "connection.h"

namespace nest
Expand Down Expand Up @@ -195,16 +197,16 @@ class STDPTripletConnection : public Connection< targetidentifierT >
inline double_t
facilitate_( double_t w, double_t kplus, double_t ky )
{
double_t new_w = w + kplus * ( Aplus_ + Aplus_triplet_ * ky );
return new_w < Wmax_ ? new_w : Wmax_;
double_t new_w = std::abs( w ) + kplus * ( Aplus_ + Aplus_triplet_ * ky );
return copysign( new_w < std::abs( Wmax_ ) ? new_w : Wmax_, Wmax_ );
}

inline double_t
depress_( double_t w, double_t kminus, double_t Kplus_triplet_ )
{
double_t new_w =
w - kminus * ( Aminus_ + Aminus_triplet_ * Kplus_triplet_ );
return new_w > 0.0 ? new_w : 0.0;
std::abs( w ) - kminus * ( Aminus_ + Aminus_triplet_ * Kplus_triplet_ );
return copysign( new_w > 0.0 ? new_w : 0.0, Wmax_ );
}

// data members of each connection
Expand Down Expand Up @@ -355,6 +357,13 @@ STDPTripletConnection< targetidentifierT >::set_status(
updateValue< double_t >( d, "Kplus_triplet", Kplus_triplet_ );
updateValue< double_t >( d, "Wmax", Wmax_ );

// check if weight_ and Wmax_ has the same sign
if ( not( ( ( weight_ >= 0 ) - ( weight_ < 0 ) )
== ( ( Wmax_ >= 0 ) - ( Wmax_ < 0 ) ) ) )
{
throw BadProperty( "Weight and Wmax must have same sign." );
}

if ( not( Kplus_ >= 0 ) )
{
throw BadProperty( "State Kplus must be positive." );
Expand Down
66 changes: 58 additions & 8 deletions pynest/nest/tests/test_stdp_triplet_synapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import nest
import unittest
from math import exp
import numpy as np


@nest.check_stack
Expand Down Expand Up @@ -80,25 +81,27 @@ def status(self, which):

def decay(self, time, Kplus, Kplus_triplet, Kminus, Kminus_triplet):
"""Decay variables."""
Kplus *= exp(- time / self.syn_spec["tau_plus"])
Kplus_triplet *= exp(- time / self.syn_spec["tau_plus_triplet"])
Kminus *= exp(- time / self.post_neuron_params["tau_minus"])
Kminus_triplet *= exp(- time /
Kplus *= exp(-time / self.syn_spec["tau_plus"])
Kplus_triplet *= exp(-time / self.syn_spec["tau_plus_triplet"])
Kminus *= exp(-time / self.post_neuron_params["tau_minus"])
Kminus_triplet *= exp(-time /
self.post_neuron_params["tau_minus_triplet"])
return (Kplus, Kplus_triplet, Kminus, Kminus_triplet)

def facilitate(self, w, Kplus, Kminus_triplet):
"""Facilitate weight."""
return w + Kplus * (
Wmax = self.status("Wmax")
return np.sign(Wmax) * (abs(w) + Kplus * (
self.syn_spec["Aplus"] +
self.syn_spec["Aplus_triplet"] * Kminus_triplet
self.syn_spec["Aplus_triplet"] * Kminus_triplet)
)

def depress(self, w, Kminus, Kplus_triplet):
"""Depress weight."""
return w - Kminus * (
Wmax = self.status("Wmax")
return np.sign(Wmax) * (abs(w) - Kminus * (
self.syn_spec["Aminus"] +
self.syn_spec["Aminus_triplet"] * Kplus_triplet
self.syn_spec["Aminus_triplet"] * Kplus_triplet)
)

def assertAlmostEqualDetailed(self, expected, given, message):
Expand All @@ -109,6 +112,7 @@ def assertAlmostEqualDetailed(self, expected, given, message):

def test_badPropertiesSetupsThrowExceptions(self):
"""Check that exceptions are thrown when setting bad parameters."""

def setupProperty(property):
bad_syn_spec = self.syn_spec.copy()
bad_syn_spec.update(property)
Expand Down Expand Up @@ -201,6 +205,7 @@ def test_weightChangeWhenPrePostSpikes(self):
Kminus = 0.0
Kminus_triplet = 0.0
weight = self.status("weight")
Wmax = self.status("Wmax")

(Kplus, Kplus_triplet, Kminus, Kminus_triplet) = self.decay(
2.0, Kplus, Kplus_triplet, Kminus, Kminus_triplet)
Expand Down Expand Up @@ -239,6 +244,7 @@ def test_weightChangeWhenPrePostPreSpikes(self):
Kminus = 0.0
Kminus_triplet = 0.0
weight = self.status("weight")
Wmax = self.status("Wmax")

(Kplus, Kplus_triplet, Kminus, Kminus_triplet) = self.decay(
2.0, Kplus, Kplus_triplet, Kminus, Kminus_triplet)
Expand Down Expand Up @@ -288,13 +294,57 @@ def test_maxWeightStaturatesWeight(self):
"weight"), "weight should have been limited")


@nest.check_stack
class STDPTripletInhTestCase(STDPTripletConnectionTestCase):

def setUp(self):
nest.set_verbosity('M_WARNING')
nest.ResetKernel()

# settings
self.dendritic_delay = 1.0
self.decay_duration = 5.0
self.synapse_model = "stdp_triplet_synapse"
self.syn_spec = {
"model": self.synapse_model,
"delay": self.dendritic_delay,
# set receptor 1 post-synaptically, to not generate extra spikes
"receptor_type": 1,
"weight": -5.0,
"tau_plus": 16.8,
"tau_plus_triplet": 101.0,
"Aplus": 0.1,
"Aminus": 0.1,
"Aplus_triplet": 0.1,
"Aminus_triplet": 0.1,
"Kplus": 0.0,
"Kplus_triplet": 0.0,
"Wmax": -100.0,
}
self.post_neuron_params = {
"tau_minus": 33.7,
"tau_minus_triplet": 125.0,
}

# setup basic circuit
self.pre_neuron = nest.Create("parrot_neuron")
self.post_neuron = nest.Create("parrot_neuron", 1,
params=self.post_neuron_params)
nest.Connect(self.pre_neuron, self.post_neuron, syn_spec=self.syn_spec)


def suite_inh():
return unittest.makeSuite(STDPTripletInhTestCase, "test")


def suite():
return unittest.makeSuite(STDPTripletConnectionTestCase, "test")


def run():
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite())
runner.run(suite_inh())

if __name__ == "__main__":
run()
Loading