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

Allow negative exponential distributions (fixes #835) #836

Merged
merged 4 commits into from
Feb 6, 2018
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
4 changes: 2 additions & 2 deletions librandom/exp_randomdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion librandom/exp_randomdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ 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.
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)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/unittests/test_rdv_param_setting.sli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down