A PyTorch implementation of the Projected Normal distribution with fitting capabilities.
Project description
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},
}
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 projnormal-0.1.tar.gz.
File metadata
- Download URL: projnormal-0.1.tar.gz
- Upload date:
- Size: 110.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bd7ec24c8b9e6c2c6ca9446d534d2a7acee51f5859811ace71516697616c343
|
|
| MD5 |
0ae47c94ac4cd6067739ef0084a7c0ca
|
|
| BLAKE2b-256 |
553ff8920c7d392dcdc090790ed69df51543d5714158ca6b9df1500284aa47e9
|
Provenance
The following attestation bundles were made for projnormal-0.1.tar.gz:
Publisher:
publish-to-pypi.yml on dherrera1911/projnormal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
projnormal-0.1.tar.gz -
Subject digest:
5bd7ec24c8b9e6c2c6ca9446d534d2a7acee51f5859811ace71516697616c343 - Sigstore transparency entry: 272103538
- Sigstore integration time:
-
Permalink:
dherrera1911/projnormal@a4c025c607e88171c714b92686f265ebe436b272 -
Branch / Tag:
refs/tags/v0.1 - Owner: https://github.com/dherrera1911
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a4c025c607e88171c714b92686f265ebe436b272 -
Trigger Event:
release
-
Statement type:
File details
Details for the file projnormal-0.1-py3-none-any.whl.
File metadata
- Download URL: projnormal-0.1-py3-none-any.whl
- Upload date:
- Size: 42.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e789a16d1e7d2e4b58083e1d6dff3ce9e7a7cb0fe907491949ffd35b1bde87f
|
|
| MD5 |
bc0f4e928c1a3839a654cae23a36730f
|
|
| BLAKE2b-256 |
22aba314b5040c638251dc39e297639c4b3c4b17dd0a565d577fb57f9e772e1c
|
Provenance
The following attestation bundles were made for projnormal-0.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on dherrera1911/projnormal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
projnormal-0.1-py3-none-any.whl -
Subject digest:
3e789a16d1e7d2e4b58083e1d6dff3ce9e7a7cb0fe907491949ffd35b1bde87f - Sigstore transparency entry: 272103557
- Sigstore integration time:
-
Permalink:
dherrera1911/projnormal@a4c025c607e88171c714b92686f265ebe436b272 -
Branch / Tag:
refs/tags/v0.1 - Owner: https://github.com/dherrera1911
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a4c025c607e88171c714b92686f265ebe436b272 -
Trigger Event:
release
-
Statement type: