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_{k=1}^{K}\pi_k(x)} {\int_{\mathcal X} \prod_{k=1}^{K}\pi_k(u)\thinspace\mathrm{d}u} \propto \prod_{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)\thinspace\pi^\star(x)\thinspace\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\text{ }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.13

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.13
File Size Uploaded Provenance Actions
product_monte_carlo-0.1.13.tar.gz 12.9 kB With provenance Details for product_monte_carlo-0.1.13.tar.gz

Built distribution (wheel)

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

Total release size: 27.0 kB

Release files / product_monte_carlo-0.1.13.tar.gz

Download URL product_monte_carlo-0.1.13.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b33559f1f51ecf1686952bfeed2608ee7d5e65c17606fb5548ec9ec932ab9b26
BLAKE2b-256 checksum
How to use checksums
1a63a4883198878d485de1d858d824e9c481aa57d327f5960e51e79ab551fb9f
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.13-py3-none-any.whl

Download URL product_monte_carlo-0.1.13-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b4ae4f1f97f70b8cc8ca7600ad3c0e3fbd2e2b3f342cabd33d67fbf79b411ea
BLAKE2b-256 checksum
How to use checksums
11856fa32a676f9f3a801c25c3401a91e9373c3648b979bfb73df7dd80c5ec4d
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.13

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.13.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.13 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