Repository navigation
Conversation
syclik
left a comment
There was a problem hiding this comment.
Lots of changes to be made. Will review again after it's been addressed.
| namespace stan { | ||
| namespace math { | ||
|
|
||
| template <typename T_n, typename T_rate> |
| VectorView<const T_rate> log_lambda_vec(log_lambda); | ||
| size_t size = max_size(n, log_lambda); | ||
|
|
||
| using std::log; |
There was a problem hiding this comment.
can you move this down to about line 58, where you use it?
|
|
||
| // Explicit return for extreme values | ||
| // The gradients are technically ill-defined, but treated as neg infinity | ||
| for (size_t i = 0; i < stan::length(n); i++) { |
There was a problem hiding this comment.
Is this the correct behavior? Shouldn't we check that n is non-negative?
There was a problem hiding this comment.
And shouldn't we be returning -inf instead of 0? (log(0) as opposed to log(1))
|
|
||
| const T_partials_return n_dbl = value_of(n_vec[i]); | ||
| const T_partials_return log_lambda_dbl = value_of(log_lambda_vec[i]); | ||
| const T_partials_return lambda_dbl = exp(log_lambda_dbl); |
There was a problem hiding this comment.
This should be computed outside the loop the number as its own VectorView. Here, log_lambda_vec could be much smaller than size.
| return operands_and_partials.value(negative_infinity()); | ||
|
|
||
| const T_partials_return n_dbl = value_of(n_vec[i]); | ||
| const T_partials_return log_lambda_dbl = value_of(log_lambda_vec[i]); |
There was a problem hiding this comment.
log_lambda_dbl isn't used anywhere else except to exp. So maybe this isn't the right variable to put into a vector view.
| check_values(count, log_rate); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Add additional tests for boundary conditions.
| EXPECT_FALSE(is_nan(gradients1[0])); | ||
| EXPECT_FALSE(is_nan(gradients2[0])); | ||
| EXPECT_NEAR(gradients1[0], gradients2[0] * rate_dbl, 0.01); | ||
| } |
There was a problem hiding this comment.
Add additional tests for boundary conditions.
| EXPECT_FALSE(is_nan(gradients1[0])); | ||
| EXPECT_FALSE(is_nan(gradients2[0])); | ||
| EXPECT_NEAR(gradients1[0], gradients2[0] * rate_dbl, 0.01); | ||
| } |
There was a problem hiding this comment.
Add additional tests for boundary conditions.
|
|
||
| EXPECT_FALSE(is_nan(gradients1[0])); | ||
| EXPECT_FALSE(is_nan(gradients2[0])); | ||
| EXPECT_NEAR(gradients1[0], gradients2[0] * rate_dbl, 0.01); |
| EXPECT_FALSE(is_nan(gradients1[0])); | ||
| EXPECT_FALSE(is_nan(gradients2[0])); | ||
| EXPECT_NEAR(gradients1[0], gradients2[0] * rate_dbl, 0.01); | ||
| } |
There was a problem hiding this comment.
Add additional tests for boundary conditions.
|
@syclik thanks for the review. just a quick update on this: I created a separate issue (#475) and will modernize a bunch of functions in prim/scal/prob per your comments, starting with poisson_cdf, etc. Very few of the existing functions have any doc, clean vectorization, following their pattern was a mistake. |
|
Any reason this PR was closed? |
|
oh just because I don't want to merge it, I'm going to rewrite poisson_cdf, etc, which are also not up to standards, and add these after, following their pattern. |
|
Ok. Thanks.
… On Dec 29, 2016, at 8:09 PM, thelseraphim ***@***.***> wrote:
oh just because I don't want to merge it, I'm going to rewrite poisson_cdf, etc, which are also not up to standards, and add these after, following their pattern.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Submisison Checklist
./runTests.py test/unitmake cpplintSummary:
adds
poisson_log_cdf,poisson_log_cdf_log, andpoisson_log_ccdf_logand adds tests for correct values and partial derivatives with respect to the log rate parameter. this is computed in the silly way you'd expect,poisson_log_cdf(n, t) = poisson_cdf(n, exp(t))and the derivatives get a corresponding correction from the chain rule applied to the second argument.resolves #90
Intended Effect:
How to Verify:
Besides running the six tests, it may be helpful to look at the adjacent files
poisson_cdf.hpp,poisson_cdf_log.hpp, andpoisson_ccdf_log.hppof which these files are a minor variation.Side Effects:
None, adds three functions to the math library.
Documentation:
Will follow up with a PR adding these to the stan language and add doc in the manual at that time
Reviewer Suggestions:
Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Columbia University
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: