Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Multivariate normal CDF computation for tensors. Implementation of closed form derivatives.

License

Notifications You must be signed in to change notification settings

rafaol/torch-mvnorm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Torch-MvNorm

With this small piece of code you can

  • Integrate multivariate normal densities (CDFs)
  • Easily obtain partial derivatives of CDFs w.r.t location, mean and covariance (implementation of closed-form formulas, see e.g. Marmin et al. 2019, appendix 6)
  • Manipulate quantities within a tensor-based framework (e.g. broadcasting is fully supported)

About Torch-MvNorm

Torch-MvNorm is a library that consists of the two following components:

  • integration -- PyTorch-Fortan bridge for Alan Genz's routine using SciPy.
  • multivariate_normal_cdf -- implementation of the formula of the multivariate normal CDF gradient, with respect to location and covariance.

There is no GPU support. I am still looking for the best way to perform integrations of normal densities with GPUs. If you want, please share your opinion on this, e.g. opening an issue.

Installation

Dependencies

sudo apt-get install -y python3-joblib
  • Install SciPy python module.

Get the Torch-MvNorm source

git clone --recursive https://github.com/SebastienMarmin/torch-mvnorm
cd torch-mvnorm

Test the code

import torch
from torch.autograd import grad
from mvnorm import multivariate_normal_cdf as Phi

d = 3
x = torch.randn(d)
m = torch.zeros(d)
Croot = torch.randn(d,d)
C = Croot.mm(Croot.t())+torch.diag(torch.ones(d))

x.requires_grad = True
m.requires_grad = True
C.requires_grad = True

P = Phi(x,m,C)
dPdx, dPdm, dPdC = grad(P,(x,m,C)) # Bien sûr, dPdx = -dPdm.

Getting Started

Communication and contribution

I welcome all contributions. Please let me know if you encounter a bug by filing an issue. Feel free to request a feature, make suggestions, share thoughts, etc, using the GitHub plateform or contacting me.

If you came across this work for a publication, please considere citing me for the code or for the mathematical derivation.

License

Torch-MvNorm is under GNU General Public License. See the LICENSE file.

About

Multivariate normal CDF computation for tensors. Implementation of closed form derivatives.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.3%
  • TeX 1.7%