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 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions librandom/exp_randomdev.cpp
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
9 changes: 8 additions & 1 deletion librandom/exp_randomdev.h
Expand Up @@ -39,8 +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.
Copy link
Contributor

Choose a reason for hiding this comment

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

@luis-rr This line is longer than 79 characters, so it fails our code formatting checks. Could you fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just sent another commit.

Out of curiosity, how did you identify the error? I'm looking at Travis' log and all I can see is:
MSGBLD0220: C/C++ files with formatting errors:
MSGBLD0220: ... librandom/exp_randomdev.cpp
MSGBLD0220: ... librandom/exp_randomdev.h

But not the description of the formatting error itself.


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
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