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

define stp parameters for synapses from a distribution [WIP] #75

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
21 changes: 12 additions & 9 deletions carlsim/interface/inc/carlsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ class CARLsim {
void setISTDP(int grpId, bool isSet, STDPType type, PulseCurve curve);

/*!
* \brief Sets STP params U, tau_u, and tau_x of a neuron group (pre-synaptically)
* \brief Sets STP params U, tau_u, and tau_x of a neuron group in
* terms of mean and standard deviation (pre-synaptically)
*
* CARLsim implements the short-term plasticity model of (Tsodyks & Markram, 1998; Mongillo, Barak, & Tsodyks, 2008)
* \f{eqnarray}
Expand All @@ -750,15 +751,16 @@ class CARLsim {
* Source: Misha Tsodyks and Si Wu (2013) Short-term synaptic plasticity. Scholarpedia, 8(10):3153., rev #136920
*
* \STATE ::CONFIG_STATE
* \param[in] grpId pre-synaptic group ID
* \param[in] preGrpId pre-synaptic group ID
* \param[in] postGrpId post-synaptic group ID
* \param[in] isSet a flag whether to enable/disable STP
* \param[in] STP_U increment of u induced by a spike
* \param[in] STP_tau_u decay constant of u (tau_F)
* \param[in] STP_tau_x decay constant of x (tau_D)
* \note STP will be applied to all outgoing synapses of all neurons in this group.
* \param[in] STP_U Normal distribution mean and sd of increment of u induced by a spike
* \param[in] STP_tau_u Normal distribution mean and sd of decay constant of u (tau_F)
* \param[in] STP_tau_x Normal distribution mean and sd of decay constant of x (tau_D)
* \note STP will be applied to all outgoing synapses of all neurons in this group. Each neuron in the group will have individual STP parameters drawn from the normal distribution.
* \note All outgoing synapses of a certain (pre-synaptic) neuron share the resources of that same neuron.
*/
void setSTP(int grpId, bool isSet, float STP_U, float STP_tau_u, float STP_tau_x);
void setSTP(int preGrpId, int postGrpId, bool isSet, const STPu& STP_U, const STPtauU& STP_tau_u, const STPtauX& STP_tau_x);

/*!
* \brief Sets STP params U, tau_u, and tau_x of a neuron group (pre-synaptically) using default values
Expand All @@ -773,15 +775,16 @@ class CARLsim {
* These default values can be overridden using setDefaultSTPparams.
*
* \STATE ::CONFIG_STATE
* \param[in] grpId pre-synaptic group ID
* \param[in] preGrpId pre-synaptic group ID
* \param[in] postGrpId post-synaptic group ID
* \param[in] isSet a flag whether to enable/disable STP
* \note STP will be applied to all outgoing synapses of all neurons in this group.
* \note All outgoing synapses of a certain (pre-synaptic) neuron share the resources of that same neuron.
* \see setDefaultSTPparams
* \see setSTP(int, bool, float, float, float)
* \since v3.0
*/
void setSTP(int grpId, bool isSet);
void setSTP(int preGrpId, int postGrpId, bool isSet);

/*!
* \brief Sets the weight and weight change update parameters
Expand Down
86 changes: 83 additions & 3 deletions carlsim/interface/inc/carlsim_datastructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,93 @@ struct RangeDelay {
min = _min;
max = _max;
}
int min, max;
};
/*!
* \brief a distribution struct for STPu parameters
*
* STPu parameter distribution specified using mean and standard deviation
* \param[in] mean STPu value
* \param[in] standard STPu value
* Examples:
* STPu(2) => all STPu will be 2
* STpu(1,10) => STPu will be from the normal distribution with mean 1 and SD 10
*/
struct STPu {
STPu(double _mean) {
mean = _mean;
std = 0.0;
}

STPu(double _mean, double _sd) {
UserErrors::assertTrue(_sd>=0.0, UserErrors::CANNOT_BE_NEGATIVE, "STPu", "mean_STPu", "sd_STPu");
mean = _mean;
std = _sd;
}

friend std::ostream& operator<<(std::ostream &strm, const RangeDelay &d) {
return strm << "delay=[" << d.min << "," << d.max << "]";
friend std::ostream& operator<<(std::ostream &strm, const STPu &u) {
return strm << "STPu=[" << u.mean << "," << u.std << "]";
}
int min,max;
double mean, std;
};

/*!
* \brief a distribution struct for STP_tau_u parameters
*
* STP_tau_u parameter distribution specified using mean and standard deviation
* \param[double] mean STP_tau_u value
* \param[double] standard STP_tau_u value
* Examples:
* STP_tau_u(2) => all STP_tau_u will be 2
* STP_tau_u(1,10) => STP_tau_u will be from the normal distribution with mean 1 and SD 10
*/
struct STPtauU {
STPtauU(double _mean) {
mean = _mean;
std = 0.0;
}

STPtauU(double _mean, double _sd) {
UserErrors::assertTrue(_sd>=0.0, UserErrors::CANNOT_BE_NEGATIVE, "STP_tau_u", "mean_STP_tau_u", "sd_STP_tau_u");
mean = _mean;
std = _sd;
}

friend std::ostream& operator<<(std::ostream &strm, const STPtauU &tau_u) {
return strm << "STP_tau_u=[" << tau_u.mean << "," << tau_u.std << "]";
}
double mean, std;
};

/*!
* \brief a distribution struct for STP_tau_x parameters
*
* STP_tau_x parameter distribution specified using mean and standard deviation
* \param[double] mean STP_tau_x value
* \param[double] standard STP_tau_x value
* Examples:
* STP_tau_x(2) => all STP_tau_x will be 2
* STP_tau_x(1,10) => STP_tau_x will be from the normal distribution with mean 1 and SD 10
*/
struct STPtauX {
STPtauX(double _mean) {
mean = _mean;
std = 0.0;
}

STPtauX(double _mean, double _sd) {
UserErrors::assertTrue(_sd>=0.0, UserErrors::CANNOT_BE_NEGATIVE, "STP_tau_x", "mean_STP_tau_x", "sd_STP_tau_x");
mean = _mean;
std = _sd;
}

friend std::ostream& operator<<(std::ostream &strm, const STPtauX &tau_x) {
return strm << "STP_tau_x=[" << tau_x.mean << "," << tau_x.std << "]";
}
double mean, std;
};


/*!
* \brief a range struct for synaptic weight magnitudes
*
Expand Down
86 changes: 51 additions & 35 deletions carlsim/interface/src/carlsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,44 +786,46 @@ class CARLsim::Impl {
}

// set STP, default
void setSTP(int grpId, bool isSet) {
std::string funcName = "setSTP(\""+getGroupName(grpId)+"\")";
void setSTP(int preGrpId, int postGrpId, bool isSet) {
std::string funcName = "setSTP(\""+getGroupName(preGrpId)+ " ," + getGroupName(postGrpId)+"\")";
UserErrors::assertTrue(carlsimState_==CONFIG_STATE, UserErrors::CAN_ONLY_BE_CALLED_IN_STATE, funcName,
funcName, "CONFIG.");

hasSetSTPALL_ = grpId==ALL; // adding groups after this will not have conductances set
hasSetSTPALL_ = preGrpId==ALL; // adding groups after this will not have conductances set

if (isSet) { // enable STDP, use default values
UserErrors::assertTrue(isExcitatoryGroup(grpId) || isInhibitoryGroup(grpId), UserErrors::WRONG_NEURON_TYPE,
UserErrors::assertTrue(isExcitatoryGroup(preGrpId) || isInhibitoryGroup(preGrpId), UserErrors::WRONG_NEURON_TYPE,
funcName, "setSTP");

if (isExcitatoryGroup(grpId))
snn_->setSTP(grpId,true,def_STP_U_exc_,def_STP_tau_u_exc_,def_STP_tau_x_exc_);
else if (isInhibitoryGroup(grpId))
snn_->setSTP(grpId,true,def_STP_U_inh_,def_STP_tau_u_inh_,def_STP_tau_x_inh_);
if (isExcitatoryGroup(preGrpId))
// snn_->setSTP(grpId,true,def_STP_U_exc_,def_STP_tau_u_exc_,def_STP_tau_x_exc_);
snn_->setSTP(preGrpId, postGrpId, isSet, def_STP_U_exc_mean, def_STP_U_exc_std, def_STP_tau_u_exc_mean, def_STP_tau_u_exc_std, def_STP_tau_x_exc_mean, def_STP_tau_x_exc_std);
else if (isInhibitoryGroup(preGrpId))
//snn_->setSTP(grpId,true,def_STP_U_inh_,def_STP_tau_u_inh_,def_STP_tau_x_inh_);
snn_->setSTP(preGrpId, postGrpId, isSet, def_STP_U_inh_mean, def_STP_U_inh_std, def_STP_tau_u_inh_mean, def_STP_tau_u_inh_std, def_STP_tau_x_inh_mean, def_STP_tau_x_inh_std);
else {
// some error message
// otherwise it will fail the assert anyway
}
} else { // disable STDP
snn_->setSTP(grpId,false,0.0f,0.0f,0.0f);
snn_->setSTP(preGrpId, postGrpId, isSet, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
}
}

// set STP, custom
void setSTP(int grpId, bool isSet, float STP_U, float STP_tau_u, float STP_tau_x) {
std::string funcName = "setSTP(\""+getGroupName(grpId)+"\")";
// set STP, custom normal distributed STP parameters
void setSTP(int preGrpId, int postGrpId, bool isSet, const STPu& STP_U, const STPtauU& STP_tau_u, const STPtauX& STP_tau_x){
std::string funcName = "setSTP(\""+getGroupName(preGrpId)+ " ," + getGroupName(postGrpId)+"\")";
UserErrors::assertTrue(carlsimState_==CONFIG_STATE, UserErrors::CAN_ONLY_BE_CALLED_IN_STATE, funcName,
funcName, "CONFIG.");

hasSetSTPALL_ = grpId==ALL; // adding groups after this will not have conductances set
hasSetSTPALL_ = preGrpId==ALL; // adding groups after this will not have conductances set

if (isSet) { // enable STDP, use default values
UserErrors::assertTrue(isExcitatoryGroup(grpId) || isInhibitoryGroup(grpId), UserErrors::WRONG_NEURON_TYPE,
UserErrors::assertTrue(isExcitatoryGroup(preGrpId) || isInhibitoryGroup(preGrpId), UserErrors::WRONG_NEURON_TYPE,
funcName,"setSTP");

snn_->setSTP(grpId,true,STP_U,STP_tau_u,STP_tau_x);
snn_->setSTP(preGrpId, postGrpId, isSet, STP_U.mean, STP_U.std, STP_tau_u.mean, STP_tau_u.std, STP_tau_x.mean, STP_tau_x.std);
} else { // disable STDP
snn_->setSTP(grpId,false,0.0f,0.0f,0.0f);
snn_->setSTP(preGrpId, postGrpId, isSet, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
}
}

Expand Down Expand Up @@ -1543,25 +1545,32 @@ class CARLsim::Impl {
}

// set default STP values for an EXCITATORY_NEURON or INHIBITORY_NEURON
void setDefaultSTPparams(int neurType, float STP_U, float STP_tau_u, float STP_tau_x) {
// void setDefaultSTPparams(int neurType, float STP_U, float STP_tau_u, float STP_tau_x) {
void setDefaultSTPparams(int neurType, const STPu& STP_U, const STPtauU& STP_tau_u, const STPtauX& STP_tau_x){
std::string funcName = "setDefaultSTPparams()";
UserErrors::assertTrue(neurType==EXCITATORY_NEURON || neurType==INHIBITORY_NEURON, UserErrors::WRONG_NEURON_TYPE,
funcName);
UserErrors::assertTrue(carlsimState_==CONFIG_STATE, UserErrors::CAN_ONLY_BE_CALLED_IN_STATE, funcName, funcName, "CONFIG.");

assert(STP_tau_u>0.0f);
assert(STP_tau_x>0.0f);
assert(STP_tau_u.mean>0.0f);
assert(STP_tau_x.mean>0.0f);

switch (neurType) {
case EXCITATORY_NEURON:
def_STP_U_exc_ = STP_U;
def_STP_tau_u_exc_ = STP_tau_u;
def_STP_tau_x_exc_ = STP_tau_x;
def_STP_U_exc_mean = STP_U.mean;
def_STP_tau_u_exc_mean = STP_tau_u.mean;
def_STP_tau_x_exc_mean = STP_tau_x.mean;
def_STP_U_exc_std = STP_U.std;
def_STP_tau_u_exc_std = STP_tau_u.std;
def_STP_tau_x_exc_std = STP_tau_x.std;
break;
case INHIBITORY_NEURON:
def_STP_U_inh_ = STP_U;
def_STP_tau_u_inh_ = STP_tau_u;
def_STP_tau_x_inh_ = STP_tau_x;
def_STP_U_inh_mean = STP_U.mean;
def_STP_tau_u_inh_mean = STP_tau_u.mean;
def_STP_tau_x_inh_mean = STP_tau_x.mean;
def_STP_U_inh_std = STP_U.std;
def_STP_tau_u_inh_std = STP_tau_u.std;
def_STP_tau_x_inh_std = STP_tau_x.std;
break;
default:
// some error message instead of assert
Expand Down Expand Up @@ -1697,12 +1706,19 @@ class CARLsim::Impl {
float def_STDP_delta_; //!< default value for interval of LTD

// all default values for STP
float def_STP_U_exc_; //!< default value for STP U excitatory
float def_STP_tau_u_exc_; //!< default value for STP u decay (\tau_F) excitatory (ms)
float def_STP_tau_x_exc_; //!< default value for STP x decay (\tau_D) excitatory (ms)
float def_STP_U_inh_; //!< default value for STP U inhibitory
float def_STP_tau_u_inh_; //!< default value for STP u decay (\tau_F) inhibitory (ms)
float def_STP_tau_x_inh_; //!< default value for STP x decay (\tau_D) inhibitory (ms)
float def_STP_U_exc_mean; //!< default value for STP U excitatory
float def_STP_tau_u_exc_mean; //!< default value for STP u decay (\tau_F) excitatory (ms)
float def_STP_tau_x_exc_mean; //!< default value for STP x decay (\tau_D) excitatory (ms)
float def_STP_U_exc_std; //!< default value for STP U excitatory
float def_STP_tau_u_exc_std; //!< default value for STP u decay (\tau_F) excitatory (ms)
float def_STP_tau_x_exc_std; //!< default value for STP x decay (\tau_D) excitatory (ms)

float def_STP_U_inh_mean; //!< default value for STP U inhibitory
float def_STP_tau_u_inh_mean; //!< default value for STP u decay (\tau_F) inhibitory (ms)
float def_STP_tau_x_inh_mean; //!< default value for STP x decay (\tau_D) inhibitory (ms)
float def_STP_U_inh_std; //!< default value for STP U inhibitory
float def_STP_tau_u_inh_std; //!< default value for STP u decay (\tau_F) inhibitory (ms)
float def_STP_tau_x_inh_std; //!< default value for STP x decay (\tau_D) inhibitory (ms)

// all default values for homeostasis
float def_homeo_scale_; //!< default homeoScale
Expand Down Expand Up @@ -1890,12 +1906,12 @@ void CARLsim::setISTDP(int grpId, bool isSet, STDPType type, PulseCurve curve) {
}

// Sets STP params U, tau_u, and tau_x of a neuron group (pre-synaptically)
void CARLsim::setSTP(int grpId, bool isSet, float STP_U, float STP_tau_u, float STP_tau_x) {
_impl->setSTP(grpId, isSet, STP_U, STP_tau_u, STP_tau_x);
void CARLsim::setSTP(int preGrpId, int postGrpId, bool isSet, const STPu& STP_U, const STPtauU& STP_tau_u, const STPtauX& STP_tau_x) {
_impl->setSTP(preGrpId, postGrpId, isSet, STP_U, STP_tau_u, STP_tau_x);
}

// Sets STP params U, tau_u, and tau_x of a neuron group (pre-synaptically) using default values
void CARLsim::setSTP(int grpId, bool isSet) { _impl->setSTP(grpId, isSet); }
void CARLsim::setSTP(int preGrpId, int postGrpId, bool isSet) { _impl->setSTP(preGrpId, postGrpId, isSet); }

// Sets the weight and weight change update parameters
void CARLsim::setWeightAndWeightChangeUpdate(UpdateInterval wtANDwtChangeUpdateInterval, bool enableWtChangeDecay,
Expand Down
16 changes: 12 additions & 4 deletions carlsim/kernel/inc/snn.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include <cassert>
#include <cstdio>
#include <climits>
#include <limits>

#include <carlsim.h>
#include <callback_core.h>
Expand Down Expand Up @@ -363,12 +364,17 @@ class SNN {
* presynaptic terminal, after which (ii) a fraction u of available resources is consumed to produce the post-synaptic
* current. Between spikes, u decays back to zero with time constant STP_tau_u (\tau_F), and x recovers to value one
* with time constant STP_tau_x (\tau_D).
* \param[in] grpId pre-synaptic group id. STP will apply to all neurons of that group!
* \param[in] preGrpId pre-synaptic group id. STP will apply to all neurons of that group!
* \param[in] postGrpId post-synaptic group id. STP will apply to all neurons of that group!
* \param[in] isSet a flag whether to enable/disable STP
* \param[in] STP_tau_u decay constant of u (\tau_F)
* \param[in] STP_tau_x decay constant of x (\tau_D)
* \param[in] STP_U_mean mean of STP_U (\STP_U)
* \param[in] STP_U_std mean of STP_std (\STP_std)
* \param[in] STP_tau_u_mean mean of decay constant of u (\tau_F)
* \param[in] STP_tau_u_std sd of decay constant of u (\tau_F)
* \param[in] STP_tau_x_mean mean of decay constant of x (\tau_D)
* \param[in] STP_tau_x_std sd of decay constant of x (\tau_D)
*/
void setSTP(int grpId, bool isSet, float STP_U, float STP_tau_u, float STP_tau_x);
void setSTP(int preGrpId, int postGrpId, bool isSet, float STP_U_mean, float STP_U_std, float STP_tau_u_mean, float STP_tau_u_std, float STP_tau_x_mean, float STP_tau_x_std);

//! Sets the weight and weight change update parameters
/*!
Expand Down Expand Up @@ -683,6 +689,8 @@ class SNN {
void connectNetwork();
inline void connectNeurons(int netId, int srcGrp, int destGrp, int srcN, int destN, short int connId, int externalNetId);
inline void connectNeurons(int netId, int _grpSrc, int _grpDest, int _nSrc, int _nDest, short int _connId, float initWt, float maxWt, uint8_t delay, int externalNetId);
inline float generateNormalSample(float mean, float std, float min_limit, float max_limit);
inline double marsaglia_polar_gaussian_generator(const double& mean, const double &stdDev);
void connectFull(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
void connectOneToOne(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
void connectRandom(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
Expand Down
Loading