summaries: This paper addresses the problem of constructing injective normalizing flows, which connect some low-dimensional space with the data manifold of interest in the high-dimensional space. Typically injective (or rectangular) flows are composed of two square flows with the “upsampling” padding layer between them. Because the volume change term in the case of injective flows is seemingly intractable, current approaches find workarounds by training these two square flows separately step-by-step. Though this decision has certain drawbacks and may result in suboptimal performance. Current work suggests to employ numerical linear algebra methods to make volume change computation tractable. Experiments demonstrate that taking into account volume сhanging term improves the generation results both for synthetic and real-life data. Interestingly, it also improves out of distribution detection score, allowing the model trained on FashionMNItST to assign lower probability for the MNIST data samples. The paper addresses the challenge of learning a normalizing flow, under the assumption that the data probability function is concentrated on a low dimensional manifold. Utilizing the manifold assumption introduces a challenge in computing the volume change term. This paper suggests addressing this computational challenge in two ways: i) If the manifold dimension is low enough, it is reasonable to calculate the map differential exactly based on AD forward mode; ii) alternatively, an unbiased stochastic estimator for the log det can be used.  This paper is motivated by the desire to circumvent a problematic requirement in Normalizing Flows (NFs) on the function $f: \mathbb{R}^d \rightarrow \mathbb{R}^D$ that produces the pushforward measure --- namely, that $f$ must be strictly invertible. This is difficult for generative models, since the dimension of the latent space $d$ is usually much smaller than that of the target data space $D$, i.e. $d << D$. The invertibility requirement centers around the change-of-variables formula, which is crucial for computing the cost function in NFs, and which requires computing the Jacobian of $f^{-1}$. To enable the use of NFs on latent/data spaces where $d << D$, the authors propose "Rectangular" NFs (RNFs). The name comes from the fact that the Jacobian of $f$ is now rectangular in the $d << D$ case. This involves the use of a differential geometric variant of the change-of-variables formula, and is much more computationally taxing, but provides superior density estimation performance to previous work.  The paper presents new methods for estimating densities using rectangular normalizing flows. Rectangular normalizing flows, unlike squared normalizing flows, allow considering injective instead of bijective flows. This property is exploited for estimating the density of data residing on a low (d) dimensional manifold in R^D, for D>d. Existing works using rectangular flows to estimate densities supported on low dimensional manifolds assume that the manifold is known, and therefore are restricted to tori, spheres, etc. In contrast, this work does not make this assumption and shows that density estimation for injective flows based on ML is tractable. Two methods are proposed, which are based on incorporating and estimating the “Jacobian-transpose-Jacobian” in the objective. One is based on an exact derivation, which is computationally demanding. The other is based on stochastic gradient estimates. Experimental results on a simulation and a couple of datasets are shown, demonstrating the advantage of the proposed methods compared to an existing method as well as the tradeoff between memory and variance incurred by the two proposed methods. The task of interest is to simultaneously learn a manifold (with a fixed predefined dimensionality) and the density on it, from training data. The proposed method, rectangular flows, is developed based on an existing work (Brehmer and Cranmer [6]) that used a two-step training procedure (for manifold matching and density matching, respectively). The main contributions include: (1) revealing that the two-step training can be improved by joint training; (2) a new technique to enable computing the Jacobian-transpose-Jacobian term of the joint training objective with better efficiency. Experiments on simulated data and MNIST/FMNIST are conducted to demonstrate the proposed method.
abstractText: Normalizing flows are invertible neural networks with tractable change-of-volume terms, which allow optimization of their parameters to be efficiently performed via maximum likelihood. However, data of interest are typically assumed to live in some (often unknown) low-dimensional manifold embedded in a high-dimensional ambient space. The result is a modelling mismatch since – by construction – the invertibility requirement implies high-dimensional support of the learned distribution. Injective flows, mappings from lowto high-dimensional spaces, aim to fix this discrepancy by learning distributions on manifolds, but the resulting volume-change term becomes more challenging to evaluate. Current approaches either avoid computing this term entirely using various heuristics, or assume the manifold is known beforehand and therefore are not widely applicable. Instead, we propose two methods to tractably calculate the gradient of this term with respect to the parameters of the model, relying on careful use of automatic differentiation and techniques from numerical linear algebra. Both approaches perform end-to-end nonlinear manifold learning and density estimation for data projected onto this manifold. We study the trade-offs between our proposed methods, empirically verify that we outperform approaches ignoring the volume-change term by more accurately learning manifolds and the corresponding distributions on them, and show promising results on out-of-distribution detection. Our code is available at https://github.com/layer6ai-labs/rectangular-flows.
authors.name: Anthony L. Caterini
authors.name: Gabriel Loaiza-Ganem
authors.name: Geoff Pleiss
authors.name: John P. Cunningham
references.authors: A.A. Alemi I. Fischer J.V. Dillon K. Murphy
references.title: Deep variational information bottleneck
references.venue: ICLR
references.authors: A.A. Alemi I. Fischer J.V. Dillon
references.title: Uncertainty in the variational information bottleneck
references.venue: arXiv preprint arXiv:1807.00906
references.authors: A.G. Baydin B.A. Pearlmutter A.A. Radul J.M. Siskind
references.title: Automatic differentiation in machine learning: a survey
references.venue: Journal of machine learning research, 18
references.authors: J. Behrmann W. Grathwohl R.T. Chen D. Duvenaud J.-H. Jacobsen
references.title: Invertible residual networks
references.venue: International Conference on Machine Learning, pages 573–582. PMLR
references.authors: J. Behrmann P. Vicol K.-C. Wang R. Grosse J.-H. Jacobsen
references.title: Understanding and mitigating exploding inverses in invertible neural networks
references.venue: International Conference on Artificial Intelligence and Statistics, pages 1792–1800. PMLR
references.authors: Y. Bengio A. Courville P. Vincent
references.title: Representation learning: A review and new perspectives
references.venue: IEEE transactions on pattern analysis and machine intelligence, 35(8):1798–1828
references.authors: D.P. Bertsekas
references.title: Constrained optimization and Lagrange multiplier methods
references.venue: Academic press
references.authors: J. Brehmer K. Cranmer
references.title: Flows for simultaneous manifold learning and density estimation
references.venue: Advances in Neural Information Processing Systems, volume 33
references.authors: R.T.Q. Chen J. Behrmann D.K. Duvenaud J.-H. Jacobsen
references.title: Residual flows for invertible generative modeling
references.venue: Advances in Neural Information Processing Systems, volume 32
references.authors: H. Choi E. Jang A.A. Alemi
references.title: Waic
references.venue: but why? generative ensembles for robust anomaly detection. arXiv preprint arXiv:1810.01392
references.authors: R. Cornish A. Caterini G. Deligiannidis A. Doucet
references.title: Relaxing bijectivity constraints with continuously indexed normalising flows
references.venue: International Conference on Machine Learning, pages 2133–2143. PMLR
references.authors: E. Cunningham R. Zabounidis A. Agrawal I. Fiterau D. Sheldon
references.title: Normalizing flows across dimensions
references.venue: arXiv preprint arXiv:2006.13070
references.authors: B. Dai D. Wipf
references.title: Diagnosing and enhancing vae models
references.venue: ICLR
references.authors: L. Dinh D. Krueger Y. Bengio
references.title: Nice: Non-linear independent components estimation
references.venue: arXiv preprint arXiv:1410.8516
references.authors: L. Dinh J. Sohl-Dickstein S. Bengio
references.title: Density estimation using real nvp
references.venue: ICLR
references.authors: C. Durkan A. Bekasov I. Murray G. Papamakarios
references.title: Neural spline flows
references.venue: Advances in Neural Information Processing Systems, volume 32
references.authors: J. Gardner G. Pleiss K.Q. Weinberger D. Bindel A.G. Wilson
references.title: Gpytorch: Blackbox matrix-matrix gaussian process inference with gpu acceleration
references.venue: Advances in Neural Information Processing Systems, 31
references.authors: M.C. Gemici D. Rezende S. Mohamed
references.title: Normalizing flows on riemannian manifolds
references.venue: arXiv preprint arXiv:1611.02304
references.authors: I.J. Goodfellow J. Pouget-Abadie M. Mirza B. Xu D. Warde-Farley S. Ozair A. Courville Y. Bengio
references.title: Generative adversarial nets
references.venue: Proceedings of the 27th International Conference on Neural Information Processing Systems-Volume 2, pages 2672–2680
references.authors: I. Han D. Malioutov J. Shin
references.title: Large-scale log-determinant computation through stochastic chebyshev expansions
references.venue: International Conference on Machine Learning, pages 908–917. PMLR
references.authors: M. Heusel H. Ramsauer T. Unterthiner B. Nessler S. Hochreiter
references.title: Gans trained by a two time-scale update rule converge to a local nash equilibrium
references.venue: Advances in Neural Information Processing Systems, volume 30
references.authors: C.-W. Huang R.T. Chen C. Tsirigotis A. Courville
references.title: Convex potential flows: Universal probability distributions with optimal transport and convex optimization
references.venue: ICLR
references.authors: M.F. Hutchinson
references.title: A stochastic estimator of the trace of the influence matrix for laplacian smoothing splines
references.venue: Communications in Statistics-Simulation and Computation, 18(3):1059– 1076
references.authors: S. Ioffe C. Szegedy
references.title: Batch normalization: Accelerating deep network training by reducing internal covariate shift
references.venue: International conference on machine learning, pages 448–456. PMLR
references.authors: H. Kahn
references.title: Use of different Monte Carlo sampling techniques
references.venue: Rand Corporation
references.authors: W. Karush
references.title: Minima of functions of several variables with inequalities as side constraints
references.venue: M. Sc. Dissertation. Dept. of Mathematics, Univ. of Chicago
references.authors: D.P. Kingma J. Ba
references.title: Adam: A method for stochastic optimization
references.venue: ICLR
references.authors: D.P. Kingma P. Dhariwal
references.title: Glow: generative flow with invertible 1⇥ 1 convolutions
references.venue: Advances in Neural Information Processing Systems, volume 31
references.authors: D.P. Kingma M. Welling
references.title: Auto-encoding variational bayes
references.venue: ICLR
references.authors: D.P. Kingma T. Salimans R. Jozefowicz X. Chen I. Sutskever M. Welling
references.title: Improved variational inference with inverse autoregressive flow
references.venue: Advances in Neural Information Processing Systems, volume 30
references.authors: I. Kobyzev S. Prince M. Brubaker
references.title: Normalizing flows: An introduction and review of current methods
references.venue: IEEE Transactions on Pattern Analysis and Machine Intelligence
references.authors: S.G. Krantz H.R. Parks
references.title: Geometric integration theory
references.venue: Springer Science & Business Media
references.authors: A. Krizhevsky G. Hinton
references.title: Learning multiple layers of features from tiny images
references.authors: H.W. Kuhn A. Tucker. W
references.title: 1951," nonlinear programming,
references.venue: In Proceedings of the Second Berkeley Symposium on Mathematical Statistics and Probability(University of California Press, Berkeley, CA),
references.authors: A. Kumar B. Poole K. Murphy
references.title: Regularized autoencoders via relaxed injective probability flow
references.venue: International Conference on Artificial Intelligence and Statistics, pages 4292–4301. PMLR
references.authors: Y. LeChun
references.title: The mnist database of handwritten digits
references.venue: 1998. URL http://yann. lecun. com/exdb/mnist
references.authors: G. Loaiza-Ganem Y. Gao J.P. Cunningham
references.title: Maximum entropy flow networks
references.venue: ICLR
references.authors: I. Loshchilov F. Hutter
references.title: Decoupled weight decay regularization
references.venue: ICLR
references.authors: C. Lu J. Chen C. Li Q. Wang J. Zhu
references.title: Implicit normalizing flows
references.venue: ICLR
references.authors: E. Mathieu M. Nickel
references.title: Riemannian continuous normalizing flows
references.venue: Advances in Neural Information Processing Systems, volume 33
references.authors: E. Nalisnick A. Matsukawa Y.W. Teh D. Gorur
references.title: and B
references.venue: Lakshminarayanan. Do deep generative models know what they don’t know? ICLR
references.authors: Y. Netzer T. Wang A. Coates A. Bissacco B. Wu A.Y. Ng
references.title: Reading digits in natural images with unsupervised feature learning
references.authors: J. Nocedal S. Wright
references.title: Numerical optimization
references.venue: Springer Science & Business Media
references.authors: D. Oktay N. McGreivy J. Aduol A. Beatson R.P. Adams
references.title: Randomized automatic differentiation
references.venue: ICLR
references.authors: G. Papamakarios T. Pavlakou I. Murray
references.title: Masked autoregressive flow for density estimation
references.venue: Advances in Neural Information Processing Systems, volume 30
references.authors: G. Papamakarios E. Nalisnick D.J. Rezende S. Mohamed B. Lakshminarayanan
references.title: Normalizing flows for probabilistic modeling and inference
references.venue: arXiv preprint arXiv:1912.02762
references.authors: A. Paszke S. Gross F. Massa A. Lerer J. Bradbury G. Chanan T. Killeen Z. Lin N. Gimelshein L. Antiga A. Desmaison A. Kopf E. Yang Z. DeVito M. Raison A. Tejani S. Chilamkurthy B. Steiner L. Fang J. Bai S. Chintala
references.title: Pytorch: An imperative style, high-performance deep learning library
references.venue: In Advances in Neural Information Processing Systems 32,
references.authors: X. Pennec
references.title: Intrinsic statistics on riemannian manifolds: Basic tools for geometric measurements
references.venue: Journal of Mathematical Imaging and Vision, 25(1):127–154
references.authors: K.B. Petersen M.S. Pedersen
references.title: The matrix cookbook
references.venue: URL http://www2.imm
references.authors: A. Potapczynski L. Wu D. Biderman G. Pleiss J.P. Cunningham
references.title: Bias-free scalable gaussian processes via randomized truncations
references.venue: International Conference on Machine Learning, to appear
references.authors: J. Ren P.J. Liu E. Fertig J. Snoek R. Poplin M. Depristo J. Dillon B. Lakshminarayanan
references.title: Likelihood ratios for out-of-distribution detection
references.venue: Advances in Neural Information Processing Systems, volume 32
references.authors: D. Rezende S. Mohamed
references.title: Variational inference with normalizing flows
references.venue: International Conference on Machine Learning, pages 1530–1538. PMLR
references.authors: D.J. Rezende G. Papamakarios S. Racaniere M. Albergo G. Kanwar P. Shanahan K. Cranmer
references.title: Normalizing flows on tori and spheres
references.venue: International Conference on Machine Learning, pages 8083–8092. PMLR
references.authors: B.L. Ross J.C. Cresswell
references.title: Tractable density estimation on learned manifolds with conformal embedding flows
references.venue: arXiv preprint arXiv:2106.05275
references.authors: J.R. Shewchuk
references.title: An introduction to the conjugate gradient method without the agonizing pain
references.authors: C. Szegedy W. Liu Y. Jia P. Sermanet S. Reed D. Anguelov D. Erhan V. Vanhoucke A. Rabinovich
references.title: Going deeper with convolutions
references.venue: Proceedings of the IEEE conference on computer vision and pattern recognition, pages 1–9
references.authors: H. Xiao K. Rasul R. Vollgraf
references.title: Fashion-mnist: a novel image dataset for benchmarking machine learning algorithms
references.venue: arXiv preprint arXiv:1708.07747
sections.heading: 1 Introduction
sections.text: In recent years, Normalizing Flows (NFs) have become a staple of generative modelling, being widely used for density estimation [14, 15, 45, 28, 16], variational inference [52, 30], maximum entropy modelling [37], and more [46, 31]. In density estimation, we typically have access to a set of points living in some high-dimensional space RD. NFs model the corresponding data-generating distribution as the pushforward of a simple distribution on RD – often a Gaussian – through a smooth bijective mapping. Clever construction of these bijections allows for tractable density evaluation and thus maximum likelihood estimation of the parameters. However, as an immediate consequence of this choice, the learned distribution has support homeomorphic to RD; in particular, the resulting distribution is supported on a set of dimension D. This is not a realistic assumption in practice – especially for density estimation – as it directly contradicts the manifold hypothesis [6] which states that high-dimensional data lives on a lower-dimensional manifold embedded in ambient space.
  ⇤Authors contributed equally.
  35th Conference on Neural Information Processing Systems (NeurIPS 2021).
  A natural idea to circumvent this misspecification is to consider injective instead of bijective flows, which now push forward a random variable on Rd with d < D to obtain a distribution on some d-dimensional manifold embedded in RD. These mappings admit a change-of-variable formula bearing resemblance to that of bijective flows, but unfortunately the volume-change term becomes computationally prohibitive, which then impacts the tractability of maximum likelihood. While there have been recent efforts towards training flows where the resulting distribution is supported on a low-dimensional manifold [18, 53, 8, 35, 40, 12], these approaches either assume that the manifold is known beforehand or propose various heuristics to avoid the change-of-variable computation. Both of these are undesirable, because, while we should expect most high-dimensional data of interest to exhibit low-dimensional structure, this structure is almost always unknown. On the other hand, we argue that avoiding the volume-change term may result in learning a manifold to which it is difficult to properly assign density, and this approach further results in methods which do not take advantage of density evaluation, undermining the main motivation for using NFs in the first place.
  We show that density estimation for injective flows based on maximum likelihood can be made tractable. By carefully leveraging forward- and backward-mode automatic differentiation [3], we propose two methods that allow backpropagating through the volume term arising from the injective change-of-variable formula. The first method involves exact evaluation of this term and its gradient which incurs a higher memory cost; the second uses conjugate gradients [43] and Hutchinson’s trace estimator [23] to obtain unbiased stochastic gradient estimates. Unlike previous work, our methods do not need the data manifold to be specified beforehand, but instead simultaneously estimate this manifold along with the distribution on it end-to-end, thus enabling maximum likelihood training to occur. To the best of our knowledge, ours are the first methods to scale backpropagation through the injective volume-change term to ambient dimensions D close to 3,000. We study the trade-off between memory and variance introduced by our methods and show empirical improvements over injective flow baselines for density estimation. We also show that injective flows obtain state-of-the-art performance for likelihood-based Out-of-Distribution (OoD) detection, assigning higher likelihoods to Fashion-MNIST (FMNIST) [57] than to MNIST [36] with a model trained on the former.
