Sameera Ramasinghe∗[email protected] \addauthorKasun Fernando∗[email protected] \addauthorSalman [email protected] \addauthorNick [email protected] \addinstitution Australian National University \addinstitution University of Toronto \addinstitution Mohamed bin Zayed University of AI A Robust NF using Bernstein-type Polynomials
A Robust Normalizing Flow using Bernstein-type Polynomials
Abstract
Modeling real-world distributions can often be challenging due to sample data that are subjected to perturbations, e.g., instrumentation errors, or added random noise. Since flow models are typically nonlinear algorithms, they amplify these initial errors, leading to poor generalizations. This paper proposes a framework to construct Normalizing Flows (NFs) which demonstrate higher robustness against such initial errors. To this end, we utilize Bernstein-type polynomials inspired by the optimal stability of the Bernstein basis. Further, compared to the existing NF frameworks, our method provides compelling advantages like theoretical upper bounds for the approximation error, better suitability for compactly supported densities, and the ability to employ higher degree polynomials without training instability. We conduct a theoretical analysis and empirically demonstrate the efficacy of the proposed technique using experiments on both real-world and synthetic datasets.
1 Introduction
Modeling the probability distribution of a set of observations, i.e., generative modeling, is a crucial task in machine learning. It enables the generation of synthetic samples using the learned model and allows the estimation of the likelihood of a data sample. This field has met with great success in many problem domains including image generation (Ho et al., 2019; Kingma and Dhariwal, 2018; Lu and Huang, 2020), audio synthesis (Esling et al., 2019; Prenger et al., 2019), reinforcement learning (Mazoure et al., 2020; Ward et al., 2019), noise modeling (Abdelhamed et al., 2019), and simulating physics experiments (Wirnsberger et al., 2020; Wong et al., 2020). In the recent past, deep neural networks such as generative adversarial networks (GANs) and variational autoencoders (VAEs) have been widely adopted in generative modeling due to their success in modeling high dimensional distributions. However, they entail several limitations: 1) exact density estimation of arbitrary data points is not possible, and 2) training can be cumbersome due to aspects such as mode collapse, posterior collapse and high sensitivity to architectural design of the model (Kobyzev et al., 2020).
In contrast, normalizing flows (NFs) are a category of generative models that enable exact density computation and efficient sampling (for theoretical foundations see Appendix 1.1 and references therein). As a result, NFs have been gaining increasing attention from the machine learning community since the seminal work of Rezende and Mohamed (2015). In essence, NFs consist of a series diffeomorphisms that transforms a simple distribution into a more complex one, and must be designed so that the Jacobian determinants of these diffeomorphisms can be efficiently calculated (This is, in fact, an essential part of the implementation). To this end, two popular approaches have been proposed so far: 1) efficient determinant calculation methods such as Berg et al. (2018); Grathwohl et al. (2018); Lu and Huang (2020), and 2) triangular maps (Jaini et al., 2019; Dinh et al., 2014, 2016). The key benefit of triangular maps is that their Jacobian matrices are triangular, and hence, the calculation of Jacobian determinants takes only steps as opposed to the complexity of the computation of a determinant of an unconstrained matrix. In this paper, we focus only on triangular maps.
On the one hand, it is not a priori clear whether such a constrained class of maps is expressive enough to produce sufficiently complex transformations. Interestingly, (Bogachev et al., 2005) showed that, given two probability densities, there exists a unique increasing triangular map that transforms one density to the other. Consequently, the constructed NFs should be universal, i.e., dense in the class of increasing triangular maps, in order to approximate those density transformations with arbitrary precision. But it is observed in Jaini et al. (2019) that, despite many NFs being triangular, they are not universal. To remedy this, most have reverted to the empirical approach of stacking several transformations together, thereby increasing the expressiveness of the model. Alternatively, there are NFs that use genuinely universal transformations. Many such methods employ coupling functions based on polynomials, e.g., sum-of-squares (SOS) polynomials in Jaini et al. (2019), cubic splines in Durkan et al. (2019a) or rational quadratic splines in Durkan et al. (2019b). Here, we employ another class of polynomials called Bernstein-type polynomials to construct a universal triangular flow which henceforth is called Bernstein-type NF. Our universality proof is a consequence of Bernstein (1912), and unlike the proofs in the previous literature, is constructive, and hence, yields analytic expressions for approximations of known density transformations; see Section 2.4.
On the other hand, noise is omnipresent in data. Sample data can be subjected to perturbations due to experimental uncertainty (instrumentation errors or added random noise). It is well-known that nonlinear systems amplify these initial errors and produce drastically different outcomes even for small changes in the input data; see Taylor (1982); Higham (1996); Lanckriet et al. (2002). In terms of (deep) classifiers, robustness is often studied in the context of adversarial attacks, where the performance of the classifier should be robust against specific perturbations of the inputs. Similarly, for generative models, this translates to robustly modeling a distribution in the presence of perturbed data. Recently, Condessa and Kolter (2020) analyzed the robustness of deep generative models against random perturbations of the inputs, where they designed a VAE variant that is robust to random perturbations. Similarly, Kos et al. (2018) also proposed a heuristic-based method to make deep generative models robust against perturbations of the inputs.
As any other nonlinear model, NFs are also susceptible of numerical instabilities. Unless robust, trained NFs may amplify initial errors, and demonstrate out-of-distribution sample generation and poor generalization to unseen data. For instance, consider an NF modeling measured or generated velocities (energies) of molecular movements; see Köhler et al. (2020). Similarly, consider a scenario where we intend to flag certain samples of a random process as out-of-distribution data. If the training data is susceptible to noise, the measured log-likelihoods of the test samples may significantly deviate from the true values unless the NF model is robust.
Therefore, it is imperative that the robustness of NFs is investigated during their construction and implementation. Despite this obvious importance, robustness of NFs has not been theoretically or even experimentally studied in the previous literature, unlike other deep generative models. One of the key motivations behind this work is to fill this void. Accordingly, we show that Bernstein-type polynomials are ideal candidates for the construction of NFs that are not only universal but also robust. Robustness of Bernstein-type NFs follow from the optimal stability of the Bernstein basis (Farouki and Goodman, 1996; Farouki and Rajan, 1987); see also, Section 2.5.
Recently, Bernstein polynomials have also been used in conditional transformation models to due to their versatility; see for example, Hothorn et al. (2018), Hothorn and Zeileis (2021), Baumann et al. (2021) and references therein. In contrast, here, we introduce a novel approach of building NFs using Bernstein polynomials.
In summary, apart from collecting, organizing and summarising in a coherent fashion the appropriate theoretical results which were scattered around the mathematical literature, we 1) deduce, in Theorem 3, the universality of Bernstein flows, 2) state and prove, in Theorem 2, a strict monotonicity result of Bernstein polynomials which has been mentioned without proof and used in Farouki (2000), 3) prove, in Theorem 1, that, in any NF, it is enough to consider compactly supported targets (in the previous literature was implicitly assumed without proper justification), 4) theoretically establish that, compared to other polynomial-based flow models, Bernstein-type NFs demonstrate superior robustness to perturbations in data. To our knowledge, ours is the first work to discuss robustness in NFs, 5) discuss a theoretical bound for the rate of convergence of Bernstein-type NFs, which, to our knowledge, has not been discussed before in the context of NFs, and 6) propose a practical framework to construct normalizing flows using Bernstein-type polynomials and empirically demonstrate that theoretically discussed properties hold in practice.
Moreover, compared to previous NF models, our method has several additional advantages such as suitability for approximating compactly supported target densities; see Section 2.2, the ability to increase the expressiveness by increasing the polynomial degree at no cost to the training stability; see Section 2.2, and being able to invert easily and accurately due to the availability of efficient root finding algorithms; see Section 2.3.
2 Theoretical foundations of the Bernstein-type NF
Here, we elaborate on the desirable properties of Berstein-type polynomials and their implication to our NF model. The mathematical results taken directly from existing literature are stated as facts with appropriate references. The proofs of Theorems 1, 2 and 3, appear in Appendix 2. Also, in each subsection, we point out the advantages of our model (over existing models) based on the properties discussed. We point the reader to Appendix 1.1 for a brief discussion on triangular maps and other preliminaries.
2.1 Bernstein-type polynomials
The degree Bernstein polynomials, , were first introduced by Bernstein in his constructive proof of the Weierstrass theorem in Bernstein (1912). In fact, given a continuous function , its degree Bernstein approximation, , given by
(1) |
is such that uniformly in as . Moreover, Bernstein polynomials form a basis for degree polynomials on . More generally, polynomials of Bernstein-type can be defined as follows.
Definition 1.
A degree polynomial of Bernstein-type is a polynomial of the form
(2) |
where , are some real constants.
Remark 1.
Polynomials of Bernstein-type on an arbitrary closed interval are defined by composing with the linear map that sends to , So, Bernstein-type polynomials on take the form . Hereafter, we denote degree Bernstein-type polynomials by regardless of the domain.
As we shall see below, one can control various properties of Bernstein-type polynomials like strict monotonicity, range and universality by specifying conditions on the coefficients, and the error of approximation depends on the degree of the polynomials used.
2.2 Easier control of the range and suitability for compact targets
The supports of distributions of samples used when training and applying NFs are not fixed. So, it is important to be able to easily control the range of the coupling functions. In the case of Bernstein-type polynomials, s, this is very straightforward. Note that if is defined on , then and . Therefore, one can fix the values of a Bernstein-type polynomial at the end points of by fixing and . So, if is increasing (which will be the case in our model; see Section 2.3), then its range is . This translates to a significant advantage when training for compactly supported targets because we can achieve any desired range (the support of the target) by fixing and and letting only vary. So, s are ideal for modeling compactly supported targets. In fact, in most other methods except splines in Durkan et al. (2019a, b), either there is no obvious way to control the range or the range is infinite. We present the following theorem to establish that for the purpose of training, we can assume the target has compact support (up to a known diffeomorphism).
Theorem 1.
Let be measurable subsets of . Suppose is the support of the target , is the support of the prior , is the class of coupling functions with ranges contained in and is a diffeomorphism. If is the distribution on such that , then
(3) |
In the previous literature that uses transformations with compact range, this fact was implicitly assumed without proper justification. As a consequence of the above theorem, our coupling functions having finite ranges is not a restriction, and in any NF model, even if the target density is not compactly supported, the learning procedure can be implemented by first converting the target density to a density with a suitable compact support via a diffeomorphism, and then training on the transformed data. Since we deal with compactly supported targets, in practice, we do not need to construct deep architectures (with a higher number of layers), as we can increase the degree of the polynomials to get a better approximation. In other polynomial based methods, a practical problem arises because the higher order polynomials could predict extremely high values initially leading to unstable gradients (e.g., Jaini et al. (2019)). In contrast, we can avoid that problem as the range of our transformations can be explicitly controlled from the beginning by fixing and .
2.3 Strict monotonicity and efficient inversion
In triangular flows, the coupling maps are expected to be invertible. Since strict monotonocity implies invertibility, it is sufficient that the s we use are strictly monotone.
Theorem 2.
Consider the Bernstein-type polynomial in (2). Suppose . Then, is strictly increasing on .
This result was mentioned as folklore without proof and used in Farouki (2000). On the other hand, in Lindvall (2002), the conclusion is stated with monotonicity and not strict monotonicity (which is absolutely necessary for invertibility). Hence, we added a complete proof of the statement in Appendix 2. According to this result, the strict monotonicity of s depends entirely on the strict monotonicity of the coefficients s. It is easy to see that the assumption of strict monotonicity of the coefficients is not a further restriction on the optimization problem. For example, if the required range is , we can take where s are real valued. This converts the constrained problem of finding s to an unconstrained one of finding s. Alternatively, we can take and , and after each iteration, linearly scale s in such a way that . After guaranteeing invertibility, we focus on computing the inverse, i.e., at each iteration, given we solve for ,
(4) |
because Bernstein polynomials form a partition of unity on . So, finding inverse images, i.e., solving the former is equivalent to finding solutions to the latter. Due to our assumption of increasing s, is increasing, and has at most one root on . The condition (which can be easily checked) guarantees the existence of a unique solution, and hence, the invertibility of the original transformation.
Due to the extensive use of Bernstein-type polynomials in computer-aided geometric design, there are several well-established efficient root finding algorithms at our disposal (Spencer, 1994). For example, the parabolic hull approximation method in Rajan et al. (1988) is ideal for higher degree polynomials with fewer roots (in our case, just one) and has cubic convergence for simple roots (better than both the bijection method and Newton’s method). Further, because of the numerical stability described in Section 2.5 below, the use of Bernstein-type polynomials in our model minimizes the errors in such root solvers based on floating–point arithmetic. Even though inverting splines are easier due to the availability of analytic expressions for roots, compared to all other other NF models, we have more efficient and more numerically stable algorithms that allow us to reduce the cost of numerical inversion in our setting.
2.4 Universality and the explicit rate of convergence
In order to guarantee universality of triangular flows, we need to use a class of coupling functions that well-approximates increasing continuous functions. This is, in fact, the case for s, and hence, we have the following theorem whose proof we postpone to Appendix 2.
Theorem 3.
Bernstein-type normalizing flows are universal.
The basis of all the universality proofs of NFs in the existing literature is that the learnable class of functions is dense in the class of increasing continuous functions. In contrast, the argument we present here is constructive. As a result, we can write down sequences of approximations for (known) transformations between densities explicitly; see Appendix 4.
In the case of cubic-spline NFs of Durkan et al. (2019a), it is known that for and , when the transformation is times continuously differentiable and the bin size is , the error is (Ahlberg et al., 1967, Chapter 2). However, we are not aware of any other instance where an error bound is available. Fortunately for us, the error of approximation of a function by its Bernstein polynomials has been extensively studied. We recall from Voronovskaya (1932) the following error bound: for twice continuously differentiable
(5) |
and this holds for an arbitrary interval with replaced by . Since the error estimate is given in terms of the degree of the polynomials used, we can improve the optimality of our NF by avoiding unnecessarily high degree polynomials. This allows us to keep the number of trainable parameters under control in our NF model. It can be shown that the error above does not necessarily improve when SOS polynomials are used instead; see Appendix 3. In our NF, at each step, the estimation is done using a univariate polynomial, and hence, the overall convergence rate is, in fact, the minimal univariate convergence rate of (equivalently, the error upper bound is the maximum of univariate upper bounds), and in general, cannot be improved further regardless of how regular the density transformation is. However, our experiments (in Section 4.3) show that our model on average has a significantly smaller error than the given theoretical upper-bound.
2.5 Robustness of Bernstein-type normalizing flows
In this section, we recall some known results in Farouki and Goodman (1996); Farouki and Rajan (1987) about the optimal stability of the Bernstein basis. The two key ideas are that smaller condition numbers lead to smaller numerical errors and that the Bernstein basis has the optimal condition numbers compared to other polynomial bases.
To illustrate this, let be a polynomial on of degree expressed in terms of a basis , i.e.,
(6) |
Let be randomly perturbed, with perturbations where the relative error . Then the total pointwise perturbation is
(7) |
where is the condition number for the total perturbation with respect to the basis . It is clear that controls the magnitude of the total perturbation.
According to Farouki and Goodman (1996), if and are non-negative bases for polynomials of degree on , and for all , latter is a non-negative linear combination of the former, that is, with . Then, for any polynomial ,
(8) |
For , the Bernstein polynomials and the power monomials, , are non-negative bases on . It is true that the latter is a positive linear combination of the former but not vice-versa; see Farouki and Goodman (1996). Therefore, Bernstein polynomial basis has the lowest condition number out of the two. This means that the change in the value of a polynomial caused by a perturbation of coefficients is always smaller in the Bernstein basis than in the power basis. A more involved computation gives
(9) |
as the condition number that controls the computational error for a fold root of in ; see Farouki and Rajan (1987). There, it is proved that if and denote the condition numbers for finding roots of any polynomial on in the power and the Bernstein bases on , respectively, then for and . This means that the change in the value of a root of a polynomial caused by a perturbation of coefficients is always smaller in the Bernstein basis than in the power basis.
In fact, a universal statement is true: Among all non-negative basis on a given interval, the Bernstein polynomial basis is optimally stable in the sense that no other non-negative basis gives smaller condition numbers for the values of polynomials (see (Peña, 1997, Theorem 2.3)) and no other basis expressible as non-negative combinations of the Bernstein basis gives smaller condition numbers for the roots of polynomials (see (Farouki and Goodman, 1996, Section 5.3)).
In particular, s are systematically more stable than the polynomials in the power form when determining roots (for example, when inverting) and evaluation (for example, when finding image points). As a result, when polynomials are used to construct NFs (for example, Q-NSF based on quadratic or cubic splines, SOS based on some of square polynomials and our NF based on Bernstein-type polynomials, ours yields the most numerically stable NF, i.e., it is theoretically impossible for them to be more robust. Our experiments in Section 4.2, while confirming this, demonstrate that our method outperforms even the NFs that are not based on polynomials.
3 Construction of the Bernstein-type normalizing flow

In this section, we describe the construction of normalizing flows using the theoretical framework established in Section 2 for compactly supported targets. For this, we employ a MADE style network (Germain et al., 2015). Consider a -dimensional source and a -dimensional target . Then, the element-wise mapping between the components and is approximated using a Bernstein-type polynomial as . We obtain the parameters of using a neural network which is conditioned on . This ensures a triangular mapping between the distributions. We fix and to be constants, and thus, define the range of each transformation; see Section 2.2. Moreover, as per Theorem 2, s need to be strictly increasing for a transformation to be strictly increasing. However, when we convert this constrained problem to an unconstrained one as proposed in Section 2.3, we obtain s using the neural network and then calculate s as described.
For each , we employ a fully-connected neural net with three layers to obtain the parameters, except in the case of in which we directly optimize the parameters. Figure 1 illustrates a model architecture with layers and degree polynomials for -dimensional distributions. Here, there are variable coefficients altogether. We use maximum likelihood to train the model with a learning rate with a decay factor of per iterations. All the weights are initialized randomly using a standard normal distribution.
4 Experiments
In this section, we summarise our empirical evaluations of the proposed model based on both real-world and synthetic datasets and compare our results with other NF methods.
4.1 Modeling sample distributions
Model | Power | Gas | Hepmass | MiniBoone | BSDS300 | |
---|---|---|---|---|---|---|
FFJORD | ||||||
GLOW | ||||||
MAF | ||||||
NAF | ||||||
BLOCK-NAF | ||||||
RQ-NSF (AR) | ||||||
Q-NSF (AR) | ||||||
SOS | ||||||
BERNSTEIN |
Model | MNIST | CIFAR10 |
---|---|---|
Real-NVP | ||
FFJORD | ||
GLOW | ||
MAF | ||
MADE | ||
SOS | ||
BERNSTEIN |
We conducted experiments on four datasets from the UCI machine-learning repository and BSDS300 dataset. Table 1 compares the obtained test log-likelihood against recent flow-based models. As illustrated, our model achieves competitive results on all of the five datasets. We observe that our model consistently reported a lower standard deviation which may be attributed to the robustness of our model.
We also applied our method to two low-dimensional image datasets, CIFAR10 & MNIST. The results are reported in Table 2. Among the methods that do not use multi-scale convolutional architectures, we obtain the optimal results. In addition, we tested our model on several toy datasets (shown in Figure 3). Note that these 2D datasets contain multiple modes, sharp jumps and are not fully supported. So, the densities are not that obvious to learn. Despite the difficulties, our model is able to estimate the given distributions in a satisfactory manner.


4.2 Robustness
In order to experimentally verify that Bernstein-type NFs are more numerically stable than other polynomial based NFs (as claimed in Section 2.5) we use a standard idea in the literature; see Taylor (1982).
We add i.i.d. noise, sampled from a Uniform, to the five datasets included in Table 1, and measure the change in the test log-likelihood as a fraction of the standard deviation (so that the change is in terms of standard deviations). In practice, values of the experimented datasets are rescaled to a magnitude around unity. In signal processing, a good SNR is considered to be above 40DB which is used in most real-world cases. Here, we have chosen a noise order of because our intention is to demonstrate that a SNR level below or even around that range can affect the performance of NFs.
For a fair comparison, we train all the models from scratch on the noise-free train set using the codes provided by the authors, strictly following the instructions in the original works to the best of our ability. Then, we test the models on the noise-free test set. We run the above experiment times to obtain the standard deviation and mean of the test log-likelihood. Next, we add noise to the training set, retrain the model, and obtain the test log-likelihood on the noise-free test set. Finally, we obtain the metric which we report in Table 3.
Model | Power | Gas | Hepmass | MiniBoone | BSDS300 |
---|---|---|---|---|---|
FFJORD | |||||
Real-NVP | |||||
GLOW | |||||
NAF | |||||
MAF | |||||
MADE | |||||
RQ-NSF | |||||
SOS | |||||
BERNSTEIN |
As expected, Bernstein NF demonstrate the lowest relative change in performance, implying the robustness against random initial errors. In fact, other models are not robust: even small initial errors consistently (at least in 4 out of 5 datasets) created changes larger than (corresponding to the two % tails of the distribution of errors) where is the original standard deviation of error. In comparison, the change in our NF consistently (4 out of 5) was well-within the acceptable range and is at most . In the remaining dataset, change in our model is while in all other models it’s more than
4.3 Validation of the theoretical error upper-bound
The degree Bernstein approximation of has an error upper-bound
(10) |
where (Bustamante, 2017, Chapter 4). Now, we verify this using a Kumarswamy distribution as the prior and Uniform as the target. Let and be the learned degree Bernstein-type polynomial. The average error, obtained using the learned s and satisfying
(11) |
are plotted in Figure 3. It shows that the observed (average) error is smaller than this theoretical upper-bound. In the NF, we have used a single layer and increased the degree of the polynomial from 10 to 100. The NF model was stable even when the degree 100 polynomial was used. So, this experiment also demonstrates that our model is, in fact, stable even when higher degree polynomials are used (as claimed in Section 2.2).
5 Conclusion
We propose a novel method to construct a universal autoregressive NFs with Bernstein-type polynomials as the coupling functions, and is the first instance of robustness of NFs being discussed. We show that Bernstein-type NFs posses advantages like true universality, robustness against initial and round-off errors, efficient inversion, having an explicit convergence rate, and better training stability for higher degree polynomials.
Appendix
6 Preliminaries
In this section, we describe the general set up of triangular normalizing flow models.
6.1 Normalizing flows and triangular maps
NFs learn an invertible mapping between a prior and a more complex distribution (the target) in the same dimension. Typically, the prior is chosen to be a Gaussian with identity covariance or uniform on the unit cube, and the target is the one we intend to learn. Below, we present a summary of related ideas and refer the readers to Jaini et al. (2019) and Kobyzev et al. (2020) for a comprehensive discussion.
More formally, let z and x be sampled data from the prior with density and the target distribution with density , respectively. Then, NFs learn a transformation such that which is differentiable and invertible with a differentiable inverse. Such transformations are called diffeomorphisms and they allow the estimation of the probability density via the change of variables formula where is the Jacobian determinant of .
Given an independent and identically distributed (i.i.d.) sample with law , learning the target density and the transformation (within an expressive function class ) is done simultaneously via minimizing the Kullback-Leibler (KL) divergence between and the pushforward of under denoted by ,
(12) |
Density estimation using (12) requires efficient calculation of the Jacobian as well as . Both can be achieved via constraining to be an increasing triangular map. That is, taking to be a multivariate distribution where , and the prior where , the components of x are expressed as for suitably defined transformations where is increasing with respect to . From now on, we denote by . In this case, the Jacobian determinant is the product . Also, because is increasing in , inversion can be done recursively starting from .
7 Proofs
Proof of Theorem 1.
To illustrate the relevance of the theorem to our setting, we write down the details of the proof assuming that the learnable class is Bernstein-type polynomials. The same proof is true for any class of functions.
Take for with with the possibility that or whence the interval is understood to be open on the infinite end and the target may have non-compact support. Let be the learnable Bernstein-type polynomial with coeffecients . Let be a fixed invertible transformation so that transforms the target density to supported on , i.e., , and
(13) |
Fix , and let Then the optimization problem is
(14) | ||||
(15) | ||||
(16) | ||||
(17) | ||||
(18) | ||||
(19) | ||||
(20) |
Note that the second integral in (17) can be taken outside the because it is independent of , and hence, it becomes a constant that is irrelevant for the optimization. From (20), it follows that the minimum of is achieved if and only if the minimum of is achieved. Hence,
(21) |
as required. It is easy to see that this argument remains unchanged when is replaced by and is replaced by . ∎
Proof of Theorem 2.
There is a probabilistic interpretation of Bernstein polynomials that makes the analysis easier. Let , be i.i.d. Bernoulli random variables. Then
(22) |
See, for example, Chapter 2 of Bustamante (2017). We will use this definition in the proof.
Let be a strictly increasing continuous function such that . Let and let and be a sequence of iid Bernoulli for , defined on the same probability space such that via monotone coupling. That is, let and where is a uniform random variables on and couple them as follows.
(23) |
and . So, as required.
Proof of Theorem 3.
Recall From Bernstein (1912) that s are uniformly dense in the space of continuous function on because uniformly. By rescaling, this is true on any interval . Moreover, by construction, whenever is increasing, is increasing. So, it is automatic that increasing Bernstein polynomials on are uniformly dense in the space of increasing continuous functions on . Finally, to show true universality, we have to show that any increasing continuous function is well-approximated by s.
Given continuous and increasing, choose two positive sequences and such that and . Let . Then, there exists a Bernstein approximation of , say , which is increasing on (which can be monotonically extended to ) such that
(26) |
Then the sequence of Bernstein approximations converges point-wise to on , and this convergence is uniform on each compact interval. ∎
Remark 2.
We can write down a sequence explicitly when is regular. For example, when is with bounded derivatives and , choosing the degree of to be is sufficient because it follows from the error estimate in Section 4.3 that works. That is, choose to be the degree Bernstein approximation of on .
Remark 3.
Note that this result is not a restatement of the original result in Bernstein (1912). The latter is about Bernstein-type polynomials being uniformly dense in the space of continuous functions on a compact interval. It uses the fact that such functions have a maximum. For the universality of NFs, we need that given an increasing continuous function on the real line (which is noncompact and hence, no guarantee of a maximum) there is a sequence of Bernstein-type polynomials that converge (at least, pointwise) to it.
8 Universality and the explicit rate of convergence
The basis of all the universality proofs of NFs in the existing literature is that the learnable class of functions is dense in the class of increasing continuous functions. In contrast, the argument we present here is constructive. As a result, we can write down sequences of approximations for (known) transformations between densities; see Section 9.
In the case of cubic-spline NFs of Durkan et al. (2019a), it is known that for and , when the transformation is times continuously differentiable and the bin size is , the error is (Ahlberg et al., 1967, Chapter 2). However, we are not aware of any other instance where an error bound is available. Fortunately for us, the error of approximation of a function by its Bernstein polynomials has been extensively studied. We recall from Voronovskaya (1932) the following error bound: for twice continuously differentiable
(27) |
and this holds for an arbitrary interval with replaced by .
Since the error estimate is given in terms of the degree of the polynomials used, we can improve the optimality of our NF by avoiding unnecessarily high degree polynomials. This allows us to keep the number of trainable parameters under control in our NF model. The following example shows that the error above does not necessarily improve when SOS polynomials are used instead.
Example 1.
Uniform to the Normal There is bounded such that
(28) |
see Jaini et al. (2019). This is the power series expansion of at , and hence, it is unique. The SOS approximation of the series above truncated at is only accurate on compact sub-intervals of . This is precisely the accuracy one would expect from the degree Bernstein approximation on any compact subinterval of .
In our NF, at each step, the estimation is done using a univariate polynomial, and hence, the overall convergence rate is, in fact, the minimal univariate convergence rate of (equivalently, the error upper bound is the maximum of univariate upper bounds), and in general, cannot be improved further regardless of how regular the density transformation is. However, our experiments show that our model on average has a significantly smaller error than the given theoretical upper-bound.
9 Examples of Bernstein-type approximations
In this section, we illustrate how to use Bernstein-type polynomials to approximate diffeomorphisms between densities. We restrict our attention to densities on . Suppose and are the distribution functions of the two probability densities and on . Then the increasing rearrangement is the unique increasing transformation that pushes forward to , and this generalizes to higher dimensions (Villani, 2009, Chapter 1). Now, we can explicitly write down their degree Bernstein-type approximations, along with convergence rates.
Example 2.
Uniform to a continuous and non-zero density on Note that is strictly increasing and hence, invertible on . So, , and is once continuously differentiable. Then
(29) |
and .
Example 3.
10 Hyper-parameters and training details
For optimization, we used the Adam optimizer with parameters , , , where parameters refer to the usual notation. An initial learning rate of was used for updating the weights with a decay factor of per iterations. We initialized all the trainable weights randomly from a standard normal distribution and used maximum likelihood as the objective function for training. We observed that a single layer model with degree polynomials performed well for the real-world data.
In contrast, for 2D toy distributions and and images we used higher number of layers () with degree polynomials in each layer. For all the experiments, we use a Kumaraswamy distribution with parameters and as the base density. Using a standard normal distribution after converting it to a density on using a nonlinear transformation, e.g., , also yielded similar results.
11 Training stability for higher degree polynomials
Typically, polynomial-based models such as SOS yield training instability as their target ranges are not compact. This is because higher degree approximations could increase the range of outputs without bound, and in turn cause gradients to explode while training. As a solution, they opt to use a higher number of layers with lower degree polynomials. In contrast, our model can entertain higher degree approximations without any instability which allows more design choices. Figure 4 demonstrates this behavior experimentally.


According to Figure 4, the model hits a peak in performance at a certain degree and shows a slight drop in performance at higher degrees. Nevertheless, the model does not exhibit unstable behavior at higher degrees as opposed to SOS-flows – an indication of the superior training stability of our model. This further illustrates that our model provides the option to design shallow models by increasing the number of degrees in the polynomials instead of deeper models with a higher number of layers.
12 Ablation study
We compare the performance of different variants of our model against a simple task in order to better understand the design choices. For this, we use a standard normal as the base distribution, and a mixture of five Gaussians with means , variances = , and weights each, as the target. Figure 5 depicts the results.
Clearly, we were able to increase the expressiveness of the transformation by increasing the degree of the polynomials, as well as the number of layers. However, it is also visible that using an unnecessarily higher degree over-parametrizes the model, and hence, deteriorate the output. As discussed in the main article and in Section 11, we are able to use polynomials with degree as high as 100 in this experiment and others with no cost to the training stability because the training is done for a compactly supported target.
We also examine how the initial base distribution affects the performance. We use a mixture of seven Gaussians with means , variances = , and weights , as the target. We used a model with a -degree polynomial and a single layer for this experiment. Figure 6 illustrates the results. Although all priors capture the multimodes, when Uniform is used the model was not able to predict that the density is almost zero for large negative values.


13 Experiments with two-dimensional image datasets
In Section 4.2, we reported the results of the experiments we ran on two low-dimensional image datasets: CIFAR10 and MNIST. The samples generated from the experiment are shown Figure 7. We recall that we manage to obtain the optimal results among the methods that do not use multi-scale convolutional architectures.


References
- Abdelhamed et al. (2019) Abdelrahman Abdelhamed, Marcus A Brubaker, and Michael S Brown. Noise flow: Noise modeling with conditional normalizing flows. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pages 3165–3173, 2019.
- Ahlberg et al. (1967) J. H. Ahlberg, E. N. Nilson, and J. L. Walsh. The Theory of Splines and their Applications. Academic Press, 1967.
- Baumann et al. (2021) Philipp F. M. Baumann, Torsten Hothorn, and David Rügamer. Deep conditional transformation models. In Nuria Oliver, Fernando Pérez-Cruz, Stefan Kramer, Jesse Read, and Jose A. Lozano, editors, Machine Learning and Knowledge Discovery in Databases. Research Track, pages 3–18. Springer International Publishing, 2021.
- Berg et al. (2018) Rianne van den Berg, Leonard Hasenclever, Jakub M Tomczak, and Max Welling. Sylvester normalizing flows for variational inference. arXiv preprint arXiv:1803.05649, 2018.
- Bernstein (1912) S. Bernstein. Démonstration du théorème de weierstrass fondée sur le calcul des probabilités. Communications of the Kharkov Mathematical Society, pages 1–2, 1912.
- Bogachev et al. (2005) Vladimir Igorevich Bogachev, Aleksandr Viktorovich Kolesnikov, and Kirill Vladimirovich Medvedev. Triangular transformations of measures. Sbornik: Mathematics, 196(3):309, 2005.
- Bustamante (2017) J. Bustamante. Bernstein Operators and Their Properties. Birkhauser, 2017.
- Condessa and Kolter (2020) Filipe Condessa and Zico Kolter. Provably robust deep generative models. arXiv preprint arXiv:2004.10608, 2020.
- Dinh et al. (2014) Laurent Dinh, David Krueger, and Yoshua Bengio. Nice: Non-linear independent components estimation. arXiv preprint arXiv:1410.8516, 2014.
- Dinh et al. (2016) Laurent Dinh, Jascha Sohl-Dickstein, and Samy Bengio. Density estimation using real nvp. arXiv preprint arXiv:1605.08803, 2016.
- Durkan et al. (2019a) Conor Durkan, Artur Bekasov, Iain Murray, and George Papamakarios. Cubic-spline flows. arXiv preprint arXiv:1906.02145, 2019a.
- Durkan et al. (2019b) Conor Durkan, Artur Bekasov, Iain Murray, and George Papamakarios. Neural spline flows. arXiv preprint arXiv:1906.04032, 2019b.
- Esling et al. (2019) Philippe Esling, Naotake Masuda, Adrien Bardet, Romeo Despres, et al. Universal audio synthesizer control with normalizing flows. arXiv preprint arXiv:1907.00971, 2019.
- Farouki (2000) R. T. Farouki. Convergent inversion approximations for polynomials in bernstein form. Comput. Aided Geom. Des., 17(2):179–196, 2000.
- Farouki and Goodman (1996) R. T. Farouki and T. N. T. Goodman. On the optimal stability of the Bernstein basis. Mathematics of Computation, 65(216):1553–1566, 1996.
- Farouki and Rajan (1987) R. T. Farouki and V. T. Rajan. On the numerical condition of polynomials in Bernstein form. Computer Aided Geometric Design 4, 4(3):191–216, 1987.
- Germain et al. (2015) Mathieu Germain, Karol Gregor, Iain Murray, and Hugo Larochelle. Made: Masked autoencoder for distribution estimation. In International Conference on Machine Learning, pages 881–889. PMLR, 2015.
- Grathwohl et al. (2018) Will Grathwohl, Ricky TQ Chen, Jesse Bettencourt, Ilya Sutskever, and David Duvenaud. Ffjord: Free-form continuous dynamics for scalable reversible generative models. arXiv preprint arXiv:1810.01367, 2018.
- Higham (1996) N. J. Higham. Accuracy and stability of numerical algorithms. SIAM, 1996.
- Ho et al. (2019) Jonathan Ho, Xi Chen, Aravind Srinivas, Yan Duan, and Pieter Abbeel. Flow++: Improving flow-based generative models with variational dequantization and architecture design. In International Conference on Machine Learning, pages 2722–2730. PMLR, 2019.
- Hothorn and Zeileis (2021) Torsten Hothorn and Achim Zeileis. Predictive distribution modelling using transformation forests. Journal of Computational and Graphical Statistics, 2021.
- Hothorn et al. (2018) Torsten Hothorn, Lisa Möst, and Peter Bühlmann. Most likely transformations. Scandinavian Journal of Statistics, 45(1):110–134, 2018.
- Jaini et al. (2019) Priyank Jaini, Kira A Selby, and Yaoliang Yu. Sum-of-squares polynomial flow. arXiv preprint arXiv:1905.02325, 2019.
- Kingma and Dhariwal (2018) Diederik P Kingma and Prafulla Dhariwal. Glow: Generative flow with invertible 1x1 convolutions. arXiv preprint arXiv:1807.03039, 2018.
- Kobyzev et al. (2020) Ivan Kobyzev, Simon Prince, and Marcus Brubaker. Normalizing flows: An introduction and review of current methods. IEEE Transactions on Pattern Analysis and Machine Intelligence, page 1, 2020.
- Köhler et al. (2020) Jonas Köhler, Leon Klein, and Frank Noé. Equivariant flows: exact likelihood generative learning for symmetric densities. In International Conference on Machine Learning, pages 5361–5370. PMLR, 2020.
- Kos et al. (2018) Jernej Kos, Ian Fischer, and Dawn Song. Adversarial examples for generative models. In 2018 ieee security and privacy workshops (spw), pages 36–42. IEEE, 2018.
- Kumaraswamy (1980) P. Kumaraswamy. A generalized probability density function for double-bounded random processes. Journal of Hydrology, 46(1-2):79–88, 1980.
- Lanckriet et al. (2002) G. R. G. Lanckriet, L. El Ghaoui, C. Bhattacharyya, and M. I. Jordan. A robust minimax approach to classification. Journal of Machine Learning Research, 3:555–582, 2002.
- Lindvall (2002) T. Lindvall. Lectures on the coupling method. Dover Publications, 2002.
- Lu and Huang (2020) You Lu and Bert Huang. Woodbury transformations for deep generative flows. Advances in Neural Information Processing Systems, 33, 2020.
- Mazoure et al. (2020) Bogdan Mazoure, Thang Doan, Audrey Durand, Joelle Pineau, and R Devon Hjelm. Leveraging exploration in off-policy algorithms via normalizing flows. In Conference on Robot Learning, pages 430–444. PMLR, 2020.
- Peña (1997) J. M. Peña. B-splines and optimal stability. Mathematics of Computation, 66(220):1555–1560, 1997.
- Prenger et al. (2019) Ryan Prenger, Rafael Valle, and Bryan Catanzaro. Waveglow: A flow-based generative network for speech synthesis. In ICASSP 2019-2019 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), pages 3617–3621. IEEE, 2019.
- Rajan et al. (1988) V. T. Rajan, S. R. Klinkner, and R. T. Farouki. Root isolation and root approximation for polynomials in Bernstein form. Technical Report RC14224, IBM Research Division, T. J. Watson Research Center, Yorktown Heights, N.Y. 10598, 1988.
- Rezende and Mohamed (2015) Danilo Jimenez Rezende and Shakir Mohamed. Variational inference with normalizing flows. arXiv preprint arXiv:1505.05770, 2015.
- Spencer (1994) M. R. Spencer. Polynomial Real Root Finding in Bernstein Form. PhD thesis, Brigham Young University, 1994.
- Taylor (1982) J. R. Taylor. An introduction to error analysis: the study of uncertainties in physical measurements. Mill Valley, Calif, University Science Books, 1982.
- Villani (2009) Cédric Villani. Optimal Transport: Old and New. Springer, 2009.
- Voronovskaya (1932) E. Voronovskaya. Détermination de la forme asymptotique d’approximation des fonctions par les polynômes de M. Bernstein. Doklady Akademii Nauk SSSR, pages 79–85, 1932.
- Ward et al. (2019) Patrick Nadeem Ward, Ariella Smofsky, and Avishek Joey Bose. Improving exploration in soft-actor-critic with normalizing flows policies. arXiv preprint arXiv:1906.02771, 2019.
- Wirnsberger et al. (2020) Peter Wirnsberger, Andrew J Ballard, George Papamakarios, Stuart Abercrombie, Sébastien Racanière, Alexander Pritzel, Danilo Jimenez Rezende, and Charles Blundell. Targeted free energy estimation via learned mappings. The Journal of Chemical Physics, 153(14):144–112, 2020.
- Wong et al. (2020) Kaze WK Wong, Gabriella Contardo, and Shirley Ho. Gravitational-wave population inference with deep flow-based generative network. Physical Review D, 101(12):123005, 2020.