From 85081d48f5d55a124dc553297507b20ee84bc0ba Mon Sep 17 00:00:00 2001 From: Luis Riquelme Date: Wed, 4 Oct 2017 10:45:42 +0200 Subject: [PATCH 1/4] allow negative exponential distributions Some models rely on the synaptic weight being negative in order to consider the synapse inhibitory. However the exponential distribution wasn't allowing a negative lambda value. With this change we can generate exponential distributions of inhibitory synaptic weights. Note that the implementation in librandom/exp_randomdev.h already works for negative lambda values. --- librandom/exp_randomdev.cpp | 4 ++-- testsuite/unittests/test_rdv_param_setting.sli | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/librandom/exp_randomdev.cpp b/librandom/exp_randomdev.cpp index 66a333f266..ba210c1de1 100644 --- a/librandom/exp_randomdev.cpp +++ b/librandom/exp_randomdev.cpp @@ -33,9 +33,9 @@ librandom::ExpRandomDev::set_status( const DictionaryDatum& d ) updateValue< double >( d, names::lambda, new_lambda ); - if ( new_lambda <= 0. ) + if ( new_lambda == 0. ) { - throw BadParameterValue( "Exponential RDV: lambda > 0 required." ); + throw BadParameterValue( "Exponential RDV: lambda != 0 required." ); } lambda_ = new_lambda; diff --git a/testsuite/unittests/test_rdv_param_setting.sli b/testsuite/unittests/test_rdv_param_setting.sli index 548c9b242e..8d1900c4bb 100644 --- a/testsuite/unittests/test_rdv_param_setting.sli +++ b/testsuite/unittests/test_rdv_param_setting.sli @@ -109,7 +109,7 @@ FirstVersion: 20140402 { /MT19937 /exponential << /lambda -1. >> run_test -} fail_or_die +} assert_or_die { /MT19937 /exponential_clipped << /min 0. /max -1. >> run_test From f8b76d3264890834a01917642bca3d89412a04f0 Mon Sep 17 00:00:00 2001 From: Luis Riquelme Date: Fri, 6 Oct 2017 14:16:39 +0200 Subject: [PATCH 2/4] update documentation for exp dist --- librandom/exp_randomdev.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/librandom/exp_randomdev.h b/librandom/exp_randomdev.h index 22289a7a16..500052c62e 100644 --- a/librandom/exp_randomdev.h +++ b/librandom/exp_randomdev.h @@ -40,7 +40,9 @@ namespace librandom Name: rdevdict::exponential - exponential random deviate generator Description: Generates exponentially distributed random numbers. - p(x) = lambda exp(-lambda*x), x >= 0. + p(x) = lambda exp(-lambda*x), x >= 0 if lambda > 0 + p(x) = -lambda exp(-lambda*x), x <= 0 if lambda < 0 + Parameters: lambda - rate parameter (default: 1.0) From 98bbf9a6d91cab85cb5ffe3ad39f56e67f5b69fe Mon Sep 17 00:00:00 2001 From: Luis Riquelme Date: Mon, 23 Oct 2017 13:56:48 +0200 Subject: [PATCH 3/4] clarify that negative lambda is ok in exp dist doc --- librandom/exp_randomdev.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/librandom/exp_randomdev.h b/librandom/exp_randomdev.h index 500052c62e..293049d0ca 100644 --- a/librandom/exp_randomdev.h +++ b/librandom/exp_randomdev.h @@ -39,10 +39,15 @@ namespace librandom /*BeginDocumentation Name: rdevdict::exponential - exponential random deviate generator Description: Generates exponentially distributed random numbers. +Negative values of lambda are allowed and generate a distribution of negative numbers. - p(x) = lambda exp(-lambda*x), x >= 0 if lambda > 0 - p(x) = -lambda exp(-lambda*x), x <= 0 if lambda < 0 +For lambda > 0: + p(x) = lambda exp(-lambda*x), for x >= 0 + p(x) = 0, for x < 0 +For lambda < 0: + p(x) = 0, for x > 0 + p(x) = |lambda| exp ( -|lambda| |x| ), for x <= 0 Parameters: lambda - rate parameter (default: 1.0) From 72007ff6684e3e2e569cc9e7bc01277524117021 Mon Sep 17 00:00:00 2001 From: Luis Riquelme Date: Wed, 25 Oct 2017 09:29:09 +0200 Subject: [PATCH 4/4] wrap long line --- librandom/exp_randomdev.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/librandom/exp_randomdev.h b/librandom/exp_randomdev.h index 293049d0ca..6edb2d76f6 100644 --- a/librandom/exp_randomdev.h +++ b/librandom/exp_randomdev.h @@ -39,7 +39,8 @@ namespace librandom /*BeginDocumentation Name: rdevdict::exponential - exponential random deviate generator Description: Generates exponentially distributed random numbers. -Negative values of lambda are allowed and generate a distribution of negative numbers. +Negative values of lambda are allowed and generate a distribution +of negative numbers. For lambda > 0: p(x) = lambda exp(-lambda*x), for x >= 0