sections.heading: 2 Background
sections.heading: 2.1 Square Normalizing Flows
sections.text: A normalizing flow [52, 15] is a diffeomorphism f̃✓ : RD ! RD parametrized by ✓, that is, a differentiable bijection with differentiable inverse. Starting with a random variable Z ⇠ pZ for a simple density pZ supported on RD, e.g. a standard Gaussian, the change-of-variable formula states that the random variable X := f̃✓(Z) has density pX on RD given by:
  pX(x) = pZ ⇣ f̃ 1✓ (x) ⌘ detJ h f̃✓ i ⇣ f̃ 1✓ (x) ⌘ 1 , (1)
  where J[·] is the differentiation operator, so that J[f̃✓](f̃ 1✓ (x)) 2 RD⇥D is the Jacobian of f̃✓ (with respect to the inputs and not ✓) evaluated at f̃ 1✓ (x). We refer to this now standard setup as square flows since the Jacobian is a square matrix. The change-of-variable formula is often written in terms of the Jacobian of f̃ 1✓ , but we use the form of (1) as it is more applicable for the next section. NFs are typically constructed in such a way that not only ensures bijectivity, but also so that the Jacobian determinant in (1) can be efficiently evaluated. When provided with a dataset {xi}ni=1 ⇢ RD, an NF models its generating distribution as the pushforward of pZ through f̃✓, and thus the parameters can be estimated via maximum likelhood as ✓⇤ := argmax✓ Pn i=1 log pX(xi).
