Skip to main content

Provide function to calculate the modified Bessel function of the second kind

Project description

logbesselk

Provide function to calculate the modified Bessel function of the second kind and its derivatives.

Reference

Takashi Takekawa, Fast parallel calculation of modified Bessel function of the second kind and its derivatives, SoftwareX, 17, 100923, 2022.

Author

TAKEKAWA Takashi takekawa@tk2lab.org

For Tensorflow

Require

  • Python (>=3.8)
  • Tensorflow (>=2.6)

Installation

pip install tensorflow logbesselk

Examples

import tensorflow as tf
from logbesselk.tensorflow import log_bessel_k as logk
from logbesselk.jax import bessel_ke as ke
from logbesselk.jax import bessel_kratio as kratio

v = 1.0
x = 1.0
a = logk(v, x)

v = jnp.linspace(1, 10, 10)
x = jnp.linspace(1, 10, 10)
b = logk(v, x)

# gradient
with tf.GradientTape() as g:
    g.watch(v, x)
    f = logk(v, x)
dlogkdv = g.gradient(f, v)
dlogkdx = g.gradient(f, x)

# use tf.function
logk = tf.function(logk)

# advanced version
from logbesselk.tensorflow import log_abs_deriv_bessel_k

logk = lambda v, x: log_abs_deriv_bessel_k(v, x, 0, 0)
logdkdv = lambda v, x: log_abs_deriv_bessel_k(v, x, 1, 0)
logdkdx = lambda v, x: log_abs_deriv_bessel_k(v, x, 0, 1)

For jax

Require

  • Python (>=3.8)
  • jax (>=0.3)

Installation

pip install jax[cuda] -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
pip install logbesselk

Examples

import jax
import jax.numpy as jnp
from logbesselk.jax import log_bessel_k as logk
from logbesselk.jax import bessel_ke as ke
from logbesselk.jax import bessel_kratio as kratio

# scalar func and grad
v = 1.0
x = 1.0
a = logk(v, x)

# dlogK/dv = (dK/dv) / K
dlogkdv = jax.grad(logk, 0)
b = dlogkdv(v, x)

# dlogK/dx = (dK/dx) / K
dlogkdx = jax.grad(logk, 1)
c = dlogkdx(v, x)

# misc
d = ke(v, x)
e = kratio(v, x, d=1)

# vectorize
logk_vec = jax.vmap(logk)

v = jnp.linspace(1, 10, 10)
x = jnp.linspace(1, 10, 10)
f = logk_vec(v)

# use jit
logk_vec_jit = jax.jit(logk_vec)

# advanced version
from logbesselk.jax import log_abs_devel_bessel_k

log_dkdv = lambda v, x: log_abs_deriv_bessel_k(v, x, 1, 0)
log_dkdx = lambda v, x: log_abs_deriv_bessel_k(v, x, 0, 1)

log_dkdv_jit = jax.jit(jax.vmap(log_dkdv))
log_dkdx_jit = jax.jit(jax.vmap(log_dkdx))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logbesselk-3.2.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

logbesselk-3.2.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file logbesselk-3.2.0.tar.gz.

File metadata

  • Download URL: logbesselk-3.2.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.0-1031-azure

File hashes

Hashes for logbesselk-3.2.0.tar.gz
Algorithm Hash digest
SHA256 886b7eeb04dd906a5872400a1b0ab18cefb416a3b082f167e0d4033c8feb4313
MD5 709a77caf1f1f289ea2b08a96aeca5a7
BLAKE2b-256 46d75831e4c6cb595050d9c5d3899640b1fde37f525d6406bba43b44417c1498

See more details on using hashes here.

File details

Details for the file logbesselk-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: logbesselk-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.0-1031-azure

File hashes

Hashes for logbesselk-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffb58a6d8c738722666fa0522ad4583ec9f5862a7e0882df6fecc6df988468bc
MD5 f69670bcd12be1876e768bac8c0e04f7
BLAKE2b-256 671754e52092f3c9b07f7b5669c8b132521687a39d7e86640d709c6c351464f4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page