Transformation Autoregressive Networks

Junier B. Oliva, Avinava Dubey, Manzil Zaheer, Barnabás Póczos, Ruslan Salakhutdinov, Eric P. Xing, Jeff Schneider

Introduction

Density estimation is at the core of a multitude of machine learning applications. However, this fundamental task is difficult in the general setting due to issues like the curse of dimensionality. Furthermore, for general data, unlike spatial/temporal data, we do not have known correlations a priori among covariates that may be exploited. For example, image data has known correlations among neighboring pixels that may be hard-coded into a model through convolutions, whereas one must find such correlations in a data-driven fashion with general data.

In order to model high dimensional data, the main challenge lies in constructing models that are flexible enough while having tractable learning algorithms. A variety of diverse solutions exploiting different aspects of the problems have been proposed in the literature. A large number of methods have considered auto-regressive models to estimate the conditional factors p(xi∣xi−1,…,x1)p(x_{i}|x_{i-1},\ldots,x_{1}), for i∈{1,…,d}i\in\{1,\ldots,d\} in the chain rule (Larochelle & Murray, 2011; Uria et al., 2013, 2016; Germain et al., 2015; Gregor et al., 2014). While some methods directly model the conditionals p(xi∣xi−1,…)p(x_{i}|x_{i-1},\ldots) using sophisticated semiparametric density estimates, other methods apply sophisticated transformations of variables x↦zx\mapsto z and take the conditionals over zz to be a restricted, often independent base distribution p(zi∣zi−1,…)≈f(zi)p(z_{i}|z_{i-1},\ldots)\approx f(z_{i}) (Dinh et al., 2014, 2016). Further related works are discussed in Sec. 3. However, looking across a diverse set of dataset, as in Fig. 1, neither of these approaches have the flexibility required to accurately model real world data.

In this paper we take a step back and start from the basics. If we only model the conditionals, the conditional factors p(xi∣xi−1,…)p(x_{i}|x_{i-1},\ldots), may become increasingly complicated as ii increases to dd. On the other hand if we use a complex transformation with restricted conditionals then the transformation has to ensure that the transformed variables are independent. This requirement of independence on the transformed variables can be very restrictive. Now note that the transformed space is homeomorphic to the original space and a simple relationship between the density of the two spaces exists through the Jacobian. Thus, we can employ conditional modeling on the transformed variables to alleviate the independence requirement, while being able to recover density in the original space in a straightforward fashion. In other words, we propose transformation autoregressive networks (TANs) which composes the complex transformations and autoregressive modeling of the conditionals. The composition not only increases the flexibility of the model but also reduces the expressibility power needed from each of the individual components. This leads to an improved performance as can be seen from Fig. 1.

In particular, first we propose two flexible autoregressive models for modeling conditional distributions: the linear autoregressive model (LAM), and the recurrent autoregressive model (RAM) (Sec. 2.1). Secondly, we introduce several novel transformations of variables: 1) an efficient method for learning a linear transformation on covariates; 2) an invertible RNN-based transformation that directly acts on covariates; 3) an additive RNN-base transformation (Sec. 2.2). Extensive experiments on both synthetic (Sec. 4.1) and real-world (Sec. 4.2) datasets show the power of TANs for capturing complex dependencies between the covariates. We run an ablation study to demonstrate contributions of various components in TAN Sec. 4.3, Moreover, we show that the learned model can be used for anomaly detection (Sec. 4.4) and learning a family of distributions (Sec. 4.5).

Transformation Autoregressive Networks

This uses a straightforward linear map as gig_{i} in (4):

Recurrent Autoregressive Model (RAM):

This features a recurrent relation between gig_{i}’s. As the set of covariates is progressively fed into gig_{i}’s, it is natural to consider a hidden state evolving according to an RNN recurrence relationship:

In this case g(x,s)g(x,s) is a RNN function for updating one’s state based on an input xx and prior state ss. In the case of gated-RNNs, the model will be able to scan through previously seen dimensions remembering and forgetting information as needed for conditional densities without making any strong Markovian assumptions.