sections.heading: 2.2 Rectangular Normalizing Flows
sections.text: As previously mentioned, square NFs unrealistically result in the learned density pX having Ddimensional support. We follow the injective flow construction of Brehmer and Cranmer [8], where a smooth and injective mapping g : Rd ! RD with d < D is constructed. In this setting, Z 2 Rd is the low-dimensional variable used to model the data as X := g (Z). A well-known result from differential geometry [32] provides an applicable change-of-variable formula:
  pX(x) = pZ ⇣ g 1 (x) ⌘ detJ[g ]> ⇣ g 1 (x) ⌘ J[g ] ⇣ g 1 (x) ⌘ 1/2 1(x 2M ), (2)
  where M := {g (z) : z 2 Rd}. The Jacobian-transpose-Jacobian determinant now characterizes the change in volume from Z to X . We make several relevant observations: (i) The Jacobian matrix J[g ](g 1 (x)) 2 RD⇥d is no longer a square matrix, and we thus refer to these flows as rectangular.
  (ii) Note that g 1 : M ! Rd is only properly defined on M and not RD, and pX is now supported on the d-dimensional manifold M . (iii) We write the indicator 1(x 2M ) explicitly to highlight the fact that this density is not a density with respect to the Lebesgue measure; rather, the dominating measure is a Riemannian measure on the manifold M [48]. (iv) One can clearly verify as a sanity check that when d = D, equation (2) reduces to (1).
  Since data points x will almost surely not lie exactly on M , we use a left inverse g† : RD ! Rd in place of g 1 such that g † (g (z)) = z for all z 2 Rd, which exists because g is injective. This is
  properly defined on RD, unlike g 1 which only exists over M . Equation (2) then becomes:
  pX(x) = pZ ⇣ g† (x) ⌘ detJ[g ]> ⇣ g† (x) ⌘ J[g ] ⇣ g† (x) ⌘ 1/2 . (3)
  Note that (3) is equivalent to projecting x onto M as x g (g† (x)), and then evaluating the density from (2) at the projected point.
  Now, g is injectively constructed as follows:
  g = f̃✓ pad h⌘ and g† = h 1 ⌘ pad † f̃ 1✓ , (4)
  where f̃✓ : RD ! RD and h⌘ : Rd ! Rd are both square flows, := (✓, ⌘), and pad : Rd ! RD and pad† : RD ! Rd are defined as pad(z) = (z,0) and pad†(z, z0) = z, where 0, z0 2 RD d. Now, M depends only on ✓ and not ⌘, so we write it as M✓ from now on. Applying (3) yields:
  pX(x) = pZ ⇣ g† (x) ⌘ detJ[h⌘] ⇣ g† (x) ⌘ 1 detJ[f✓]> ⇣ f†✓ (x) ⌘ J[f✓] ⇣ f†✓ (x) ⌘ 1/2 , (5)
  where f✓ = f̃✓ pad and f†✓ = pad † f̃ 1✓ . We include a derivation of (5) in Appendix A, along with a note on why injective transformations cannot be stacked as naturally as bijective ones.
  Evaluating likelihoods is seemingly intractable since constructing flows with a closed-form volumechange term is significantly more challenging than in the square case, even if the relevant matrix is now d⇥ d instead of D ⇥D. Brehmer and Cranmer [8] thus propose a two-step training procedure to promote tractability wherein f✓ and h⌘ are trained separately. After observing that there is no term encouraging x 2M✓, and that x 2M✓ () x = g (g† (x)) () x = f✓(f † ✓ (x)), they decide to simply train f✓ by minimizing the reconstruction error to encourage the observed data to lie on M✓:
  ✓⇤ = argmin ✓
  nX
  i=1
  xi f✓ ⇣ f†✓ (xi) ⌘ 2
  2 . (6)
  Note that the above requires computing both f✓ and f†✓ , so that f̃✓ should be chosen as a flow allowing fast evaluation of both f̃✓ and f̃ 1✓ . Architectures such as the Real NVP [15] or follow-up work [28, 16] are thus natural choices for f̃✓, while architectures with an autoregressive component [45, 30] should be avoided. Then, since h⌘ does not appear in the challenging determinant term in (5), h⌘ can be chosen as any normalizing flow, and optimization – for a fixed ✓ – can be tractably achieved by maximum likelihood over the lower-dimensional space:
  ⌘⇤ = argmax ⌘
  nX
  i=1
  n log pZ ⇣ g† (xi) ⌘ log detJ[h⌘] ⇣ g† (xi) ⌘ o . (7)
  In practice, gradient steps in ✓ and ⌘ are alternated. This entire procedure circumvents evaluation of the Jacobian-transpose-Jacobian determinant term in (5), but as we show in section 3, avoiding this term by separately learning the manifold and the density on it comes with its downsides. We then show how to tractably estimate this term in section 4.
