A Connection between Generative Adversarial Networks, Inverse Reinforcement Learning, and Energy-Based Models

by   Chelsea Finn, et al.
berkeley college

Generative adversarial networks (GANs) are a recently proposed class of generative models in which a generator is trained to optimize a cost function that is being simultaneously learned by a discriminator. While the idea of learning cost functions is relatively new to the field of generative modeling, learning costs has long been studied in control and reinforcement learning (RL) domains, typically for imitation learning from demonstrations. In these fields, learning cost function underlying observed behavior is known as inverse reinforcement learning (IRL) or inverse optimal control. While at first the connection between cost learning in RL and cost learning in generative modeling may appear to be a superficial one, we show in this paper that certain IRL methods are in fact mathematically equivalent to GANs. In particular, we demonstrate an equivalence between a sample-based algorithm for maximum entropy IRL and a GAN in which the generator's density can be evaluated and is provided as an additional input to the discriminator. Interestingly, maximum entropy IRL is a special case of an energy-based model. We discuss the interpretation of GANs as an algorithm for training energy-based models, and relate this interpretation to other recent work that seeks to connect GANs and EBMs. By formally highlighting the connection between GANs, IRL, and EBMs, we hope that researchers in all three communities can better identify and apply transferable ideas from one domain to another, particularly for developing more stable and scalable algorithms: a major challenge in all three domains.



page 1

page 2

page 3

page 4


Connecting Generative Adversarial Networks and Actor-Critic Methods

Both generative adversarial networks (GAN) in unsupervised learning and ...

Bidirectional Conditional Generative Adversarial Networks

Conditional variants of Generative Adversarial Networks (GANs), known as...

Learning to Optimize via Wasserstein Deep Inverse Optimal Control

We study the inverse optimal control problem in social sciences: we aim ...

Imitation learning based on entropy-regularized forward and inverse reinforcement learning

This paper proposes Entropy-Regularized Imitation Learning (ERIL), which...

Objective-Reinforced Generative Adversarial Networks (ORGAN) for Sequence Generation Models

In unsupervised data generation tasks, besides the generation of a sampl...

Detecting Deceptive Reviews using Generative Adversarial Networks

In the past few years, consumer review sites have become the main target...

Energy-Based Sequence GANs for Recommendation and Their Connection to Imitation Learning

Recommender systems aim to find an accurate and efficient mapping from h...

Code Repositories

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Generative adversarial networks (GANs) are a recently proposed class of generative models in which a generator is trained to optimize a cost function that is being simultaneously learned by a discriminator [8]. While the idea of learning objectives is relatively new to the field of generative modeling, learning cost or reward functions has long been studied in control [5] and was popularized in 2000 for reinforcement learning problems [15]. In these fields, learning the cost function underlying demonstrated behavior is referred to as inverse reinforcement learning (IRL) or inverse optimal control (IOC). At first glance, the connection between cost learning in RL and cost learning for generative models may appear to be superficial; however, if we apply GANs to a setting where the generator density can be efficiently evaluated, the result is exactly equivalent to a sample-based algorithm for maximum entropy (MaxEnt) IRL. Interestingly, as MaxEnt IRL is an energy-based model, this connection suggests a method for using GANs to train a broader class of energy-based models.

MaxEnt IRL is a widely-used objective for IRL, proposed by Ziebart et al. [27]

. Sample-based algorithms for performing maximum entropy (MaxEnt) IRL have scaled cost learning to scenarios with unknown dynamics, using nonlinear function classes, such as neural networks 

[4, 11, 7]. We show that the gradient updates for the cost and the policy in these methods can be viewed as the updates for the discriminator and generator in GANs, under a specific form of the discriminator. The key difference to a generic discriminator is that we need to be able evaluate the density of the generator, which we integrate into the discriminator in a natural way.

Traditionally, GANs are used to train generative models for which it is not possible to evaluate the density. When it is possible to evaluate the density, for example in an autoregressive model, it is typical to maximize the likelihood of the data directly. By considering the connection to IRL, we find that GAN training may be appropriate even when density values are available. For example, suppose we are interested in modeling a complex multimodal distribution, but our model does not have enough capacity to represent the distribution. Then maximizing likelihood will lead to a distribution which “covers” all of the modes, but puts most of its mass in parts of the space that have negligible density under the data distribution. These might be images that look extremely unrealistic, nonsensical sentences, or suboptimal robot behavior. A generator trained adversarially will instead try to “fill in” as many of modes as it can, without putting much mass in the space between modes. This results in lower diversity, but ensures that samples “look like” they could have been from the original data.

By drawing an exact correspondence between adaptive, sample-based algorithms for MaxEnt IRL and GAN training, we show that this phenomenon occurs and is practically important: GAN training can significantly improve the quality of samples even when the generator density can be exactly evaluated. This is precisely analogous to the observed ability of inverse reinforcement learning to imitate behaviors that cannot be successfully learned through behavioral cloning [21], direct maximum likelihood regression to the demonstrated behavior.

Interestingly, the maximum entropy formulation of IRL is a special case of an energy-based model (EBM) [26]. The learned cost in MaxEnt IRL corresponds to the energy function, and is trained via maximum likelihood. Hence, we can also show how a particular form of GANs can be used to train EBMs. Recent works have recognized a connection between EBMs and GANs [12, 25]. In this work, we particularly focus on EBMs trained with maximum likelihood, and expand upon the connection recognized by Kim & Bengio [12] for the case where the generator’s density can be computed. By formally highlighting the connection between GANs, IRL, and EBMs, we hope that researchers in all three areas can better identify and apply transferable ideas from one domain to another.

2 Background

In this section, we formally define generative adversarial networks (GANs), energy-based models (EBMs), and inverse reinforcement learning (IRL), and introduce notation.

2.1 Generative Adversarial Networks

Generative adversarial networks are an approach to generative modeling where two models are trained simultaneously: a generator and a discriminator

. The discriminator is tasked with classifying its inputs as either the output of the generator, or actual samples from the underlying data distribution

. The goal of the generator is to produce outputs that are classified by the discriminator as coming from the underlying data distribution [8].

Formally, the generator takes noise as input and outputs a sample , while the discriminator takes as input a sample

and outputs the probability

that the sample was from the data distribution. The discriminator’s loss is the average log probability it assigns to the correct classification, evaluated on an equal mixture of real samples and outputs from the generator:

The generator’s loss can be defined one of several similar ways. The simplest definition, originally proposed in [8], is simply the opposite of the discriminator’s loss. However, this provides very little training signal if the generator’s output can be easily distinguished from the real samples. It is common to instead use the log of the discriminator’s confusion [8]. We will define the generator’s loss as the sum of these two variants:

2.2 Energy-Based Models

Energy-based models [14] associate an energy value with a sample , modeling the data as a Boltzmann distribution:


The energy function parameters are often chosen to maximize the likelihood of the data; the main challenge in this optimization is evaluating the partition function

, which is an intractable sum or integral for most high-dimensional problems. A common approach to estimating

requires sampling from the Boltzmann distribution within the inner loop of learning.

Sampling from

can be approximated by using Markov chain Monte Carlo (MCMC) methods; however, these methods face issues when there are several distinct modes of the distribution and, as a result, can take arbitrarily large amounts of time to produce a diverse set of samples. Approximate inference methods can also be used during training, though the energy function may incorrectly assign low energy to some modes if the approximate inference method cannot find them 


2.3 Inverse Reinforcement Learning

The goal of inverse reinforcement learning is to infer the cost function underlying demonstrated behavior [15]. It is typically assumed that the demonstrations come from an expert who is behaving near-optimally under some unknown cost. In this section, we discuss MaxEnt IRL and guided cost learning, an algorithm for MaxEnt IRL.

2.3.1 Maximum entropy inverse reinforcement learning

Maximum entropy inverse reinforcement learning models the demonstrations using a Boltzmann distribution, where the energy is given by the cost function :

Here, is a trajectory; is a learned cost function parametrized by ; and are the state and action at time step ; and the partition function is the integral of over all trajectories that are consistent with the environment dynamics.111This formula assumes that is a deterministic function of the previous history. A more general form of this equation can be derived for stochastic dynamics [26]. However, the analysis largely remains the same: the probability of a trajectory can be written as the product of conditional probabilities, but the conditional probabilities of the states are not affected by and so factor out of all likelihood ratios.

Under this model, the optimal trajectories have the highest likelihood, and the expert can generate suboptimal trajectories with a probability that decreases exponentially as the trajectories become more costly. As in other energy-based models, the parameters are optimized to maximize the likelihood of the demonstrations. Estimating the partition function is difficult for large or continuous domains, and presents the main computational challenge. The first applications of this model computed exactly with dynamic programming [27]. However, this is only practical in small, discrete domains, and is impossible in domains where the system dynamics are unknown.

