On 6/3/13 11:33 AM, Peter Li wrote:
> In src/stan/prob/distributions/univariate/continuous/rayleigh.hpp:
>
>> +        return cdf;
>> +      if (!check_positive(function, sigma, "Scale parameter",
>> +                          &cdf))
>> +        return cdf;
>> +      if (!(check_consistent_sizes(function,
>> +                                   y,sigma,
>> +                                   "Random variable","Scale parameter",
>> +                                   &cdf)))
>> +        return cdf;
>> +
>> +      VectorView<const T_y> y_vec(y);
>> +      VectorView<const T_scale> sigma_vec(sigma);
>> +      size_t N = max_size(y, sigma);
>> +
>> +      for (size_t n = 0; n < N; n++) {
>> +        cdf *= 1.0 - exp(-y_vec[n] * y_vec[n] / (2.0 * sigma_vec[n] * sigma_vec[n]));
>
> If we implement log CDFs do we still want to include CDFs? and for CCDFs, would we want log CCDFs?

Yes, we want _cdf_log and _ccdf_log.  I'm not sure we really need
the plain old CDFs at that point.  We only have the log probability
functions.  It's artithmetically much safer to exp() the log
versions than the other way around in terms of underflow.

You could always start by implementing the _cdf_log and _ccdf_log
in terms of the basic _cdf using log() and log1m().  Then you can
get the tests all working and then work through the derivatives,
which should be relatively easy given that it's just a log(p) or
1 - log(p) on the outside.

With

    d/dx log(F(x)) = 1/F(x) d/dx F(x)

we hope the d/dx F(x) cancels out at least some of the
terms in the 1/F(x).

> [I started to switch to OperandsAndPartials for the CDFs in Rayleigh, and that would require that I modify the
> test_fixture for distributions, so then all distributions would need to be modified appropriately.

Why would OperandsAndPartials affect testing?  It just seems like
a different implementation that should be encapsulated under the
tests.

- Bob