stan-dev / math

The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
742 stars 186 forks source link

BesselK continuous function #1112

Open stemangiola opened 5 years ago

stemangiola commented 5 years ago

Description

In order to build robust count models based for example on SICHEL distribution, a continuous version of the BesselK function is needed (nu being real instead of int).

There is a tread here https://discourse.mc-stan.org/t/besselk-with-the-order-v-as-real-parameter/7417/4 but I thought to lounch a feature request since is quite a delicate math function (that is not working natively in log scale in the R version and therefore unstable)

For feature requests:

The code is present in R

https://stat.ethz.ch/R-manual/R-devel/library/base/html/Bessel.html

Expected Output

count ~ sichel(mu, sigma, nu)

Current Version:

v2.18.1

martinmodrak commented 5 years ago

A related issues in stan: https://github.com/stan-dev/stan/issues/1939

zottelef commented 5 years ago

Could this be useful to build a Matérn covariance function for the Gaussian Processes?

martinmodrak commented 4 years ago

For anyone wondering here: the PR is closed, but I am making slow progress now and then and have code that works for many contexts. If you need this function, let me know, I might try to increase the priority of resolving it completely :-)

spinkney commented 2 years ago

With the introduction of hypergeometric pFq I believe we can use that to calculate the derivative of the modified bessel function of the second kind when $\nu \notin \mathbb{Z}$. From https://functions.wolfram.com/Bessel-TypeFunctions/BesselK/20/01/01/0002/

Screen Shot 2022-07-18 at 5 39 47 PM