2.3.2 Guided cost learning

Guided cost learning introduces an iterative sample-based method for estimating in the MaxEnt IRL formulation, and can scale to high-dimensional state and action spaces and nonlinear cost functions [7]. The algorithm estimates by training a new sampling distribution and using importance sampling:

Guided cost learning alternates between optimizing using this estimate, and optimizing

to minimize the variance of the importance sampling estimate.

The optimal importance sampling distribution for estimating the partition function is . During guided cost learning, the sampling policy is updated to match this distribution by minimizing the KL divergence between and , or equivalently minimizing the learned cost and maximizing entropy.


Conveniently, this optimal sampling distribution is the demonstration distribution for the true cost function. Thus, this training procedure results in both a learned cost function, characterizing the demonstration distribution, and a learned policy , capable of generating samples from the demonstration distribution.

This importance sampling estimate can have very high variance if the sampling distribution fails to cover some trajectories with high values of . Since the demonstrations will have low cost (as a result of the IRL objective), we can address this coverage problem by mixing the demonstration data samples with the generated samples. Let be the mixture distribution over trajectory roll-outs. Let be a rough estimate for the density of the demonstrations; for example we could use the current model , or we could use a simpler density model trained using another method. Guided cost learning uses for importance sampling222In RL settings, where generating samples requires executing a policy in the real world, such as in robotics, old samples from old generators are typically retained for efficiency. In this case, the density can be computed using a fusion distribution over the past generator densities., with as the importance weights:

2.4 Direct Maximum Likelihood and Behavioral Cloning

A simple approach to imitation learning and generative modeling is to train a generator or policy to output a distribution over the data, without learning a discriminator or energy function. For tractability, the data distribution is typically factorized using a directed graphical model or Bayesian network. In the field of generative modeling, this approach has most commonly been applied to speech and language generation tasks 

[23, 18], but has also been applied to image generation [22]. Like most EBMs, these models are trained by maximizing the likelihood of the observed data points.

When a generative model does not have the capacity to represent the entire data distribution, maximizing likelihood directly will lead to a moment-matching distribution that tries to “cover” all of the modes, leading to a solution that puts much of its mass in parts of the space that have negligible probability under the true distribution. In many scenarios, it is preferable to instead produce only realistic, highly probable samples, by “filling in” as many modes as possible, at the trade-off of lower diversity. Since EBMs are also trained with maximum likelihood, the energy function in an EBM will exhibit the same moment-matching behavior when it has limited capacity. However, designing a flexible energy function to represent a distribution’s density function is generally much easier than designing a tractable generator with the same flexibility, that can to generate samples without a complex iterative inference procedure. Moreover, once we have a trained energy function, the generator is trained to be mode-seeking, by minimizing the KL divergence between the generator’s distribution and the distribution induced by the energy function. As a result, even if the generator has the same capacity as a generative model trained with direct maximum likelihood, the generator trained with an EBM will exhibit mode-seeking behavior as long as the energy function is more flexible than the generator. Of course, this phenomenon is often achieved at the cost of tractability, as generating samples from an energy function requires training a generator which, in the case of IRL, is forward policy optimization.

In sequential decision-making domains, using direct maximum likelihood is known as behavioral cloning, where the policy is trained with supervised learning to match the actions of the demonstrating agent, conditioned on the corresponding observations. While this approach is simple and often effective for small problems, the moment-matching behavior of direct maximum likelihood can produce particularly ineffective trajectories because of compounding errors. When the policy makes a small mistake, it deviates from the state distribution seen during training, making it more likely to make a mistake again. This issue compounds and eventually, the agent reaches a state far from the training distribution and makes a catastrophic error 

[21]. Generative modeling also faces this issue when generating variables sequentially. A popular approach for handling this involves incrementally sampling more from the model and drawing less from the data distribution during training [21]. This requires that the true data distribution can be sampled from during training, corresponding to a human or algorithmic expert. Bengio et al. proposed an approximate solution, termed scheduled sampling, that does not require querying the data distribution [3]. However, while these approaches alleviate the issue, they do not solve it completely.

3 GANs and IRL

We now show how generative adversarial modeling has implicitly been applied to the setting of inverse reinforcement learning, where the data-to-be-modeled is a set of expert demonstrations. The derivation requires a particular form of discriminator, which we discuss first in Section 3.1. After making this modification to the discriminator, we obtain an algorithm for IRL, as we show in Section 3.2, where the discriminator involves the learned cost and the generator represents the policy.