sections.heading: 3 Related Work and Motivation
sections.text: Low-dimensional and topological pathologies The mismatch between the dimension of the modelled support and that of the data-generating distribution has been observed throughout the literature in various ways. Dai and Wipf [13] show, in the context of variational autoencoders [29], that using flexible distributional approximators supported on RD to model data living in a low-dimensional manifold results in pathological behavior where the manifold itself is learned, but not the distribution on it. Cornish et al. [11] demonstrate the drawbacks of normalizing flows for estimating the density of topologically-complex data, and provide a new numerically stable method for learning NFs when the support is not homeomorphic to RD. However, this approach still models the support as being D-dimensional. Behrmann et al. [5] show instabilities associated with NFs – particularly a lack of numerical invertibility, as also explained theoretically by Cornish et al. [11]. This is not too surprising, as attempting to learn a smooth invertible function mapping RD to some low-dimensional manifold is an intrinsically ill-posed problem. This body of work strongly motivates the development of models whose support has matching topology – including dimension – to that of the true data distribution.
  Manifold flows A challenge to overcome for obtaining NFs on manifolds is the Jacobian-transposeJacobian determinant computation. Current approaches for NFs on manifolds approach this challenge in one of two ways. The first assumes the manifold is known beforehand [18, 53, 40], severely limiting applicability to low-dimensional data where the true manifold can realistically be known. The second group circumvents the computation of the Jacobian-transpose-Jacobian entirely through various heuristics. Kumar et al. [35] use a potentially loose lower bound of the log-likelihood, and do not explicitly enforce injectivity, resulting in a method for which the change-of-variables almost surely does not hold. Cunningham et al. [12] propose to convolve the manifold distribution with Gaussian noise, which results in the model having high-dimensional support. Finally, Brehmer and Cranmer [8] propose the method we described in subsection 2.2, where manifold learning and density estimation are done separately in order to avoid the log determinant computation. Concurrently to our work, Ross and Cresswell [54] proposed a rectangular flow construction which sacrifices some expressiveness but allows for exact likelihood evaluation.
  Why optimize the volume-change term? Learning f✓ and h⌘ separately without the Jacobian of f✓ is concerning: even if f✓ maps to the correct manifold, it might unnecessarily expand and contract volume in such a way that makes correctly learning h⌘ much more difficult than it needs to be. Looking ahead to our experiments, Figure 1 exemplifies this issue: the top-middle panel shows the ground truth density on a 1-dimensional circle in R2, and the top-right panel shows the distribution recovered by the two-step method of Brehmer and Cranmer [8]. We can see that, while the manifold is correctly recovered, the distribution on it is not. The bottom-right panel shows the speed at which f✓⇤ maps R to M✓⇤ : the top of the circle, which should have large densities, also has high speeds. Indeed, there is nothing in the objective discouraging f✓ to learn this behaviour, which implies that the corresponding low-dimensional distribution must be concentrated in a small region and thus making it harder to learn. The bottom-middle panel confirms this explanation: the learned low-dimensional distribution (dark red) does not match what it should (i.e. the distribution of {f†✓⇤(xi)} n i=1, in light red). This failure could have been avoided by learning the manifold in a density-aware fashion by including the Jacobian-transpose-Jacobian determinant in the objective.
