Skip to main content

Fast evaluation of SMC' likelihood for population genetic data

Project description

phlashlib

This library computes the log-likelihood of binary heterozygosity sequences under a sequentially Markov coalescent model with recombination.

API

phlashlib.loglik(
    data: Int[ArrayLike, "L"],
    iicr: IICRCurve,
    times: Float[ArrayLike, "T"],
    theta: ScalarLike,
    rho: ScalarLike,
    warmup: int = 500,
    chunk_size: int = None,
) -> Scalar

Features

  • JAX-compatible: vmap, jit, grad, etc.
  • GPU-accelerated via cuda.core.experimental (fallback to CPU if unavailable)

Example

from phlashlib.iicr import PiecewiseConstant
from phlashlib.loglik import loglik
import jax.numpy as jnp

times = jnp.array([0.0, 0.1, 0.5, 2.0])
rates = jnp.array([100.0, 10.0, 1.0])
iicr = PiecewiseConstant(t=times[:-1], c=rates)

data = jnp.array([0, 1, 1, 0, -1, 1, 0, 0], dtype=jnp.int8)
theta = 1.5
rho = 0.5

ll = loglik(data, iicr, times, theta, rho)

JAX Use

from jax import jit, vmap, grad

# JIT
f = jit(loglik)

# Vectorized over data
batched_ll = vmap(loglik, in_axes=(0, None, None, None, None))(batch_data, iicr, times, theta, rho)

# Gradient w.r.t. theta
dtheta = grad(loglik, argnums=3)(data, iicr, times, theta, rho)

Notes

  • data: 1D int8, values in {0, 1, -1}
  • iicr: subclass of IICRCurve, e.g. PiecewiseConstant
  • theta, rho: scalar mutation and recombination rates
  • Internally uses a fused CUDA kernel with jax.custom_vjp if available
  • Fallback implementation uses pure JAX

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

phlashlib-0.1.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phlashlib-0.1.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file phlashlib-0.1.1.tar.gz.

File metadata

  • Download URL: phlashlib-0.1.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for phlashlib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8839fd4a53d390143518b02c5437fb2332290e8f4ade5bd0112e07ccfbcd38ce
MD5 616d01b9211c945ac1540aecef48c485
BLAKE2b-256 08728a28526bc39eacc94ef4622ab7818cf79ca8deec519627126bbeb8519d2c

See more details on using hashes here.

File details

Details for the file phlashlib-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: phlashlib-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for phlashlib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6e10c6f4bcc6a48eb4f405c1e4a6e62704a2c49bf50cd612f137145eca87618
MD5 5c8967185b523ae167c6d8828169a1d1
BLAKE2b-256 b78cf30e508bc1210aefdf48bfc2cebf989183f44fd844e9a2b9db3a20a6332a

See more details on using hashes here.

Supported by

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