Add wiener distribution

Code from by Joachim Vandekerckhove http://www.cidlab.com/supp.php?o=wienerstan, which was created for stan v1.3; tweaked by Mike Lawrence to (hopefully) work for 2.1.0.
It's possible to tear models apart and put them back together
in such a way that the gradients are still right.  I'd look
at testing with finite diffs no matter what happens.

- Bob

On Jul 10, 2014, at 11:26 AM, Marco Inacio <notifications@github.com> wrote:

> In src/stan/prob/distributions/univariate/continuous/wiener.hpp:
> 
> > +      }
> > +      else // if error threshold set too high
> > +        kl = 1.0 / (MY_PI * sqrt(x)); // set to boundary condition
> > +
> > +      // calculate number of terms needed for small t
> > +      if ((2.0 * sqrt(2.0 * MY_PI * x) * WIENER_ERR) < 1) { // if error threshold is set low enough
> > +        ks = 2.0 + sqrt(-2.0 * x * log(2.0 * sqrt(2.0 * MY_PI * x) * WIENER_ERR)); // bound
> > +        ks = (ks > sqrt(x) + 1.0) ? ks : sqrt(x) + 1.0; // ensure boundary conditions are met
> > +      }
> > +      else // if error threshold was set too high
> > +        ks = 2.0; // minimal kappa for that case
> > +
> > +      // compute density: f(tt|0,1,w)
> > +      if (ks < kl) { // if small t is better (i.e., lambda<0)
> > +        K = ceil(ks); // round to smallest integer meeting error
> > +        for (k = -floor((K - 1.0) / 2.0); k <= ceil((K - 1.0) / 2.0); k++)
> 
> No, I haven't tried finite diff tests yet because I came across the problem above (of line 89). This one here was more a theoretical concern (about discontinuous gradients).
> 
> In fact, I was hopping the code was ok [and didn't check it] when I started writing the tests, but it seems now that it isn't and I might not know enough about Wiener process to fix it.
> 
> —
> Reply to this email directly or view it on GitHub.
>