sections.heading: 4 Maximum Likelihood for Rectangular Flows: Taming the Gradient
sections.heading: 4.1 Our Optimization Objective
sections.text: We have argued that including the Jacobian-transpose-Jacobian in the optimization objective is sensible. However, as we previously mentioned, (5) corresponds to the density of the projection of x onto M✓. Thus, simply optimizing the likelihood would not result in learning M✓ in such a way that observed data lies on it, only encouraging projected data points to have high likelihood. We thus maximize the log-likelihood subject to the constraint that the reconstruction error should be smaller than some threshold, i.e. ⇤ = argmax Pn i=1 log pX(xi) subject to Pn i=1 ||xi f✓(f † ✓ (xi))|| 2 2  .
  In practice, we use the KKT conditions [26, 34] and maximize the Lagrangian [7] instead:
  ⇤= argmax
  nX
  i=1
  ⇢ log pZ ⇣ g† (xi) ⌘ log detJ[h⌘] ⇣ g† (xi) ⌘ 1
  2 log det J>✓ (xi)J✓(xi) (8)
  xi f✓ ⇣ f†✓ (xi) ⌘ 2
  2
  ,
  where we treat > 0 as a hyperparameter rather than , and denote J[f✓](f†✓ (xi)) as J✓(xi) for simplicity. We have dropped the absolute value since J>✓ (xi)J✓(xi) is always symmetric positive definite, since J✓(xi) has full rank by injectivity of f✓. We now make a technical but relevant observation about our objective: since our likelihoods are Radon-Nikodym derivatives with respect to a Riemannian measure on M✓, different values of ✓ will result in different supports and dominating measures. One should thus be careful to compare likelihoods for models with different values of ✓. However, thanks to the smoothness of the objective over ✓, we should expect likelihoods for values of ✓ which are “close enough” to be comparable for practical purposes. In other words, comparisons remain reasonable locally, and the gradient of the volume-change term should contain relevant information to learn M✓ in such a way that also facilitates learning h⌘ on the pulled-back dataset {f†✓ (xi)} n i=1.
