Skip to main content

Baryx

Barycenter preserving measure reduction in JAX

A JAX implementation of the recombination (barycenter preserving discrete-measure reduction) algorithms.

Installation

Requires Python 3.10+

pip install baryx

Example

import jax
import jax.random as jr

from baryx import recombine

# Required for good results with the default solvers.
jax.config.update("jax_enable_x64", True)

# Nodes and weights define a discrete measure $\mu$.
n, m = 1024, 32
key = jr.key(0)
nodes_key, weights_key = jr.split(key)
nodes = jr.normal(nodes_key, (n, m))
weights = jr.uniform(weights_key, (n,))


# Test functions $f$ used to define the push-forward $f_{\#}\mu$.
def f(x):
    return x


# Apply the test functions $f$ to yield the push-forward $f_{\#}\mu$.
pushed_forward_nodes = f(nodes)

# Solve the recombination problem for the push-forward $f_{\#}{\mu}$.
solution = recombine(pushed_forward_nodes, weights)
err = solution.error(norm=2)
print(err)

# Construct the recombined measure $\hat{\mu}$.
recombined_nodes = nodes[solution.indices]
recombined_weights = solution.weights

What is recombination

Recombination refers to both a discrete measure reduction problem and the algorithm(s) used to solve it.

The recombination problem

Given a discrete measure $\mu$, whose support is a subset of some arbitrary space $X$ with cardinality $n$, and a set of test functions $f = \{f_1, \dots, f_m \mid f_i \colon X \to \mathbb{R}\}$, construct a discrete measure $\hat{\mu}$ whose support has cardinality at most $r+1$ and is a subset of the support of $\mu$ such that

$$\int_\Omega f(x)\mu(x) dx = \int_\Omega f(x)\hat{\mu}(x) dx,$$

where $f(x) = (f_1(x), f_2(x), \dots, f_m(x))$ is an embedding $X \to \mathbb{R}^m$. Note: The number of retained support points is at most $r + 1$, where $r$ is the rank of the embedded node matrix (i.e., the number of linearly independent test functions), satisfying $r \le m$.

A linear programming interpretation: The recombination problem can also be formulated as finding a basic feasible solution $\hat{w}$ to the following linear program $$\bar{A}^Tw = \bar{b},\ w \ge 0,$$ with trivial (zero) objective and constraints $\bar{A} = [1 \mid A]$ and $\bar{b} = [\sum w \mid b ]$, where $A = (f(x_1), \dots, f(x_n))^T$ is an $n \times m$ matrix representing the points for the push-forward measure $f_{\#}\mu$, and $b = \int_\Omega f(x)\mu(x)$ represents the integral to be preserved.

In this interpretation, a given (not necessarily basic) feasible solution $w$—the weights of the initial measure $\mu$—is recombined into a basic feasible solution $\hat{w}$ that satisfies the same linear constraints with minimal support.

The recombination algorithm(s)

The process of applying a numerical algorithm which solves the recombination problem, as defined above, may be referred to as recombination, e.g., "we perform recombination to obtain a reduced measure...".

This library implements the deterministic 1-Tree and m-Tree measure reduction algorithms introduced by Litterer and Lyons 2012 and Tchernychova 2016 respectively, in addition to providing a new generalization referred to as $\alpha$--Tree measure reduction. The tree reduction algorithms can be accessed by setting the solver keyword argument of recombine(nodes, weights, solver=...) to the following:

  • 1-Tree: Caratheodory(...) or TreeReduce(Caratheodory(...), tree_reduction_factor=n/(m+1)),
  • m-Tree reduction: TreeReduce(Caratheodory(...), tree_reduction_factor=2),
  • $\alpha$-Tree reduction (default): TreeReduce(Caratheodory(...), tree_reduction_factor=1+alpha/(m+1)).

Notice that 1-Tree and m-Tree reduction are special cases of $\alpha$-Tree, where $\alpha = n - (m + 1)$ and $\alpha = m + 1$ respectively.

The randomized and hybrid algorithms introduced by Cossentino et al 2020 are not yet implemented in this library; a JAX-free implementation can be found here. Please open an issue if there is another recombination-like algorithm you would like to see implemented in baryx.

Notice

Baryx loosely forks and extends the recombination algorithms implemented in the Coreax coreset library (licensed under Apache-2.0). Baryx provides a variety of algorithmic, numerical, and quality-of-life improvements in addition to having a simpler user API, and fewer dependencies.

See also

Some other recombination related works that you may find interesting:

Packages

  • PyRecombine - the original (CPU only) CPP implementation with python bindings.
  • RoughPy - a toolbox for working with streaming data as rough paths in Python.

Metadata

Release files for baryx 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for baryx 0.1.0
File Size Uploaded
baryx-0.1.0.tar.gz 20.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for baryx 0.1.0
File Interpreter ABI Platform
baryx-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.5 kB

Release files / baryx-0.1.0.tar.gz

Download URL baryx-0.1.0.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
27154fbfd6455e41fa56c11720e65e8f2a04fc56adc21a69eb666211fda29cf0
BLAKE2b-256 checksum
How to use checksums
78fe091e2a96ee169c2822711e3223ffe53a17da7d57b225ed6224f611336576
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / baryx-0.1.0-py3-none-any.whl

Download URL baryx-0.1.0-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e0c21d87616f768ce0f74e984152b2dcb6be2c76c30861f41f2954fa6b6ebe4
BLAKE2b-256 checksum
How to use checksums
718012bd9184ea2bb28322ac573821fa6ff22e454590b323cf8abbb5338a6e98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page