3.1 A special form of discriminator

For a fixed generator with a [typically unknown] density , the optimal discriminator is the following [8]:


where is the actual distribution of the data.

In the traditional GAN algorithm, the discriminator is trained to directly output this value. When the generator density can be evaluated, the traditional GAN discriminator can be modified to incorporate this density information. Instead of having the discriminator estimate the value of Equation 3 directly, it can be used to estimate , filling in the value of with its known value. In this case, the new form of the discriminator with parameters is

In order to make the connection to MaxEnt IRL, we also replace the estimated data density with the Boltzmann distribution. As in MaxEnt IRL, we write the energy function as to designate the learned cost. Now the discriminator’s output is:

The resulting architecture for the discriminator is very similar to a typical model for binary classification, with a sigmoid as the final layer and as the bias of the sigmoid. We have adjusted the architecture only by subtracting from the input to the sigmoid. This modest change allows the optimal discriminator to be completely independent of the generator: the discriminator is optimal when . Independence between the generator and the optimal discriminator may significantly improve the stability of training.

This change is very simple to implement and is applicable in any setting where the density can be cheaply evaluated. Of course this is precisely the case where we could directly maximize likelihood, and we might wonder whether it is worth the additional complexity of GAN training. But the experience of researchers in IRL has shown that maximizing log likelihood directly is not always the most effective way to learn complex behaviors, even when it is possible to implement. As we will show, there is a precise equivalence between MaxEnt IRL and this type of GAN, suggesting that the same phenomenon may occur in other domains: GAN training may provide advantages even when it would be possible to maximize likelihood directly.

3.2 Equivalence between generative adversarial networks and guided cost learning

In this section, we show that GANs, when applied to IRL problems, optimize the same objective as MaxEnt IRL, and in fact the variant of GANs described in the previous section is precisely equivalent to guided cost learning.

Recall that the discriminator’s loss is equal to

In maximum entropy IRL, the log-likelihood objective is:


where we have substituted , i.e. we are using the current model to estimate the importance weights.

We will establish the following facts, which together imply that GANs optimize precisely the MaxEnt IRL problem:

  1. The value of which minimizes the discriminator’s loss is an importance-sampling estimator for the partition function, as described in Section 2.3.2.

  2. For this value of , the derivative of the discriminator’s loss with respect to is equal to the derivative of the MaxEnt IRL objective.

  3. The generator’s loss is exactly equal to the cost minus the entropy of , i.e. the MaxEnt policy loss defined in Equation 2 in Section 2.3.2.

Recall that is the mixture distribution between and . Write . Note that when and are optimized, is an estimate for the density of , and hence is an estimate for the density of .

3.2.1 estimates the partition function

We can compute the discriminator’s loss:


Only the first and last terms depend on . At the minimizing value of , the derivative of these term with respect to will be zero:

Thus the minimizing is precisely the importance sampling estimate of the partition function in Equation 4.

3.2.2 optimizes the IRL objective

We return to the discriminator’s loss as computed in Equation 8, and consider the derivative with respect to the parameters . We will show that this is exactly the same as the derivative of the IRL objective.

Only the second and fourth terms in the sum depend on . When we differentiate those terms we obtain:

On the other hand, when we differentiate the MaxEnt IRL objective, we obtain:

In the third equality, we used the definition of as an importance sampling estimate. Note that in the second equality, we have treated as a constant rather than as a quantity that depends on . This is because the IRL optimization is minimizing and using as the weights for an importance sampling estimator of . For this purpose we do not want to differentiate through the importance weights.

3.3 The generator optimizes the MaxEnt IRL objective

Finally, we compute the generator’s loss:

The term is a parameter of the discriminator that is held fixed while optimizing the generator, this loss is exactly equivalent the sampler loss from MaxEnt IRL, defined in Equation 2.

3.4 Discussion

There are many apparent differences between MaxEnt IRL and the GAN optimization problem. But, we have shown that after making a single key change—using a generator for which densities can be evaluated efficiently, and incorporating this information into the discriminator in a natural way—generative adversarial networks can be viewed as a sample-based algorithm for the MaxEnt IRL problem. By connecting GANs to the empirical literature on inverse reinforcement learning [7], this demonstrates that GAN training can improve the quality of samples even when the generator’s density can be evaluated exactly. By generalizing this connection, we can derive a new adversarial training strategy for energy-based models, which we discuss in the next section.

4 GANs for training EBMs

Now that we have highlighted the connection between GANs and guided cost learning, the application of GANs to EBMs follows directly. As discussed in Section 2.2, the primary challenge in training EBMs is estimating the partition function, which is done by approximately sampling from the distribution induced by the energy . Two recent papers have proposed to use adversarial training to derive fast estimates of the partition function [12, 25]. In particular, these methods alternate between training a generator to produce samples with minimal energy , and optimizing the parameters of the energy function using the samples to estimate the partition function.

When the density of the generator is available, however, we can derive an unbiased estimate of the partition function as

where denotes an equal mixture of generated and real data points, denotes the density under the generator, and denotes an estimate for the data density.

This gives a loss function

As before, the generator is updated to minimize energy and maximize entropy:

If we set , the resulting model is a special case of a GAN which is straightforward to implement. The discriminator’s output is , where

is a sigmoid with a trainable bias. The discriminator’s loss is the log probability and the generator’s loss is the discriminator’s log odds, as defined in Section 


Kim & Bengio proposed a similar energy-based model for generative image modeling, but did not assume they could compute the generator’s density [12]. As a result, they do not use importance weights, and work with a biased estimator of the partition function which converges to the true partition function when the generator correctly samples from the energy-based model. In contrast, by using the generator density, we can get an unbiased estimate of the partition function that does not rely on any assumptions about the generator. Thus, even if the generator cannot learn to sample exactly from the data distribution, our training procedure is consistent.

Zhao et al. also proposed an energy-based GAN model with an autoencoder discriminator where the energy is given by the mean-squared error between the data example (generated or real) and the discriminator’s reconstruction 

[25]. The energy function is optimized with a margin loss, and the generator is trained to minimize energy. This method also did not use the form of discriminator presented above. An interesting direction for future exploration is to consider combining the GAN training algorithm discussed here with an objective other than log-likelihood, such as one used with EBMs [14] or different -divergences used with GANs [17].

5 Related Work

Ho et al. [10, 9] previously presented a GAN-like algorithm for imitation learning, where the goal is to recover a policy that matches the expert demonstrations. The proposed algorithm, called generative adversarial imitation learning (GAIL), has an adversarial structure. The analysis in this paper provides additional insight into what GAIL is doing. As discussed above, GANs are optimizing the same objective as MaxEnt IRL. Thus, the GAIL policy is being trained to optimize a cost learned through MaxEnt IRL. Unlike guided cost learning [7], however, Ho & Ermon use the typical unconstrained form of the discriminator [9] and do not use the generator’s density. In this case, the cost function remains implicit within the discriminator and cannot be recovered. Hence, in GAIL, the discriminator is discarded and the policy is the end result.

Bachman & Precup [1] suggested that data generation can be converted into a sequential decision-making problem and solved with a reinforcement learning method. Several recent works have proposed methods for merging maximum likelihood objectives and known reward functions for training sequential language generation models and rely on surrogate reward function such as BLEU score or edit distance [20, 16, 2]. In this work, we assume that the reward function is unknown.

Yu et al. proposed to learn a cost function for sequential data generation using GANs, where the cost is defined as the probability of the discriminator classifying the generated sequence as coming from the data distribution [24]. The discriminator does not take advantage of the policy’s density values, despite the fact that they are known (and are used during pre-training). Their experiments also find that max-likelihood pre-training is crucial for good performance, suggesting that recurrent generators that can’t afford such pre-training (e.g. because they don’t have densities) are less practical to train.

Pfau & Vinyals drew a connection between the optimization problems in GANs and actor-critic methods in reinforcement learning, suggesting how ideas for stabilizing training in one domain could be beneficial for the other [19]. As the authors point out, these optimization tricks could also be useful for imitation learning algorithms with the same two-level optimization structure.

6 Discussion

In this work, we showed an equivalence between generative adversarial modeling and an algorithm for performing maximum entropy inverse reinforcement learning. Our derivation used a special form of discriminator that leverages likelihood values from the generator, leading to an unbiased estimate of the underlying energy function. A natural direction for future work is to experiment with combining deep generators that can provide densities, such as autoregressive models [13, 22] or models that use invertible transformations [6], with generative adversarial modeling. Such an approach may provide more stable training, better generators, and wider applicability to discrete problems such as language.

This work also suggests a new algorithm for training energy-based models using generative adversarial networks, that trains a neural network model to sample from the distribution induced by the current energy. This method could reduce the computational challenges of existing MCMC-based solutions.


The authors would like to thank Ian Goodfellow and Joan Bruna for insightful discussions.