sections.heading: 4.2 Optimizing our Objective: Stochastic Gradients
sections.text: Note that all the terms in (8) are straightforward to evaluate and backpropagate through except for the third one; in this section we show how to obtain unbiased stochastic estimates of its gradient. In what follows we drop the dependence of the Jacobian on xi from our notation and write J✓, with the understanding that the end computation will be parallelized over a batch of xis. We assume access to an efficient matrix-vector product routine, i.e. computing J>✓ J✓✏ can be quickly achieved for any ✏ 2 Rd. We elaborate on how we obtain these matrix-vector products in the next section. It is a well known fact from matrix calculus [49] that:
  @
  @✓j log det J>✓ J✓ = tr
  ✓ (J>✓ J✓) 1 @
  @✓j J>✓ J✓
  ◆ , (9)
  where tr denotes the trace operator and ✓j is the j-th element of ✓. Next, we can use Hutchinson’s trace estimator [23], which states that for any matrix M 2 Rd⇥d, tr(M) = E✏[✏>M✏] for any Rd-valued random variable ✏ with zero mean and identity covariance matrix. We can thus obtain an unbiased stochastic estimate of our gradient as:
  @
  @✓j log det J>✓ J✓ ⇡
  1
  K
  KX
  k=1
  ✏>k (J > ✓ J✓)
  1 @
  @✓j J>✓ J✓✏k, (10)
  where ✏1, . . . , ✏K are typically sampled either from standard Gaussian or Rademacher distributions. Naïve computation of the above estimate remains intractable without explicitly constructing J>✓ J✓. Fortunately, the J>✓ J✓✏ terms can be trivially obtained using the given matrix-vector product routine, avoiding the construction of J>✓ J✓, and then @/@✓jJ > ✓ J✓✏ follows by taking the gradient w.r.t. ✓.
  There is however still the issue of computing ✏>(J>✓ J✓) 1 = [(J>✓ J✓) 1✏]>. We use conjugate gradients (CG) [43] in order to achieve this. CG is an iterative method to solve problems of the form Au = ✏ for given A 2 Rd⇥d (in our case A = J>✓ J✓) and ✏ 2 Rd; we include the CG algorithm in Appendix B for completeness. CG has several important properties. First, it is known to recover the solution (assuming exact arithmetic) after at most d steps, which means we can evaluate A 1✏. The solution converges exponentially (in the number of iterations ⌧ ) to the true value [55], so often ⌧ ⌧ d iterations are sufficient for accuracy to many decimal places. In practice, if we can tolerate a certain amount of bias, we can further increase computational speed by stopping iterations early. Second, CG only requires a method to compute matrix-vector products against A, and does not require access to A itself. One such product is performed at each iteration, and CG thus requires at most d matrix-vector products, though again in practice ⌧ ⌧ d products usually suffice. This results in O(⌧d2) solve complexity—less than the O(d3) required by direct inversion methods. We denote A 1✏ computed with conjugate gradients as CG(A; ✏). We can then compute the estimator from (10) as:
  @
  @✓j log det J>✓ J✓ ⇡
  1
  K
  KX
  k=1
  CG J>✓ J✓; ✏k > @ @✓j J>✓ J✓✏k. (11)
  In practice, we implement this term by noting that CG(J>✓ J✓; ✏) >@/@✓jJ>✓ J✓✏ = @/@✓jstop_gradient(CG(J>✓ J✓; ✏) >)J>✓ J✓✏, thereby taking advantage of the stop_gradient operation from Automatic Differentiation (AD) libraries and allowing us to avoid implementing a custom backward pass. We thus compute the contribution of a point x to the training objective as:
  log pZ ⇣ g† (x) ⌘ log detJ[h⌘] ⇣ g† (x) ⌘ x f✓ ⇣ f†✓ (x) ⌘ 2
  2 (12)
  1
  2K
  KX
  k=1
  stop_gradient ⇣ CG
  J>✓ J✓; ✏k >⌘ J>✓ J✓✏k
  which gives the correct gradient estimate when taking the derivative with respect to .
  Linear solvers for Jacobian terms We note that linear solvers like CG have been used before to backpropagate through log determinant computations in the context of Gaussian processes [17], and more recently for square NFs with flexible architectures which do not allow for straightforward Jacobian determinant computations [22, 39]. However, none of these methods require the Jacobiantranspose-Jacobian-vector product routine that we derive in the next section, and to the best of our knowledge, these techniques have not been previously applied for training rectangular NFs. We also point out that recently Oktay et al. [44] proposed a method to efficiently obtain stochastic estimates of J✓✏. While their method cannot be used as a drop-in replacement within our framework as it would result in a biased CG output, we believe this could be an interesting direction for future work. Finally, we note that CG has recently been combined with the Russian roulette estimator [25] to avoid having to always iterate d times while maintaining unbiasedness, again in the context of Gaussian processes [50]. We also leave the exploration of this estimator within our method for future work.