Both LAM and RAM are flexible and able to adjust the hidden states, hih_{i} in (4), to model the distinct conditional tasks p(xi∣xi−1,…)p(x_{i}|x_{i-1},\ldots). There is a trade-off of added flexibility and transferred information between the two models. LAM treats the conditional tasks for p(xi∣xi−1,…)p(x_{i}|x_{i-1},\ldots) and p(xi+1∣xi,…)p(x_{i+1}|x_{i},\ldots) in a largely independent fashion. This makes for a very flexible model, however the parameter size is also large and there is no sharing of information among the conditional tasks. On the other hand, RAM provides a framework for transfer learning among the conditional tasks by allowing the hidden state hih_{i} to evolve through the distinct conditional tasks. This leads to fewer parameters and more sharing of information in respective tasks, but also yields less flexibility since conditional estimates are tied, and may only change in a smooth fashion.

2 Transformations

Recurrent Transformation:

Recurrent neural networks are also a natural choice for variable transformations. Due to their dependence on only previously seen dimensions, RNN transformations have triangular Jacobians, leading to simple determinants. Furthermore, with an invertible output unit, their inversion is also straight-forward. We consider the following form to an RNN transformation:

Furthermore, the determinant of the Jacobian for (9) is the product of diagonal terms:

Recurrent Shift Transformation:

It is worth noting that the rescaling brought on by the recurrent transformation effectively incurs a penalty through the log of the determinant (11). However, one can still perform a transformation that depends on the values of covariates through a shift operation. In particular, we propose an additive shift based on a recurrent function on prior dimensions:

where gg is recurrent function for updating states, and mm is a fully connected network. Inversion proceeds as before:

Composing Transformations:

Lastly, we considering stacking (i.e. composing) several transformations q=q(1)∘…∘q(T)q=q^{(1)}\circ\ldots\circ q^{(T)} and renormalizing:

where we take q(0)q^{(0)} to be xx. We note that composing several transformations together allows one to leverage the respective strengths of each transformation. Moreover, inserting a reversal mapping (x1,…,xd↦xd,…,x1x_{1},\ldots,x_{d}\mapsto x_{d},\ldots,x_{1}) as one of the qiq_{i}s yields bidirectional relationships.

3 Combined Approach

We combine the use of both transformations of variables and rich autoregressive models by: 1) writing the density of inputs, p(x)p(x), as a normalized density of a transformation: p(q(x))p(q(x)) (14). Then we estimate the conditionals of p(q(x))p(q(x)) using an autoregressive model, i.e., to learn our model we minimize the negative log likelihood:

which is obtained by substituting (2) into (14) with hih_{i} as defined in (4).

Related Works

Nonparametric density estimation has been a well studied problem in statistics and machine learning (Wasserman, 2007). Unfortunately, nonparametric approaches like kernel density estimation suffer greatly from the curse of dimensionality and do not perform well when data does not have a small number of dimensions (d≲3d\lesssim 3). To alleviate this, several semiparametric approaches have been explored. Such approaches include forest density estimation (Liu et al., 2011), which assumes that the data has a forest (i.e. a collection of trees) structured graph. This assumption leads to a density which factorizes in a first order Markovian fashion through a tree traversal of the graph. Another common semiparametric approach is to use a nonparanormal type model (Liu et al., 2009). This approach uses a Gaussian copula with a rank-based transformation and a sparse precision matrix. While both approaches are well-understood theoretically, their strong assumptions lead to inflexible models.

In order to provide greater flexibility with semiparametric models, recent work has employed deep learning for density estimation. The use of neural networks for density estimation dates back to Bishop (1994) and has seen success in speech (Zen & Senior, 2014; Uria, 2015), music (Boulanger-Lewandowski et al., 2012), etc. Typically such approaches use a network to learn the parameters of a parametric model for data. Recent work has also explored the application of deep learning to build density estimates in image data (Oord et al., 2016; Dinh et al., 2016). However, such approaches are heavily reliant on exploiting structure in neighboring pixels, often subsampling, reshaping or re-ordering data, and using convolutions to take advantage of neighboring correlations. Modern approaches for general density estimation in real-valued data include Uria et al. (2013, 2016); Germain et al. (2015); Gregor et al. (2014); Dinh et al. (2014); Kingma et al. (2016); Papamakarios et al. (2017).

NADE (Uria et al., 2013) is an RBM-inspired density estimator with a weight-sharing scheme across conditional densities on covariates. It may be written as a special case of LAM (5) with tied weights:

NICE (Dinh et al., 2014) and its successor Real NVP (Dinh et al., 2016) models assume that data is drawn from a latent independent Gaussian space and transformed. The transformation uses several “additive coupling” shifting on the second half of dimensions, using the first half of dimensions. For example NICE’s additive coupling proceeds by splitting inputs into halves x=(x<d/2, x≥d/2)x=(x_{<{d}/{2}},\,x_{\geq{d}/{2}}), and transforming the second half as an additive function of the first half:

MAF (Papamakarios et al., 2017) identified that Gaussian conditional autoregressive models for density estimation can be seen as transformations. This enabled them to stack multiple autoregressive models that increases flexibility. However, stacking Gaussian conditional autoregressive models amounts to just stacking shift and scale transformations. Unlike MAF, in the TAN framework we not only propose novel and more complex equivalence like Recurrent Transformation (Sec. 2.2), but also systematically composing stacks of such transformations with flexible autoregressive models.

There are several methods for obtaining samples from an unknown distribution that by-pass density estimation. For instance, generative adversarial networks (GANs) apply a (typically noninvertible) transformation of variables to a base distribution by optimizing a minimax loss (Goodfellow, 2016; Kingma et al., 2016). Samples can also be obtain from methods that compose graphical models with deep networks (Johnson et al., 2016; Al-Shedivat et al., 2017). Furthermore, one can also obtain samples with only limited information about the density of interest using methods such as Markov chain Monte Carlo (Neal, 1993), Hamiltonian Monte Carlo (Neal, 2010), stochastic variants (Dubey et al., 2016), etc.

Experiments

We now present empirical studies for our TAN framework in order to establish (i) the superiority of TANs over one-prong approaches (Sec. 4.1), (ii) that TANs are accurate on real world datasets (Sec. 4.2), (iii) the importance of various components of TANs, (iv) that TANs are easily amenable to various tasks (Sec. 4.4), such as learning a parametric family of distributions and being able to generalize over unseen parameter values (Sec. 4.5).

Implementation

Models were implemented in Tensorflow (Abadi et al., 2016)See https://github.com/lupalab/tan.. Both RAM conditional models as well as the RNN shift transformation make use of the standard GRUCell GRU implementation. We take the mixture models of conditionals (2) to be mixtures of 40 Gaussians. We optimize all models using the AdamOptimizer (Kingma & Ba, 2014) with an initial learning rate of 0.0050.005. Training consisted of 30 00030\,000 iterations, with mini-batches of size 256256. The learning rate was decreased by a factor of 0.10.1, or 0.50.5 (chosen via a validation set) every 5 0005\,000 iterations. Gradient clipping with a norm of 11 was used. After training, the best iteration according to the validation set loss was used to produce the test set results.

1 Synthetic

To showcase the strengths of TANs and short-comings of only conditional models & only transformations, we carefully construct two synthetic datasets

Observations

We detail the mean log-likelihoods on a test set for TANs using various combinations of conditional models and transformations in Appendix, Tab. 2 and Tab. 3 respectively. We see that both LAM and RAM conditionals are providing most of the top models. We observe good samples from the best performing model as shown in Fig. 2. Particularly in second dataset, simpler conditional methods are unable to model the data well, suggesting that the complicated dependencies need a two-prong TAN approach. We observe a similar pattern when learning over the star data with d=128d=128 (see Appendix, Tab. 4).

2 Efficacy on Real World Data

We performed several real-world data experiments and compared to several state-of-the-art density estimation methods to substantially improved performance of TAN.

We carefully followed (Papamakarios et al., 2017) and code (MAF Git Repository, ) to ensure that we operated over the same instances and covariates for each of the datasets considered in (Papamakarios et al., 2017). Specifically we performed unconditional density estimation on four datasets from UCI machine learning repositoryhttp://archive.ics.uci.edu/ml/: power: Containing electric power consumption in a household over 47 months. gas: Readings of 16 chemical sensors exposed to gas mixtures. hepmass: Describing Monte Carlo simulations for high energy physics experiments. minibone: Containing examples of electron neutrino and muon neutrino. We also used BSDS300 which were obtained from extracting random 8×88\times 8 monochrome patches from the BSDS300 datasets of natural images (Martin et al., 2001). These are multivariate datasets from a varied set of sources meant to provide a broad picture of performance across different domains. Here, we used a batch size of 1024 with 60K training iterations. We saw great performance by using multiple successions of a linear transformation, followed by an element-wise leaky transformation (as in eq. 9), a recurrent shift transformation (12), and an element-wise rescale transformation. Thus in addition, we used a model with 5 such stacked transformations (5x L+ReLU+SRNN+Re). Further, to demonstrate that our proposed models can even be used to model high dimensional data and produce coherent samples, we consider image modeling task, treating each image as a flattened vector. We consider 28×2828\times 28 grayscale images of MNIST digits and 32×3232\times 32 natural colored images of CIFAR-10. Following Dinh et al. (2014), we dequantize pixel values by adding noise and rescaling.

Metric

We use the average test log-likelihoods of the best TAN model selected using a validation set and compare to values reported by (Papamakarios et al., 2017) for MADE (Germain et al., 2015), Real NVP (Dinh et al., 2016), and MAF (Papamakarios et al., 2017) methods for each dataset. For images, we use transformed version of test log-likelihood, called bits per pixel, which is more popular. In order to calculate bits per pixel, we need to convert the densities returned by a model back to image space in the range , for which we use the same logit mapping provided in Papamakarios et al. (2017, Appendix E.2).

Observations

Tab. 1 and Fig. 4 shows our results on various multivariate datasets and images respectively, with error bars computed over 5 runs. As can be seen, our TAN models are considerably outperforming other state-of-the-art methods across all multivariate as well as image datasets, justifying our claim of utilizing both complex transformations and conditionals. Furthermore, we plot samples for MNIST case in Fig. 3. We see that TAN is able to capture the structure of digits with very few artifacts in samples, which is also reflected in the likelihoods.

3 Ablation Study

To study how different components of the models affect the log-likelihood, we perform a comprehensive ablation study across different datasets.

We used multiple datasets from the UCI machine learning repositoryhttp://archive.ics.uci.edu/ml/ and Stony Brook outlier detection datasets collection (ODDS)http://odds.cs.stonybrook.edu to evaluate log-likelihoods on test data. Broadly, the datasets can be divided into: Particle acceleration: higgs, hepmass, and susy datasets where generated for high-energy physics experiments using Monte Carlo simulations; Music: The music dataset contains timbre features from the million song dataset of mostly commercial western song tracks from the year 1922 to 2011; (Bertin-Mahieux et al., 2011). Word2Vec: wordvecs consists of 3 million words from a Google News corpus. Each word represented as a 300 dimensional vector trained using a word2vec modelhttps://code.google.com/archive/p/word2vec/. ODDS datasets: We used several ODDS datasets–forest, pendigits, satimage2. These are multivariate datasets from varied set of sources meant to provide a broad picture of performance across anomaly detection tasks. To not penalize models for low likelihoods on outliers in ODDS, we removed anomalies from test sets.

As noted in (Dinh et al., 2014), data degeneracies and other corner-cases may lead to arbitrarily low negative log-likelihoods. Thus, we remove discrete features, standardize, and add Gaussian noise (stddev of 0.010.01) to training sets.

Observations

We report average test log-likelihoods in Fig. 5 for each dataset and conditional model for the top transformations picked on a validation dataset. The tables with test log-likelihoods for all combinations of conditional models and transformations for each dataset is in Appendix Tab. 6-12. We observe that the best performing models in real-world datasets are those that incorporate a flexible transformation and conditional model. In fact, the best model in each of the datasets considered always has LAM or RAM autoregressive components. Each row of these tables show that using a complex conditional is always better than using restricted, independent conditionals. Similarly, each column of the table shows that for a given conditional, it is better to pick a complex transformation rather than having no transformation. It is interesting to note that many of these top models also contain a linear transformation. Of course, linear transformations of variables are common to most parametric models, however they have been under-explored in the context of autoregressive density estimation. Our methodology for efficiently learning linear transformations coupled with their strong empirical performance encourages their inclusion in autoregressive models for most datasets.

Finally, we pick the “overall” winning combination of transformations and conditionals. For this we compute the fraction of the top likelihood achieved by each transformation tt and conditional model mm for dataset DD: s(t,m,D)=exp⁡(lt,m,D)/max⁡a,bexp⁡(la,b,D)s(t,m,D)=\exp(l_{t,m,D})/\max_{a,b}\exp(l_{a,b,D}), where lt,m,Dl_{t,m,D} is the test log-likelihood for t,mt,m on DD. We then average SS over the datasets: S(t,m)=1T∑DS(t,m,D)S(t,m)=\frac{1}{T}\sum_{D}S(t,m,D), where TT is the total number of datasets and reported all these score in Appendix Tab. 5. This provides a summary of which models performed better over multiple datasets. In other words, the closer this score is to 1 for a model means the more datasets for which the model is the best performer. We see that RAM conditional with L RNN transformation, and LAM conditional with L RNN+4xAdd+Re were the two best performers.

4 Anomaly Detection

