-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Add probability tests to check vectorized/scalar lpmfs/lpdfs are the same #1989
Changes from all commits
d6c5225
bd2ebc1
ea07b9e
0aa88c1
fdc7757
5db698a
35b74c4
6ebcaad
0ef320e
778280f
95b4288
a631664
f2d7504
a080c63
84310eb
3f2c5ea
69045e7
acb7a3f
9304cf9
79231ca
e68772a
70de131
e84ff0a
8e4886c
791d99c
bd880ee
e0277ca
f934306
1fe965c
603dc28
5732b5e
025c88a
f3eca66
4b3546f
b5e234d
251b9a7
4238841
f62e5b4
5e1a87b
12f59b7
f610349
b47308f
3c95343
afcf788
ff8d6ce
dfd1079
55d5c8a
dcb7216
52087d6
9fe249f
4f27b6f
dbdca40
fe5c9fd
f98703e
5bbea21
dde875c
6fdf624
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ return_type_t<T_y, T_shape, T_scale> frechet_lpdf(const T_y& y, | |
T_partials_return, T_y> | ||
inv_y(size(y)); | ||
for (size_t i = 0; i < stan::math::size(y); i++) { | ||
inv_y[i] = 1.0 / value_of(y_vec[i]); | ||
inv_y[i] = inv(value_of(y_vec[i])); | ||
} | ||
|
||
VectorBuilder<include_summand<propto, T_y, T_shape, T_scale>::value, | ||
|
@@ -107,10 +107,9 @@ return_type_t<T_y, T_shape, T_scale> frechet_lpdf(const T_y& y, | |
logp -= sigma_div_y_pow_alpha[n]; | ||
|
||
if (!is_constant_all<T_y>::value) { | ||
const T_partials_return inv_y_dbl = value_of(inv_y[n]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem here was this second value_of (inv_y has already had one value_of). |
||
ops_partials.edge1_.partials_[n] | ||
+= -(alpha_dbl + 1.0) * inv_y_dbl | ||
+ alpha_dbl * sigma_div_y_pow_alpha[n] * inv_y_dbl; | ||
+= -(alpha_dbl + 1.0) * inv_y[n] | ||
+ alpha_dbl * sigma_div_y_pow_alpha[n] * inv_y[n]; | ||
} | ||
if (!is_constant_all<T_shape>::value) { | ||
ops_partials.edge2_.partials_[n] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,10 +52,10 @@ class AgradCdfBinomial : public AgradCdfTest { | |
using std::exp; | ||
using std::log; | ||
|
||
stan::return_type_t<T_prob> cdf(1); | ||
stan::return_type_t<T_prob> cdf(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is the same as the log cdf code without the log: https://github.com/stan-dev/math/blob/develop/test/prob/binomial/binomial_cdf_log_test.hpp |
||
|
||
for (int i = 0; i <= n; i++) { | ||
cdf *= binomial_coefficient<double>(N, i) | ||
cdf += binomial_coefficient<double>(N, i) | ||
* exp(i * log(theta) + (N - i) * log(1 - theta)); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,10 @@ class AgradDistributionsExponential : public AgradDistributionTest { | |
parameters.push_back(param); | ||
log_prob.push_back(-57.13902344686439249699); // expected log_prob | ||
|
||
param[0] = 1e-08; | ||
param[0] = 1e-2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test point needs to be far enough away from zero so that the finite difference checks don't go out of range. |
||
param[1] = 3.9; | ||
parameters.push_back(param); | ||
log_prob.push_back(1.3609765141356007); | ||
log_prob.push_back(1.3219765531356007); | ||
} | ||
|
||
void invalid_values(vector<size_t>& index, vector<double>& value) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,11 @@ class AgradCcdfLogGamma : public AgradCcdfLogTest { | |
ccdf_log.push_back( | ||
std::log(1.0 - 0.6321205588285576659757)); // expected ccdf_log | ||
|
||
param[0] = 16.0; // y | ||
param[1] = 3.0; // alpha | ||
param[2] = 3.0; // beta | ||
param[0] = 9.0; // y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made the test case easier because the test implementations were struggling numerically. See: #2006 The Stan implementations of the ccdf didn't seem to have this problem. |
||
param[1] = 1.2; // alpha | ||
param[2] = 1.2; // beta | ||
parameters.push_back(param); | ||
ccdf_log.push_back(std::log(1.7116220633718619e-18)); // expected ccdf_log | ||
ccdf_log.push_back(-10.221534317077268); // expected ccdf_log | ||
} | ||
|
||
void invalid_values(vector<size_t>& index, vector<double>& value) { | ||
|
@@ -90,10 +90,10 @@ class AgradCcdfLogGamma : public AgradCcdfLogTest { | |
stan::return_type_t<T_y, T_shape, T_inv_scale> ccdf_log_function( | ||
const T_y& y, const T_shape& alpha, const T_inv_scale& beta, const T3&, | ||
const T4&, const T5&) { | ||
using boost::math::gamma_q; | ||
using stan::math::gamma_q; | ||
using std::log; | ||
using boost::math::gamma_p; | ||
using stan::math::gamma_p; | ||
using stan::math::log1m; | ||
|
||
return log(gamma_q(alpha, beta * y)); | ||
return log1m(gamma_p(alpha, beta * y)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing log1m(cdf) worked better than log(ccdf) for forward mode. Check here for the lcdf: https://github.com/stan-dev/math/blob/develop/test/prob/gamma/gamma_cdf_log_test.hpp#L84 |
||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,6 @@ class AgradDistributionGumbel : public AgradDistributionTest { | |
stan::return_type_t<T_y, T_loc, T_scale> log_prob_function( | ||
const T_y& y, const T_loc& mu, const T_scale& beta, const T3&, const T4&, | ||
const T5&) { | ||
return -log(beta) - (y - mu) / beta + exp((mu - y) / beta); | ||
return -log(beta) - (y - mu) / beta - exp((mu - y) / beta); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gumbel pdf here: https://en.wikipedia.org/wiki/Gumbel_distribution |
||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,6 @@ class AgradCcdfLogInvChiSquare : public AgradCcdfLogTest { | |
const T5&) { | ||
using stan::math::gamma_p; | ||
|
||
return log(1.0 - gamma_p(0.5 * nu, 0.5 / y)); | ||
return log(gamma_p(0.5 * nu, 0.5 / y)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the math version: https://github.com/stan-dev/math/blob/develop/stan/math/prim/prob/inv_chi_square_lccdf.hpp#L92 (this is checked with finite differences so I assume it's the correct one) |
||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies but for the discrete range changes you're just gonna have to check me (by this I mean check I'm doing the bounds correctly).
This if goes inside this loop because y_dbl > upper_vec multiplies the cdf by 1.0 (the vectorized cdfs are the products of all the constituent cdfs).
If the if statement stays outside, then this function erroneously returns 1 if any single cdf term should be one.