sections.heading: 4.3 AD Considerations: The Exact Method and the Forward-Backward AD Trick
sections.text: In this section we derive the aforementioned routine for vector products against J>✓ J✓, as well as an exact method that avoids the need for stochastic gradients (for a given x) at the price of increased memory requirements. But first, let us ask: why are these methods needed in the first place? There is work using power series to obtain stochastic estimates of log determinants [20, 9], and one might consider using them in our setting. However, these series require knowledge of the singular values of J>✓ J✓, to which we do not have access (constructing J > ✓ J✓ to obtain its singular values would defeat the purpose of using the power series in the first place), and we would thus not have a guarantee that the series are valid. Additionally, they have to be truncated and thus result in biased estimators, and using Russian roulette estimators to avoid bias [9] can result in infinite variance [11]. Finally, these series compute and backpropagate (w.r.t. ✓) through products of the form ✏>(J>✓ J✓)
  m✏ for different values of m, which can easily require more matrix-vector products than our methods. Behrmann et al. [4] address some of the issues with power series approximations as the result of controlling Lipschitz constants, although their estimates remain biased and potentially expensive.
  Having motivated our approach, we now use commonly-known properties of AD to derive it; we briefly review these properties in Appendix C, referring the reader to Baydin et al. [3] for more detail. First, we consider the problem of explicitly constructing J✓. This construction can then be used to evaluate J>✓ J✓ and exactly compute its log determinant either for log density evaluation of a trained model, or to backpropagate (with respect to ✓) through both the log determinant computation and the matrix construction, thus avoiding having to use stochastic gradients as in the previous section. We refer to this procedure as the exact method. Naïvely, one might try to explicitly construct J✓ using only backward-mode AD, which would require D vector-Jacobian products (vjps) of the form v>J✓ – one per basis vector v 2 RD (and then stacking the resulting row vectors vertically). A better way to explicitly construct J✓ is with forward-mode AD, which only requires d Jacobian-vector products (jvps) J✓✏, again one per basis vector ✏ 2 Rd (and then stacking the resulting column vectors horizontally). We use a custom implementation of forward-mode AD in the popular PyTorch [47] library2 for the exact method, as well as for the forward-backward AD trick described below.
  We now explain how to combine forward- and backward-mode AD to obtain efficient matrix-vector products against J>✓ J✓ in order to obtain the tractable gradient estimates from the previous section.
  2PyTorch has a forward-mode AD implementation which relies on the “double backward” trick, which is known to be memory-inefficient. See https://j-towns.github.io/2017/06/12/A-new-trick.html for a description.
  Note that v := J✓✏ can be computed with a single jvp call, and then J>✓ J✓✏ = [v >J✓]> can be efficiently computed using only a vjp call. We refer to this way of computing matrix-vector products against J>✓ J✓ as the forward-backward AD trick. We summarize both of our gradient estimators in Appendix D. Note that (12) requires K(⌧ + 1) such matrix-vector products, which is seemingly less efficient as it is potentially greater than the d jvps required by the exact method. However, the stochastic method is much more memory-efficient than its exact counterpart when optimizing over ✓: of the K(⌧ + 1) matrix-vector products needed to evaluate (12), only K require gradients with respect to ✓. Thus only K jvps and K vjps, along with their intermediate steps, must be stored in memory over a training step. In contrast, the exact method requires gradients (w.r.t. ✓) for every one of its d jvp computations, which requires storing these computations along with their intermediate steps in memory.
  Our proposed methods thus offer a memory vs. variance trade-off. Increasing K in the stochastic method results in larger memory requirements which imply longer training times, as the batch size must be set to a smaller value. On the other hand, the larger the memory cost, the smaller the variance of the gradient. This still holds true for the exact method, which results in exact gradients, at the cost of increased memory requirements (as long as K ⌧ d; if K is large enough the stochastic method should never be used over the exact one). Table 1 summarizes this trade-off.
sections.heading: 5 Experiments
sections.text: We now compare our methods against the two-step baseline of Brehmer and Cranmer [8], and also study the memory vs. variance trade-off. We use the real NVP [15] architecture for all flows, except we do not use batch normalization [24] as it causes issues with vjp computations. We point out that all comparisons remain fair, and we include a detailed explanation of this phenomenon in Appendix E, along with all experimental details in Appendix G. Throughout, we use the abbreviations RNFs-ML for our maximum likelihood training method, RNFs-TS for the two-step method, and RNFs for rectangular NFs in general. For most runs, we found it useful to anneal the likelihood term(s). That is, at the beginning of training we optimize only the reconstruction term, and then slowly incorporate the other terms. This likelihood annealing procedure helped avoid local optima where the manifold is not recovered (large reconstruction error) but the likelihood of projected data is high.
sections.heading: 5.1 Simulated Data
sections.text: We consider a simulated dataset where we have access to ground truth, which allows us to empirically verify the deficiencies of RNFs-TS. We use a von Mises distribution, which is supported on the one-dimensional unit circle in R2. Figure 1 shows this distribution, along with its estimates from RNFs-ML (exact) and RNFs-TS. As previously observed, RNFs-TS correctly approximate the manifold, but fail to learn the right distribution on it. In contrast we can see that RNFs-ML, by virtue of including the Jacobian-transpose-Jacobian term in the optimization, manage to recover both the manifold and the distribution on it (top left panel), while also resulting in an easier-to-learn lowdimensional distribution (bottom middle panel) thanks to f✓⇤ mapping to M✓⇤ at a more consistent speed (bottom left panel). We do point out that, while the results presented here are representative of usual runs for both methods, we did have runs with different results which we include in Appendix G for completeness. We finish with the observation that even though the line and the circle are not homeomorphic and thus RNFs are not perfectly able to recover the support, they manage to adequately approximate it.
  Table 2: FID-like metric for tabular data (lower is better). Bolded runs are the best or overlap with it.
  Method POWER GAS HEPMASS MINIBOONE
  RNFs-ML (exact) 0.067± 0.016 0.138± 0.023 0.486± 0.032 0.978± 0.082 RNFs-ML (K = 1) 0.083± 0.015 0.110± 0.021 0.779± 0.191 1.001± 0.051 RNFs-ML (K = 10) 0.113± 0.037 0.140± 0.013 0.495± 0.055 0.878± 0.083 RNFs-TS 0.178± 0.024 0.161± 0.016 0.649± 0.081 1.085± 0.062
sections.heading: 5.2 Tabular Data
sections.text: We now turn our attention to the tabular datasets used by Papamakarios et al. [45], now a common benchmark for NFs as well. As previously mentioned, one should be careful when comparing models with different supports, as we cannot rely on test likelihoods as a metric. We take inspiration from the FID score [21], which is commonly used to evaluate quality of generated images when likelihoods are not available. The FID score compares the first and second moments of a well-chosen statistic – taken in practice to be the values of the last hidden layer of a pre-trained inception network [56] – from the model and data distributions using the squared Wasserstein-2 metric (between Gaussians). Here, we take the statistic to be the data itself instead of the final hidden units of a pre-trained classifier: in other words, our metric compares the mean and covariance of generated data against those of observed data with the same squared Wasserstein-2 metric. We include the mathematical formulas for computing both FID and our modified version for tabular data in Appendix F. We use early stopping with our FID-like score across all models. Our results are summarized in Table 2, where we can see that RNFs-ML consistently do a better job at recovering the underlying distribution. Once again, these results emphasize the benefits of including the Jacobian-transpose-Jacobian in the objective. Interestingly, except for HEPMASS, the results from our stochastic version with K = 1 are not significantly exceeded by the exact version or using a larger value of K, suggesting that the added variance does not result in decreased empirical performance. We highlight that no tuning was done (except on GAS for which we changed d from 4 to 2), RNFs-ML outperformed RNFs-TS out-of-the-box here (details are in Appendix G). We report training times in Appendix G, and observe that RNFs-ML take a similar amount of time as RNFs-TS to train for datasets with lower values of D, and while we do take longer to train for the other datasets, our training times remain reasonable and we often require fewer epochs to converge.
sections.heading: 5.3 Image Data and Out-of-Distribution Detection
sections.text: We also compare RNFs-ML to RNFs-TS for image modelling on MNIST and FMNIST. We point out that these datasets have ambient dimension D = 784, and being able to fit RNFs-ML is in itself noteworthy: to the best of our knowledge no previous method has scaled optimizing the Jacobiantranspose-Jacobian term to these dimensions. We use FID scores both for comparing models and for early stopping during training. We also used likelihood annealing, with all experimental details again given in Appendix G. We report FID scores in Table 3, where we can see that we outperform RNFs-TS. Our RNFs-ML (K = 1) variant also outperforms its decreased-variance counterparts. This initially puzzling behaviour is partially explained by the fact that we used the K = 1 variant to tune the model (being the cheapest one to train), and then used the tuned hyperparameters for a single run of the other two variants. Nonetheless, once again these results suggest that the variance induced by our stochastic method is not empirically harmful, and that while using the exact method should be the default whenever feasible, using K = 1 otherwise is sensible. We also report training times where we can see the computational benefits of our stochastic method, as well as visualizations of samples, in Appendix G.
  We also compare performance on the CIFAR-10 dataset [33], for which D = 3,072. Once again, being able to fit RNFs-ML in this setting is in itself remarkable. We do not include RNFs-ML (K = 4) results because of limited experimentation on CIFAR-10 due to computational cost (experimental details, including hyperparameters which we tried, are given in Appendix G). We can see that, while RNFs-TS outperformed RNFs-ML (K = 1) – which we hypothesize might be reversed given more tuning – our RNFs-ML (exact) version is the best performing model, yet again highlighting the importance of including the change-of-volume term in the objective.
  We further evaluate the performance of RNFs for OoD detection. Nalisnick et al. [41] pointed out that square NFs trained on FMNIST assign higher likelihoods to MNIST than they do to FMNIST. While there has been research attempting to fix this puzzling behaviour [1, 2, 10, 51], to the best of our knowledge no method has managed to correct it using only likelihoods of trained models. Figure 2 shows that RNFs remedy this phenomenon, and that models trained on FMNIST assign higher test likelihoods to FMNIST than to MNIST. This correction does not come at the cost of strange behaviour now emerging in the opposite direction (i.e. when training on MNIST, see Appendix G for a histogram). Table 3 quantifies these results (arrows point from in-distribution datasets to OoD ones) with the accuracy of a decision stump using only log-likelihood, and we can see that the best-performing RNFs models essentially solve this OoD task. While we leave a formal explanation of this result for future work, we believe this discovery highlights the importance of
  properly specifying models and of ensuring the use of appropriate inductive biases, in this case low intrinsic dimensionality of the observed data. The strong performance of RNFs-TS here seems to indicate that this is a property of RNFs rather than of our ML training method specifically, although our exact approach is still used to compute these log-likelihoods at test time. We include additional results on OoD detection using reconstruction errors – along with a discussion – in Appendix G, where we found the opposite unexpected behaviour: FMNIST always has smaller reconstruction errors, regardless of which dataset was used for training.
sections.heading: 6 Scope and Limitations
sections.text: In this paper we address the dimensionality-based misspecification of square NFs while properly using maximum likelihood as the training objective, thus providing an advancement in the training of RNFs. Our methods however remain topologically misspecified: even though we can better address dimensionality, we can currently only learn manifolds homeomorphic to Rd. For example, one could conceive of the MNIST manifold as consisting of 10 connected components (one per digit), which cannot be learned by f✓. It is nonetheless worth noting that this limitation is shared by other deep generative modelling approaches, for example GANs [19] result in connected supports (since the image of a connected set under a continuous function is connected). We observed during training in image data that the residuals of CG were not close to 0 numerically, even after d steps, indicating poor conditioning and thus possible numerical non-invertibility of the matrix J>✓ J✓. We hypothesize that this phenomenon is caused by topological mismatch, which we also conjecture affects us more than the baseline as our CG-obtained (or from the exact method) gradients might point in an inaccurate direction. We thus expect our methods in particular to benefit from improved research on making flows match the target topology, for example via continuous indexing [11].
  Additionally, while we have successfully scaled likelihood-based training of RNFs far beyond current capabilities, our methods – even the stochastic one – remain computationally expensive for higher dimensions, and further computational gains remain an open problem. We also attempted OoD detection on CIFAR-10 against the SVHN dataset [42], and found that neither RNFs-ML nor RNFsTS has good performance, although anecdotally we may have at least improved on the situation outlined by Nalisnick et al. [41]. We hypothesize these results might be either caused by topological mismatch, or corrected given more tuning.
sections.heading: 7 Conclusions and Broader Impact
sections.text: In this paper we argue for the importance of likelihood-based training of rectangular flows, and introduce two methods allowing to do so. We study the benefits of our methods, and empirically show that they are preferable to current alternatives. Given the methodological nature of our contributions, we do not foresee our work having any negative ethical implications or societal consequences.
sections.heading: Acknowledgements
sections.text: We thank Brendan Ross, Jesse Cresswell, and Maksims Volkovs for useful comments and feedback. We would also like to thank Rob Cornish for the excellent CIFs codebase upon which our code is built, and Emile Mathieu for plotting suggestions. GP and JPC are supported by the Simons Foundation, McKnight Foundation, the Grossman Center, and the Gatsby Charitable Trust.
title: Rectangular Flows for Manifold Learning