Skip to content
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

Signature of [Modified] Bessel Functions [of the Second Kind] #23

Closed
syclik opened this issue Jul 6, 2015 · 7 comments
Closed

Signature of [Modified] Bessel Functions [of the Second Kind] #23

syclik opened this issue Jul 6, 2015 · 7 comments
Assignees
Labels
Milestone

Comments

@syclik
Copy link
Member

syclik commented Jul 6, 2015

From @ecbrown on September 22, 2013 18:32

I am trying to implement a Matern Covariance function, which depends on K_v. I believe that v may take on non-integer values, e.g v=1/2 is quite significant from a theoretical standpoint.

However, when I supply both arguments as real (nu is a real<lower=0.5> parameter):

Sigma[i,j] <- sigmasq * 1.0/(tgamma(nu)*pow(2.0,nu-1.0) *
pow(sqrt(2.0*nu)*D[i,j]/phi,nu) * modified_bessel_second_kind(nu,
sqrt(2.0*nu)*D[i,j]/phi);

I get a compilation error:

DIAGNOSTIC(S) FROM PARSER:
no matches for function name="modified_bessel_second_kind"
   arg 0 type=real
   arg 1 type=real
available function signatures for modified_bessel_second_kind:
0.  modified_bessel_second_kind(int, real) : real

which seems to make me think that K_v only takes integer v.

Is it possible to make it take two real arguments?

Copied from original issue: stan-dev/stan#231

@syclik
Copy link
Member Author

syclik commented Jul 6, 2015

From @bob-carpenter on September 22, 2013 19:47

See the previous discussion in issue #96 about implementing the Bessel functions. I think the only thing holding us up might be derivatives for the functions, because the Boost functions are general enough:

http://www.boost.org/doc/libs/1_54_0/libs/math/doc/html/math_toolkit/bessel/mbessel.html

Do you need parameters in that argument or just a real (double) constant? As is, Stan's language doesn't distinguish between the two, which means every function must be differentialble with respect to its real arguments.

One thing we might consider is allowing functions that take real constants/data only. Simplest would be to throw run-time errors, but we could make it compile time by refining the function signatures and adding some expression tests in the abstract syntax tree code.

@syclik
Copy link
Member Author

syclik commented Jul 6, 2015

From @ecbrown on September 22, 2013 19:56

In order to implement full kriging with the Matern covariance, I would need to have both v and z as real parameters.

It seems like Mathematica can take the symbolic derivative of K_v(z) with respect to z, but it bounces back for the derivative w.r.t. v. :-(

@syclik
Copy link
Member Author

syclik commented Jul 6, 2015

From @ecbrown on September 22, 2013 20:24

http://dlmf.nist.gov/10.38 gives me some hope for an evaluation of analytic derivative w.r.t. real-valued order in an implementable form. I think this would require the regularized generalized hypergeometric function to be available.

(This is 10 steps beyond my mathematical comfort zone)

@syclik
Copy link
Member Author

syclik commented Jul 6, 2015

From @bob-carpenter on September 22, 2013 20:36

They look too tricky for Boost, so I doubt we'll be
able to build them in Stan:

https://groups.google.com/forum/#!msg/boost-list/wOjuIYQuqkM/0l5zogA9e0YJ

The above thread indicates that GSL has them, but we don't want
to depend on GPL-ed code and the thread above indicates they're
rather touchy.

  • Bob

On 9/22/13 4:24 PM, Eric Brown wrote:

http://dlmf.nist.gov/10.38 gives me some hope for an evaluation of analytic derivative w.r.t. real-valued order in an
implementable form. I think this would require the regularized generalized hypergeometric function to be available.

(This is 10 steps beyond my mathematical comfort zone)


Reply to this email directly or view it on GitHub stan-dev/stan#231 (comment).

@bgoodri
Copy link
Contributor

bgoodri commented Mar 4, 2016

There is a user-defined function on stan-users for modified Bessel functions with real nu
https://groups.google.com/d/msg/stan-users/sW61HeIT24I/ZH-WuMCSBgAJ
I don't think anyone is planning on putting this into Stan Math.

@bgoodri bgoodri closed this as completed Mar 4, 2016
@bob-carpenter
Copy link
Contributor

Not until someone can work out a good algorithm for the derivatives.

@avehtari
Copy link

avehtari commented Mar 5, 2016

Matern with half-integer v = p+1/2 does not need Bessel. In this case the covariance function is a product
of an exponential and a polynomial of order p. See, e.g., Ch 4, p. 85 in GPML http://www.gaussianprocess.org/gpml/chapters/

@syclik syclik modified the milestone: v2.11.0 Jul 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants