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

# return tensor
log_k = log_bessel_k(v=1.0, x=1.0)
log_dkdv = log_bessel_k(v=1.0, x=1.0, m=1, n=0)
log_dkdx = log_bessel_k(v=1.0, x=1.0, m=0, n=1)

# build graph at first execution time
log_bessel_k_tensor = tf.function(log_bessel_k)
log_bessel_dkdv_tensor = tf.function(lambda v, x: log_bessel_k(v, x, 1, 0))
log_bessel_dkdx_tensor = tf.function(lambda v, x: log_bessel_k(v, x, 0, 1))

n = 1000
for i in range(10):
    v = 10. ** (2. * tf.random.uniform((n,)) - 1.)
    x = 10. ** (3. * tf.random.uniform((n,)) - 1.)

    log_k = log_bessel_k_tensor(v, x)
    log_dkdv = log_bessel_dkdv_tensor(v, x)
    log_dkdx = log_bessel_dkdx_tensor(v, x)

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
from logbesselk.jax import log_bessel_k

# return jnp.array
log_k = log_bessel_k(v=1.0, x=1.0)
log_dkdv = log_bessel_k(v=1.0, x=1.0, m=1, n=0)
log_dkdx = log_bessel_k(v=1.0, x=1.0, m=0, n=1)

# build graph at first execution time
log_bessel_k_jit = jax.jit(jax.vmap(log_bessel_k))
log_bessel_dkdv_jit = jax.jit(jax.vmap(lambda v, x: log_bessel_k(v, x, 1, 0)))
log_bessel_dkdx_jit = jax.jit(jax.vmap(lambda v, x: log_bessel_k(v, x, 0, 1)))

trial = 10
n = 1000
for i in range(trial):
    v = 10. ** jax.random.uniform(i, (n,), minval=-1., maxval=1.)
    x = 10. ** jax.random.uniform(i, (n,), minval=-1., maxval=2.)

    log_k = log_bessel_k_tensor(v, x)
    log_dkdv = log_bessel_dkdv_tensor(v, x)
    log_dkdx = log_bessel_dkdx_tensor(v, x)

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.0.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

logbesselk-3.0.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for logbesselk-3.0.0.tar.gz
Algorithm Hash digest
SHA256 488010afb77d675b6ca5c3928c82b7c096df3488a3499a4779cc26d36ff573e5
MD5 242a076122caf82de397fc4a32a56c45
BLAKE2b-256 20ce0083c2eff116a97019fc7a6a5285ad69ebaa7f1eba667d0c212394213201

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for logbesselk-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8eca33b001562ae98faedffdcee5ca18f17b4f2f507ca48fbc05e4938fb8c70f
MD5 26108a6abba052e1b97c73b15eff4277
BLAKE2b-256 9292a31c5d65d05324713a8e40cd05bb10a01cc7c4e4c80086a144b83cafa996

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