Skip to main content

Product Monte Carlo (PMC)

PMC estimates expectations under a product of densities. To see how, consider the following setup.

Suppose you can draw samples independently from $K$ distributions on $\mathcal X\subseteq\mathbb R^p$:

$$ X_k \overset{\text{ind.}}{\sim} \pi_k, \qquad k=1,\ldots,K. $$

We define the product distribution $\pi^\star$ as follows:

$$ \pi^\star(x) = \frac{\prod\limits_{k=1}^{K}\pi_k(x)} {\int_{\mathcal X}\prod\limits_{k=1}^{K}\pi_k(u)\,du} \propto \prod\limits_{k=1}^{K}\pi_k(x), \qquad \forall\; x\in\mathcal X. $$

Given a function $h:\mathcal X\to\mathbb R$, we wish to compute its expectation under $\pi^\star$:

$$ \mathbb E_{X\sim\pi^\star}[h(X)] = \int_{\mathcal X}h(x)\,\pi^\star(x)\,\mathrm{d}x. $$

We call a function $c:\mathcal X^K\to\mathcal X$ a consensus function if

$$ c(x,\ldots,x)=x, \qquad \forall\; x\in\mathcal X. $$

We call a function $d:\mathcal X^K\to\mathbb R^m$ a discrepancy function if, for all $x_1,\ldots,x_K\in\mathcal X$,

$$ d(x_1,\ldots,x_K)=\mathbf 0 \quad\Longleftrightarrow\quad x_1=\cdots=x_K. $$

Let $C=c(X_1,\ldots,X_K)$ and $D=d(X_1,\ldots,X_K)$. Then, under suitable regularity conditions, we have that

$$ \mathbb E_{X\sim\pi^\star}[h(X)] = \mathbb E[h(C)\mid D=\mathbf 0_m]. $$

PMC then works as follows:

  1. Draw $S$ independent samples per distribution.
  2. For each set of $K$ draws, compute its consensus $C$ and discrepancy $D$.
  3. Fit a regressor to predict $h(C)$ from $D$.
  4. Estimate the target expectation by evaluating the fitted regressor at $D=\mathbf 0_m$.

Install

To install PMC from PyPI, run:

pip install product-monte-carlo

Example

The example below shows how to estimate an expectation with PMC.

# Import PyTorch and PMC classes
import torch
from pmc import AnchoredDifferences, Mean, OLS, PMC

# Draw S = 1,000 samples from K = 2 univariate standard Gaussian distributions (p = 1)
samples = torch.randn(1_000, 2, 1)

# Configure PMC to estimate the mean under the product distribution
PMC_estimator = PMC(
    consensus=Mean(),
    discrepancy=AnchoredDifferences(),
    h=lambda x: x,
    regressor=OLS(),
)

# Compute and print the resulting estimate
PMC_estimate = PMC_estimator.estimate(samples)
print(PMC_estimate)

Metadata

Release files for product-monte-carlo 0.1.12

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

Source distribution (sdist)

Source distribution for product-monte-carlo 0.1.12
File Size Uploaded Provenance Actions
product_monte_carlo-0.1.12.tar.gz 12.9 kB With provenance Details for product_monte_carlo-0.1.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for product-monte-carlo 0.1.12
File Interpreter ABI Platform Actions
product_monte_carlo-0.1.12-py3-none-any.whl Python 3 none any Details for product_monte_carlo-0.1.12-py3-none-any.whl

Total release size: 27.0 kB

Release files / product_monte_carlo-0.1.12.tar.gz

Download URL product_monte_carlo-0.1.12.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5e21361c071ee534e970ca70ad179c9dd626ec5dfaa45828255d719448b3c317
BLAKE2b-256 checksum
How to use checksums
ccbaaecee81846a9978ccf56fd3e67388c30cf3824289602db0fd6d90bfc5727
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / product_monte_carlo-0.1.12-py3-none-any.whl

Download URL product_monte_carlo-0.1.12-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e59b15a0f14cc73dea0b937a175526ef83081442b8e95bf33ddcb305446ea16e
BLAKE2b-256 checksum
How to use checksums
a63efb333042f2d92549cbdd29b10ce4ae8821a9e32e6c284ccf6ff023038ee8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Security for product-monte-carlo 0.1.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for product_monte_carlo-0.1.12.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.12 This release

2 release files Full provenance

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