Aki
I'm not wedded to the vertical bar. Everyone seemed to think
it was a good idea in the Stan meeting.
normal_ldcdf?
(it's log of differences and not diff of logs)
> > Also if optional arguments are allowed as normal_lpdf<norm=true>, why not then have also link functions as optional arguments, e.g.,
> > bernoulli_lpdf<link=probit> or bernoulli_lpdf<link=logit> or bernoulli_lpdf<link=linear> ?
>
> We could. I don't want to get carried away and in particular don't
> want expressions as values of those = things --- just template
> parameters that resolve which function is called.
One reason for this would be to avoid confusion of what _log in the end of function stands for (log of density or log link).
Aki
I didn't agree as _ld is not consistent with _cdf and _ccdf, unless they are changed to _cd and _ccd?
Aki
I'm fine with ld << ...;
If we want stats paper look, e.g.
ld << cauchy(tau | 0, 2.5),
normal(beta | 0, 2),
bernoulli_logit(y | x * (tau * beta));
then here << is better than +=, because += would imply summing distributions (not log densities). So the corresponding version with += would look like
ld += cauchy_lpdf(tau | 0, 2.5),
normal_lpdf(beta | 0, 2),
bernoulli_logit_lpdf(y | x * (tau * beta));
this latter form is more explicit and it migh be more natural if other than built-in distributions are used, e.g.
ld += normal_lpdf(y | mu, sigma) -log(sigma)
but maybe we could use << as
ld << normal(y | mu, sigma), 1/sigma
so that _lpdf's will be used if they are available and otherwise log of the expression is used. Yes, there is possibility of confusion by using both << and +=, but it would give possiblity for both stat paper look and more explicit log density construction.
Aki
Thanks for staying on top of doing the summaries Bob, at the moment it's the
only way I keep this discussion straight.
>
> * densities need some suffix
>
> * it should not be "_log"
>
> * log-scale should be explicitly indicated
>
> I don't think there's a consensus on what the suffixes should
> be, but Aki's right that we should look at the whole family.
> I think his proposal makes a lot of sense:
>
> pdf / cdf / ccdf / dcdf
> lpdf / lcdf / lccdf / ldcdf
>
> I somehow think the "f" is redundant --- I assume we can at
> least assume our users know what a function is --- but then it's in
> common usage.
>
> Is everyone OK with that? And with using "pdf" for both density
> and mass functions? (Yes, they're all densities with the right
> math, however the textbooks say "pmf").
>
> What I don't think there's consensus on is
>
> * using a vertical bar, as in:
>
> normal_lpdf(y | mu, sigma)
>
> Also, I don't think there's consensus on the whole "<<" business,
> as in:
>
> ld << ...; // Michael
> << ...; // Aki
> ld += ...; // Krzysztof
My though was more specific---I think we should stick to the more common operators:
ld += A + B + C;
where A/B/C can be any function that evaluates to something compatible with the ld accumulator. It lets us use a construct that appears in multiple other programming languages and avoids introducing a comma addition. I think the comma is really too clever.
>
> Krzysztof thinks the vertical bar and << will confuse non-programmers.
I think I figured out from Michael's comments that the bar is adding a piece of information about the function not available anywhere else (except the manual). I still don't understand if users are making a modeling mistake that this distinction helps to resolve but I'm ok with not knowing that.
> And should that "ld" match "pdf" or vice-versa?
>
> I think some people are thinking we might add other accumulators like
> lprior or llikelihood (there's that pesky "l" for "log" again), or
> maybe "lbase" and "ldelta".
> - Bob
Here I meant to have plus instead of comma if += is used, ie
ld += cauchy_lpdf(tau | 0, 2.5) +
normal_lpdf(beta | 0, 2) +
bernoulli_logit_lpdf(y | x * (tau * beta));
Aki
Constraints do automated processing, too :)
How about having
normal
to be alias for
normal_lpdf
?
Or do we want to strictly use _lpdf even if it makes the code look less like stat papers?
Aki
Nice.
On Monday, January 4, 2016 at 9:28:17 AM UTC+2, Bob Carpenter wrote:
> everyone's going to expect normal(y | mu, sigma)
> to be on the linear scale because that's the convention.
The usual convention is also to return normalised density, but Stan returns unnormalised, which may add confusion (and has caused confusion as seen sometimes in Stan users list).
> cauchy_lpdf<norm=true>(y | mu, tau); // normalized
> cauchy_lpdf<norm=false>(y | mu, tau); // unnormalized
> cauchy_lpdf(y | mu, tau); // unnormalized
I just had an idea that maybe we could use BDA notation, ie, q for unnormalised density
cauchy_lpdf(y | mu, tau); // normalized
cauchy_lqdf(y | mu, tau); // unnormalized
And if we want less letters in all functions, we could use
_p, _lp, _q, _lq, _c, _lc, _cc, _lcc, _dc, _ldc, _r
and then we would have
cauchy_lp(y | mu, tau); // log, normalized
cauchy_lq(y | mu, tau); // log, unnormalized
or if we want to emphasize
cauchy_l_p(y | mu, tau); // log, normalized
cauchy_l_q(y | mu, tau); // log, unnormalized
I think these forms with df dropped, look nice with |
Aki
Aki
Please, tell more!
How about cdf, ccdf, dcdf and icdf? Would these functions work only on log scale, too? Currently normal_cdf is not on log scale, so the same suffix can't be used for log by default. Suffix _lcdf? Something else?
How about normalisation? Off by default? How about vector output (not summing) useful, e.g., for LOO (and waic)?
If
ld << normal(y|mu,sigma)
returns unnormalised summed log pdf, would you go for
log_lik <- normal<norm=true,vector=true>(y|mu,sigma)
to get normalised log pdfs in a vector?
Aki
normal_inv_cdf(y ??? mu, sigma) : log inverse cdf
normal_inv_cdf(p | mu, sigma);
As to inverse CDFs, you're right that it doesn't make sense to have log
output. But what about logit input? Or do we have complementary inverse
cdfs to deal with the overflow to 1 problem on the 1 side of (0,1)?
Won't that depend on how we write the code? I don't know anything
about this case, but I don't see any obstacle in principle to using
probabilities near 0 or 1 in inverse CDFs as long as the output doesn't
overflow or underflow.
Anyway, we can put off CDFs for the time being because we don't have any
implemented or any path to implement them until someone has some time
and energy for it.
What I’d like is for “normal” to be the abbreviation for “normal_log_pdf”.
OK, we can discuss again. I see where you’re coming from. I guess it’s fine if normal(a | b, c) is the log density, then we’d also have normal_log_cdf(a | b, c) and normal_cdf(a | b, c). That works. And if anyone wants to compute the normal pdf (for example, if they’re defining a mixture model), they’d just have to bite the bullet and do exp(normal(a | b, c)).
Is that ok?
OK, we can discuss again. I see where you’re coming from. I guess it’s fine if normal(a | b, c) is the log density, then we’d also have normal_log_cdf(a | b, c) and normal_cdf(a | b, c). That works. And if anyone wants to compute the normal pdf (for example, if they’re defining a mixture model), they’d just have to bite the bullet and do exp(normal(a | b, c)).
Is that ok?
Right now, my opinion is that all our distribution functions should be on the log scale. This includes:- probability distribution / mass function- cumulative distribution function- inverse cumulative distribution function
Ben
Actually I was proposing something slightly different:normal(a | b, c) should be in R: dnorm(a, b, c, log = TRUE)
normal_cdf(a | b, c) should be in R: pnorm(a, b, c, log=FALSE)
normal_log_cdf(a | b, c) should be in R: pnorm(a, b, c, log=TRUE)But your plan could work too. I’d like to avoid the _pdf or _lpdf suffix in any case because that would clutter the model. To me, the #1 thing is getting the commonly-used distributions in a clean format, then we worry about things like cdfs being logical.
As I was saying at meeting on Tues, the main Bayes formula is p(theta | y) propto p(theta) p(y | theta).But now I’d like to write it as lp(theta | y) = const + lp(theta) + lp(y | theta).