Skip to main content
projnormal logo

projnormal is a Python package for working with the projected normal and related distributions. It uses a PyTorch backend to provide efficient computations and fitting procedures.

Given an $n$-dimensional variable $\mathbf{x} \sim \mathcal{N}(\boldsymbol{\mu}, \Sigma)$, the variable obtained by radially projecting $\mathbf{x}$ onto the unit sphere, $\mathbf{y} = \frac{\mathbf{x}}{||\mathbf{x}||}$, follows a projected normal distribution, denoted as $\mathbf{y} \sim \mathcal{PN}(\boldsymbol{\mu}, \Sigma)$.

The package was introduced in the preprint "Projected Normal Distribution: Moment Approximations and Generalizations", which presents the implemented formulas.

Projected Normal Distribution

projnormal implements the following functionalities for the projected normal distribution (and related distributions):

  • PDF and log-PDF formulas
  • Maximum-likelihood parameter estimation
  • Distribution sampling
  • Approximations of the first and second moments
  • Moment matching routines

In the example code below, we generate samples from $\mathcal{PN}(\boldsymbol{\mu}, \Sigma)$ and compute their PDF. The necessary formulas are implemented in the submodule projnormal.formulas.projected_normal.

import torch
import projnormal
import projnormal.formulas.projected_normal as pn_dist

# Sample distribution parameters

N_DIM = 3  # The package work with any dimension
mean_x = projnormal.param_sampling.make_mean(N_DIM)
covariance_x = projnormal.param_sampling.make_spdm(N_DIM)

# Generate distribution samples
samples = pn_dist.sample(
  mean_x=mean_x, covariance_x=covariance_x, n_samples=2000
)

# Compute samples PDF
pdf_values = pn_dist.pdf(
  mean_x=mean_x, covariance_x=covariance_x, y=samples
)

Next, we initialize a ProjNormal object and use it to fit the distribution parameters to the samples.

# Initialize a ProjNormal object to fit
pn_fit = projnormal.classes.ProjNormal(n_dim=N_DIM)

# Fit the parameters of the projected normal distribution
pn_fit.max_likelihood(y=samples)

# Check the fitted parameters against the original parameters
print("Fitted mean vector:", pn_fit.mean_x.detach()) 
print("True mean vector:", mean_x)

print("Fitted covariance matrix: \n", pn_fit.covariance_x.detach())
print("True covariance matrix: \n", covariance_x)

Installation

Virtual environment

We recommend installing the package in a virtual environment. For this, you can first install miniconda (install instructions link), and then create a virtual environment with Python 3.11 using the following shell command:

conda create -n my-projnormal python=3.11

You can then activate the virtual environment with the following command:

conda activate my-projnormal

You should activate the my-sqfa environment to install the package, and every time you want to use it.

Install package

To install the package, you can clone the GitHub repository and install in editable mode using pip:

git clone https://github.com/dherrera1911/projnormal.git
cd projnormal
pip install -e "."

Citation

If you use projnormal in your research, please cite the preprint "Projected Normal Distribution: Moment Approximations and Generalizations":

@misc{herreraesposito2025projected,
      title={Projected Normal Distribution: Moment Approximations and Generalizations},
      author={Daniel Herrera-Esposito and Johannes Burge},
      year={2025},
      eprint={2506.17461},
      archivePrefix={arXiv},
      url={https://arxiv.org/abs/2506.17461}, 
}

Metadata

Release files for projnormal 0.1

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

Source distribution (sdist)

Source distribution for projnormal 0.1
File Size Uploaded Provenance Actions
projnormal-0.1.tar.gz 110.6 kB With provenance Details for projnormal-0.1.tar.gz

Built distribution (wheel)

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

Total release size: 152.6 kB

Release files / projnormal-0.1.tar.gz

Download URL projnormal-0.1.tar.gz
Size 110.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5bd7ec24c8b9e6c2c6ca9446d534d2a7acee51f5859811ace71516697616c343
BLAKE2b-256 checksum
How to use checksums
553ff8920c7d392dcdc090790ed69df51543d5714158ca6b9df1500284aa47e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jul 11, 2025.

Transparency log

Release files / projnormal-0.1-py3-none-any.whl

Download URL projnormal-0.1-py3-none-any.whl
Size 42.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e789a16d1e7d2e4b58083e1d6dff3ce9e7a7cb0fe907491949ffd35b1bde87f
BLAKE2b-256 checksum
How to use checksums
22aba314b5040c638251dc39e297639c4b3c4b17dd0a565d577fb57f9e772e1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jul 11, 2025.

Transparency log

Security for projnormal 0.1

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 projnormal-0.1.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 Jul 11, 2025.

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