A library providing implementations of various risk metrics for risk-aware trajectory planning.
Project description
RisKit: Risk Metrics for Risk-Aware Planning
RisKit provides implementations of common risk metrics used in risk-aware trajectory planning, intended for researchers who need reliable risk quantification under uncertainty.
The library provides the following metrics:
- Expected Value,
- Mean-Variance,
- Value at Risk (VaR),
- Conditional Value at Risk (CVaR), and
- Entropic Risk metrics,
with built-in support for both NumPy and JAX backends (can easily be extended to other backends, e.g. PyTorch). The API is type-safe, but offers automatic backend inference based on the type annotations of the cost function (uncertain variable transform).
RisKit is being actively developed. Some features may be missing and some of the API might change. You can help by reporting issues or contributing fixes and features.
Installation
Python 3.13+ is required.
pip install riskit
Quick Start
import numpy as np
from numtypes import array, Dim2
from riskit import (
risk, distribution,
NumPyInputAndState, NumPyUncertaintySamples, NumPyCosts,
)
# A cost function takes typed trajectories and uncertainty samples,
# and returns a costs array of shape (T, M, N). You're free to use
# any type you want though, as long as it supports the necessary operations.
def distance_cost(
*,
trajectories: NumPyInputAndState,
uncertainties: NumPyUncertaintySamples[Dim2],
) -> NumPyCosts:
x = trajectories.x # (T, D_x, M)
xi = uncertainties # (V, D, N)
T, _, M = x.shape
_, _, N = xi.shape
return np.tile((x[:, 0, :, None] - xi[0, 0, None, :]) ** 2, (1, 1, 1)).reshape(T, M, N)
# The factory infers the NumPy backend from the cost function's return type.
metric = risk.cvar_of(distance_cost, alpha=0.1)
# Create an uncertainty distribution.
uncertainties = distribution.numpy.gaussian(
mean=array([[0.0]], shape=(1, 1)),
covariance=array([[[1.0]]], shape=(1, 1, 1)),
seed=42,
)
# Compute risk over trajectories and uncertainty samples.
results = metric.compute(trajectories=..., uncertainties=uncertainties)
If the cost function in your case works with JAX and returns a JAX array, you can just use the appropriate type annotation and the JAX backend will be automatically inferred.
Risk Metrics
| Metric | Factory | Description |
|---|---|---|
| Expected Value | risk.expected_value_of(f) |
Mean cost across samples |
| Mean-Variance | risk.mean_variance_of(f, gamma=...) |
Mean + γ · Variance tradeoff |
| Value at Risk | risk.var_of(f, alpha=...) |
α-quantile of the cost distribution |
| Conditional VaR | risk.cvar_of(f, alpha=...) |
Expected cost in the worst α-fraction |
| Entropic Risk | risk.entropic_risk_of(f, theta=...) |
Exponential utility-based risk measure |
Features
- Multiple risk metrics with a consistent, protocol-based API
- NumPy and JAX backends with automatic inference from type annotations
- Monte Carlo sampling with built-in distributions, or custom sampling strategies
Documentation
To build the Typst-based documentation, install the custom Typst packages locally:
typi --project-directory=documents
typi is available after you've set up the project environment with uv sync.
Contributing
See CONTRIBUTING.md.
License
MIT, see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file riskit-1.0.0.tar.gz.
File metadata
- Download URL: riskit-1.0.0.tar.gz
- Upload date:
- Size: 127.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb4e06b23bea8591fd02bf78468b379888e94c28bca0423b3f7251251675c75b
|
|
| MD5 |
b3fcfe3972c50b96bf1a538e6185520c
|
|
| BLAKE2b-256 |
c4e58ad16f2b81d9b57d3271ecf207ae1803c8da45995a860e5a237e171159d3
|
File details
Details for the file riskit-1.0.0-py3-none-any.whl.
File metadata
- Download URL: riskit-1.0.0-py3-none-any.whl
- Upload date:
- Size: 39.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f38aa19535a326895629f29961a9998cab21684ae8571cc5ba95e1a19d695ad6
|
|
| MD5 |
aa88f2cda1308e7eebc1743bed737e09
|
|
| BLAKE2b-256 |
46956cf8d33ebeb2c88431ddfb0c10c88bea578af7a3624443559bfd5a76227b
|