Skip to main content
QUICK REVIEW

[Paper Review] denmarf: a Python package for density estimation using masked autoregressive flow

R. K. L. Lo|arXiv (Cornell University)|May 22, 2023
Gaussian Processes and Bayesian InferenceComputer Science3 citations
TL;DR

denmarf is a Python package that enables efficient, scalable density estimation using masked autoregressive flows (MAF), offering a scikit-learn-like interface for seamless integration into data science workflows. It provides O(1) evaluation cost independent of training data size N, supports GPU/CPU inference, and automatically handles bounded distributions via logit transformations, outperforming kernel density estimation (KDE) in speed for large datasets.

ABSTRACT

Masked autoregressive flow (MAF) is a state-of-the-art non-parametric density estimation technique. It is based on the idea (known as a normalizing flow) that a simple base probability distribution can be mapped into a complicated target distribution that one wishes to approximate, using a sequence of bijective transformations. The denmarf package provides a scikit-learn-like interface in Python for researchers to effortlessly use MAF for density estimation in their applications to evaluate probability densities of the underlying distribution of a set of data and generate new samples from the data, on either a CPU or a GPU, as simple as "from denmarf import DensityEstimate; de = DensityEstimate().fit(X)". The package also implements logistic transformations to facilitate the fitting of bounded distributions.

Motivation & Objective

  • To lower the technical barrier for researchers to apply masked autoregressive flows (MAF) in density estimation without deep learning library expertise.
  • To provide a drop-in replacement for scikit-learn's KernelDensity with superior scalability for large datasets.
  • To enable efficient density evaluation and sample generation independent of training data size N.
  • To handle bounded distributions robustly using automatic logit transformations and Jacobian correction.
  • To support both CPU and GPU inference with minimal user configuration.

Proposed method

  • Uses masked autoregressive flows (MAF) to learn a bijective transformation T mapping a complex target distribution f(x) to a standard normal base distribution u(y).
  • Employs the change-of-variable formula: f(x) = u(T(x)) * |J_T(x)|, where |J_T| is the Jacobian determinant of the transformation.
  • Applies logit transformations to input data when distributions are bounded, converting them to unbounded space to enable stable MAF training.
  • Automatically includes the Jacobian determinant of the logit transformation in density evaluations to maintain probabilistic correctness.
  • Generates new samples by sampling from the base normal distribution and applying the inverse transformation T^(-1).
  • Built on PyTorch-Flows for efficient differentiable neural network operations and supports both CPU and GPU execution.

Experimental results

Research questions

  • RQ1Can a user-friendly Python package be developed to enable efficient MAF-based density estimation with minimal machine learning expertise?
  • RQ2Does MAF-based density estimation achieve evaluation time independent of training data size N, unlike kernel density estimation?
  • RQ3How can bounded distributions be effectively modeled using MAF without violating the bijectivity of the flow?
  • RQ4Can automatic logit transformation and Jacobian correction maintain accuracy while enabling stable training on bounded data?
  • RQ5To what extent does denmarf outperform existing KDE implementations in terms of inference speed for large datasets?

Key findings

  • MAF-based density estimation in denmarf achieves evaluation cost independent of training data size N, unlike KDE which scales as O(MND) for M evaluations.
  • The package enables density evaluation and sample generation in constant time per evaluation, regardless of N, making it highly scalable for large datasets (e.g., N ~ 10^7).
  • Automatic logit transformation allows accurate modeling of bounded distributions by transforming them to unbounded space prior to flow learning.
  • The package correctly accounts for the Jacobian of the logit transformation during density evaluation, preserving probabilistic consistency.
  • denmarf provides a drop-in replacement for sklearn.neighbors.KernelDensity with significantly faster inference on large datasets.
  • The implementation supports both CPU and GPU inference with minimal user configuration, enhancing accessibility and performance.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.