Next, we apply density estimates to anomaly detection. Typically anomalies or outliers are data-points that are unlikely given a dataset. In terms of density estimations, such a task is framed by identifying which instances in a dataset have a low corresponding density. That is, we shall label an instance xx, as an anomaly if p^(x)≤t\hat{p}(x)\leq t, where t≥0t\geq 0 is some threshold and p^\hat{p} is the density estimate based on training data. Note that this approach is trained in an unsupervised fashion. Density estimates were evaluated on test data with anomaly/non-anomaly labels on instances. We used thresholded log-likelihoods on the test set to compute precision and recall. We use the average-precision metric and show our results in Fig. 7. TAN performs the best on all three datasets. Beyond providing another interesting use for our density estimates, seeing good performance in these outlier detection tasks further demonstrates that our models are learning semantically meaningful patterns.

5 Learning Parametric Family of Distributions

To further demonstrate flexibility of TANs, we consider a new task of learning parametric family of distributions together. Suppose we have a family of density Pθ\mathcal{P}_{\theta}. We assume in training data there are NN sets X1,...,XNX_{1},...,X_{N} , where the nn-th set Xn={xn,1,...,xn,mn}X_{n}=\{x_{n,1},...,x_{n,m_{n}}\} consists of mnm_{n} i.i.d. samples from density Pθn\mathcal{P}_{\theta_{n}}, i.e. XnX_{n} is a set of sample points, and xn,j∼Pθn,j=1,...,mnx_{n,j}\sim\mathcal{P}_{\theta_{n}},j=1,...,m_{n}. We assume that we do not have access to underlying true parameters θn\theta_{n}. We want to jointly learn the density estimate and parameterization of the sets to predict even for sets coming from unseen values of θ\theta.

We achieve this with a novel approach that models each set XiX_{i} with p(⋅∣ϕ(Xi))p(\cdot|\phi(X_{i})) where pp is a shared TAN model for the family of distributions and ϕ(Xi)\phi(X_{i}) are a learned embedding (parameters) for the iith set with DeepSets (Zaheer et al., 2017). In particular, we use a permutation invariant network of DeepSets parameterized by W1W_{1} to extract the embedding ϕ(X)\phi(X) for the given sample set XX. The embedding is then fed along with sample set to TAN model parameterized by W2W_{2}. We then optimize the following modified objective:

We attempt to model point-cloud representation of objects from ShapeNet (Chang et al., 2015). We produce point-clouds with 1000 particles each (x,y,zx,y,z-coordinates) from the mesh representation of objects using the point-cloud-library’s sampling routine (Rusu & Cousins, 2011). We consider each category of objects (e.g. aeroplane, chair, car) as a family and each point cloud for each object in the category as a sample set. We train a TAN and only show samples in Fig. 6 produced for unseen test sets, as there are neither any baselines for this task nor ground truth for likelihood. From the samples, we see that our model is able to capture the structure of different kinds of unseen aeroplanes and chairs, with very few artifacts in samples, which reflects a good fit.

Note that this task is subtly different from conditional density estimation as we do not have access to class/parameter values during training. Also we want to caution users against using this method when the test sample set is very different from training or comes from a different family distribution.

Conclusion

In this work, we showed that we can significantly improve density estimation for real valued data by jointly leveraging transformations of variables with autoregressive models and proposed novel modules for both. We systematically characterized various modules and evaluated their contributions in a comprehensive ablation study. This exercise not only re-emphasized the benefits of joint modeling, but also revealed some straightforward modules and combinations thereof, which are empirically good, but were missed earlier, e.g. the untied linear conditionals. Finally we introduced a novel data driven framework for learning a family of distributions.

Acknowledgements

This research is partly funded by DOE grant DESC0011114, NSF IIS1563887, NIH R01GM114311, NSF IIS1447676, and the DARPA D3M program.

References

Appendix A Appendix

Below we detail the results on several datasets using different combinations of transformations and autoregressive conditional models. Each additive coupling transformation uses a fully connected network with two hidden layers of 256 units. RNN transformations use a hidden state with 16 units. SingleInd conditional models modeled each dimension’s conditional as a standard Gaussian. MultiInd modeled each dimension’s conditional as independent mixtures with 40 components (each with mean, scale, and weight parameter). RAM, LAM, and Tied conditional models each had a hidden state with 120 units that was fed through two fully connected layers each with 120 units to produce the parameters of the mixtures with 40 components. The RAM hidden state was produced by a GRU with 256 units. LAM and Tied hidden states came through a linear map as discussed above.