Skip to content

Feature/issue 90 poisson logcdf - #471

Closed
ghost wants to merge 4 commits into
developfrom
feature/issue-90-poisson-logcdf
Closed

ghost wants to merge 4 commits into
developfrom
feature/issue-90-poisson-logcdf

Conversation

@ghost

@ghost ghost commented Dec 27, 2016

Copy link
Copy Markdown

Submisison Checklist

  • Run unit tests: ./runTests.py test/unit
  • Run cpplint: make cpplint
  • Declare copyright holder and open-source license: see below

Summary:

adds poisson_log_cdf, poisson_log_cdf_log, and poisson_log_ccdf_log and 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, and poisson_ccdf_log.hpp of 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:

@syclik syclik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs doxygen doc.

VectorView<const T_rate> log_lambda_vec(log_lambda);
size_t size = max_size(n, log_lambda);

using std::log;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the correct behavior? Shouldn't we check that n is non-negative?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use EXPECT_FLOAT_EQ

EXPECT_FALSE(is_nan(gradients1[0]));
EXPECT_FALSE(is_nan(gradients2[0]));
EXPECT_NEAR(gradients1[0], gradients2[0] * rate_dbl, 0.01);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add additional tests for boundary conditions.

@ghost

ghost commented Dec 30, 2016

Copy link
Copy Markdown
Author

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

@ghost ghost closed this Dec 30, 2016
@syclik

syclik commented Dec 30, 2016

Copy link
Copy Markdown
Member

Any reason this PR was closed?

@ghost

ghost commented Dec 30, 2016

Copy link
Copy Markdown
Author

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.

@syclik

syclik commented Dec 30, 2016 via email

Copy link
Copy Markdown
Member

@syclik
syclik deleted the feature/issue-90-poisson-logcdf branch September 15, 2022 14:13
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

poisson_log cdfs

1 participant