CAQL: Continuous Action Q-Learning
Moonkyung Ryu Yinlam Chow Ross Anderson Christian Tjandraatmadja Craig Boutilier



A Hierarchical Approach for Visual Storytelling Using Image Description
    Md Sultan Al Nahian Tasmia Tasrin Sagar Gandhi Ryan Gaines Brent Harrison
    
=============================================================================








Value-based reinforcement learning (RL) methods like Q-learning have shown success in a variety of domains.


One challenge in applying Q-learning to continuous-action RL problems, however,
is the continuous action maximization (max-Q) required for optimal Bellman backup. 



In this work, we develop CAQL, a (class of) algorithm(s) for continuous-action Q-learning

that can use several plug-and-play optimizers for the max-Q problem. Leveraging recent
optimization results for deep neural networks, we show that max-Q can be solved optimally using mixed-integer programming (MIP). When the Q-function representation has sufficient power, MIP-based optimization gives rise
to better policies and is more robust than approximate methods (e.g., gradient ascent, cross-entropy search). 
We further develop several techniques to accelerate inference in CAQL, which despite their approximate nature, perform well.

We compare CAQL with state-of-the-art RL algorithms on benchmark continuous-control problems that have different degrees of action constraints and show that CAQL outperforms policy-based methods in heavily constrained environments, often dramatically.







§ INTRODUCTION





Reinforcement learning (RL) has shown success in a variety of domains such as
games <cit.> and recommender systems (RSs) <cit.>. When the action space is finite, value-based algorithms
such as Q-learning <cit.>, which implicitly finds a policy by learning the optimal value function, are often very efficient because action optimization can be done by exhaustive enumeration. By contrast, in problems with a continuous action spaces
(e.g., robotics <cit.>), policy-based algorithms, such as policy gradient (PG) <cit.> or cross-entropy policy search (CEPS) <cit.>, which 
directly learn a return-maximizing policy, have proven more practical.
Recently, methods such as ensemble critic <cit.> and entropy regularization <cit.> have been developed to improve the performance of policy-based RL algorithms.


Policy-based approaches require a reasonable choice of policy parameterization.
In some continuous control problems, Gaussian distributions over actions conditioned on some state representation is used. 
However, in applications such as RSs, where actions often take 
the form of high-dimensional item-feature vectors, policies cannot typically be modeled by common action distributions. 
Furthermore, the admissible action set in RL is constrained in practice, 
for example, when actions must lie within a specific range for safety <cit.>.
In RSs, the admissible actions are often
random functions of the state <cit.>.
In such cases, it is non-trivial to define policy parameterizations that handle such factors.
On the other hand, value-based algorithms are well-suited to these settings, providing potential advantage over policy methods. 

Moreover, at least with linear function approximation <cit.>, under 

reasonable assumptions,
Q-learning converges to optimality, while such optimality guarantees for non-convex policy-based methods are generally limited <cit.>.
Empirical results also suggest that value-based methods are more data-efficient and less sensitive to hyper-parameters <cit.>. Of course, with large action spaces,
exhaustive action enumeration in value-based algorithms can be  expensive—-one solution is to represent actions with continuous features <cit.>.



The main challenge in applying value-based algorithms to continuous-action domains is selecting optimal actions (both
at training and inference time).
Previous work in this direction falls into three broad categories. 
The first solves the inner maximization of the (optimal) Bellman residual loss using global nonlinear optimizers, such as the cross-entropy method (CEM) for QT-Opt <cit.>, gradient ascent (GA) for actor-expert <cit.>, and action discretization <cit.>. However, these approaches do not guarantee optimality.
The second approach restricts the Q-function parameterization so that the optimization problem is tractable. For instance,
one can discretize the state and action spaces and use a tabular Q-function representation.

However, due to the curse of dimensionality, discretizations must generally be coarse,

often resulting  in unstable control. <cit.> circumvents this
issue
by averaging discrete actions weighted by their Q-values.
Wire-fitting <cit.> approximates  Q-values piecewise-linearly over a discrete set of points,
chosen to

ensure the maximum action is one of the extreme points. The normalized advantage function (NAF) <cit.> constructs the state-action advantage function to be quadratic, hence analytically solvable.

Parameterizing the Q-function with an input-convex neural network <cit.> ensures it is concave.


These restricted functional forms, however, may degrade performance if the domain does not conform to the imposed structure. The third category replaces optimal Q-values with a “soft” counterpart  <cit.>: an entropy regularizer ensures that both the optimal Q-function and policy have closed-form solutions. 


However, the sub-optimality gap of this soft policy scales with the interval and dimensionality of the action space <cit.>.


Motivated by the shortcomings of prior approaches, we propose Continuous Action Q-learning (CAQL),
a Q-learning framework for continuous actions in which the Q-function is modeled by a generic feed-forward neural network.[Results can be extended to handle convolutional NNs, but are omitted for brevity.] 
Our contribution is 
three-fold. First, we develop the CAQL framework, which minimizes the Bellman residual in Q-learning using one of several “plug-and-play” action optimizers.
We show that “max-Q” optimization, when the Q-function is approximated by a deep ReLU network, can be formulated as a mixed-integer program (MIP)
that solves max-Q optimally. When the Q-function has sufficient representation power, 

MIP-based optimization induces better policies and is more robust than methods (e.g., CEM, GA) that approximate the max-Q solution. 
Second, to improve CAQL's practicality for larger-scale applications, we develop three speed-up techniques for computing max-Q values: (i) dynamic tolerance; (ii) dual filtering; and (iii) clustering. 
Third, 
we compare CAQL with several state-of-the-art RL algorithms on several benchmark problems with varying  degrees of action constraints. Value-based CAQL is generally competitive, and outperforms policy-based methods in heavily constrained environments, sometimes
significantly. We also study the effects of our speed-ups through ablation analysis.





§ PRELIMINARIES









































We consider an infinite-horizon, discounted Markov decision process <cit.>

with states , (continuous) action space , reward function R, transition kernel P, initial state distribution
β and discount factor γ∈[0,1), all having the usual meaning.
A  (stationary, Markovian) policy π specifies a distribution π(·|x) over actions to be taken at state x.
Let Δ be the set of such policies.





The expected cumulative return of π∈Δ is 
J(π):=𝔼[∑_t=0^∞γ^t r_t| P,R,x_0∼β,π]. 
An optimal policy π^* satisfies π^*∈_π∈Δ J(π).


The Bellman operator
F[Q](x,a)=R(x,a) + γ∑_x'∈ P(x'|x,a)max_a'∈Q(x',a') over state-action value function Q

has unique fixed point Q^*(x,a) <cit.>, which is the optimal Q-function Q^*(x,a)=[∑_t=0^∞γ^t R(x_t,a_t)| x_0=x,a_0=a,π^*].
An optimal (deterministic) policy π^* can be extracted from Q^*:
π^*(a|x)=1{a=a^*(x)},  where  a^*(x)∈max_a Q^*(x,a).

For large or continuous state/action spaces, the optimal Q-function can be approximated, e.g.,
using a deep neural network (DNN) as in DQN <cit.>.  In DQN, the value function Q_θ is updated using the value label r+γmax_a'Q_θ^target(x',a'),
where Q_θ^target is a target Q-function. Instead of training these weights jointly, θ^target is updated in a separate iterative fashion using the previous θ for a fixed number of training steps, or by averaging θ^target←τθ+ (1-τ) θ^target
for some small momentum weight τ∈[0,1] <cit.>.
DQN is off-policy—the target is valid no matter how the experience was generated (as long as it
is sufficiently exploratory). Typically, the
loss is minimized over mini-batches B of
past data (x, a, r, x') sampled from a large experience replay buffer R <cit.>. One common loss function for training Q_θ^* is mean squared Bellman error:
min_θ∑_i=1^|B|(Q_θ(x_i,a_i)-r_i-γmax_a'Q_θ^target(x'_i,a'))^2.
Under this loss, RL can be viewed as ℓ_2-regression of Q_θ(·,·) w.r.t. target labels r+γmax_a'Q_θ^target(x',a').
We augment DQN, using double Q-learning for more stable training <cit.>, whose loss is:




    min_θ∑_i=1^|B|(r_i+γ Q_θ^target(x'_i, max_a' Q_θ(x'_i, a'))-Q_θ(x_i,a_i))^2.




A hinge loss can also be used in Q-learning, and has connections to the linear programming (LP) formulation of the MDP (<cit.>).
The optimal Q-network weights can be specified as: min_θ1/|B|∑_i=1^|B| Q_θ(x_i,a_i) +λ(r_i+γmax_a'∈ AQ_θ(x'_i,a') -Q_θ(x_i,a_i))_+, where λ>0 is a tunable penalty w.r.t. constraint: r+γmax_a'∈ AQ_θ(x',a') ≤ Q_θ(x,a), ∀ (x,a,r,x')∈ B.
To stabilize training, we replace the Q-network of the inner maximization
with the target Q-network and the optimal Q-value with the double-Q label,
giving (see Appendix <ref> for details):




    min_θ1/|B|∑_i=1^|B| Q_θ(x_i,a_i) +λ(r_i+γ Q_θ^target(x'_i,max_a' Q_θ(x'_i, a')) -Q_θ(x_i,a_i))_+.







In this work, we assume the Q-function approximation Q_θ to be a feed-forward network. Specifically, let Q_θ be a K-layer feed-forward NN with state-action input (x,a) (where a lies in a d-dimensional real vector space) and hidden layers arranged according to the equations:




    z_1 = (x,a),   _j = W_j-1 z_j-1 + b_j-1,    z_j = h(_j),    j = 2,…,K,    Q_θ(x,a):=c^⊤_K,[Without loss of generality, we simplify the NN by omitting the output bias and output activation function.]




where (W_j,b_j) are the multiplicative and bias weights, c is the output weight of the Q-network, θ=(c,{(W_j,b_j)}_j=1^K-1) are the weights of the Q-network, _j denotes pre-activation values at layer j, and h(·) is the (component-wise) activation function.
For simplicity, in the following analysis, we restrict our attention to the case when the activation functions are ReLU's. 
We also assume that the action space A is a d-dimensional ℓ_∞-ball (a,Δ) with some radius Δ>0 and center a. Therefore, at any arbitrary state x∈ X the max-Q problem can be re-written as q^*_x:=max_a∈ AQ_θ(x,a)=max_{_j}_j=2^K,{z_j}_j=2^K-1{ c^⊤_K: z_1=(x,a), a ∈(a,Δ),  eqs. (<ref>)}.
While the above formulation is intuitive, the nonlinear equality constraints in the neural network formulation (<ref>) makes this problem non-convex and NP-hard <cit.>. 




§ CONTINUOUS ACTION Q-LEARNING ALGORITHM



 
Policy-based methods <cit.> have been widely-used to handle continuous actions in RL.
However, they suffer from several well-known difficulties, e.g., (i) modeling high-dimensional action distributions, (ii) handling action constraints, and (iii) data-inefficiency.
Motivated by earlier work on value-based RL methods, such as QT-Opt <cit.> and actor-expert <cit.>, we
propose Continuous Action Q-learning (CAQL), a general framework for continuous-action value-based RL, in which the Q-function is parameterized by a NN (Eq. <ref>).  One novelty of CAQL is the
formulation of the “max-Q” problem, i.e., the inner maximization in (<ref>) and (<ref>), as a mixed-integer programming (MIP). 

The benefit of the MIP formulation is that it guarantees that we find the optimal action (and its true bootstrapped Q-value)
when computing target labels (and at inference time). We show empirically that this can induce
better performance, especially when the Q-network has sufficient representation power.
Moreover, since MIP can readily model linear and combinatorial constraints, 
it offers considerable flexibility when incorporating complex action constraints in RL.
That said, finding the optimal Q-label (e.g., with MIP) is computationally intensive. To alleviate this, we develop several approximation methods to systematically reduce the computational demands of the inner maximization.
In Sec. <ref>, we introduce the action function to approximate the -policy at inference time, and in Sec. <ref> we propose three techniques, dynamic tolerance, dual filtering, and clustering, to speed up max-Q computation during training.

























 §.§ Plug-N-Play Max-Q Optimizers




 In this section, we illustrate how the max-Q problem, with the Q-function represented by a ReLU network, can be formulated as a MIP, which can be solved using off-the-shelf optimization packages (e.g., SCIP <cit.>, CPLEX <cit.>, Gurobi <cit.>). In addition, we detail how approximate optimizers, specifically,
gradient ascent (GA) and the cross-entropy method (CEM), can trade optimality for speed in max-Q computation within CAQL.
For ease of exposition, we focus on Q-functions parameterized by a feedforward ReLU network. Extending our methodology (including the MIP formulation) to convolutional networks (with ReLU activation and max pooling) is straightforward (see <cit.>). 
While GA and CEM can handle generic activation functions beyond ReLU, our MIP requires additional
approximations for those that are not piecewise linear.












  
Mixed-Integer Programming (MIP)
A trained feed-forward ReLU network can be modeled as a MIP by formulating the nonlinear activation function at each neuron with binary constraints. Specifically, for a ReLU with pre-activation function of form z = max{0, w^⊤ x + b}, where x ∈ [ℓ, u] is a d-dimensional bounded input, w ∈ℝ^d, b ∈ℝ, and ℓ, u ∈ℝ^d are the weights, bias and lower-upper bounds respectively, consider the following set with a binary variable ζ indicating whether the ReLU is active or not:




    R(w,b, ℓ,u) = {(x, z, ζ) | [ z ≥ w^⊤ x + b, z ≥ 0, z ≤ w^⊤ x + b - M^- (1-ζ), z ≤ M^+ ζ,;                                (x, z, ζ) ∈ [ℓ, u] ×ℝ×{0, 1} ]}.




In this formulation, both M^+ = max_x ∈ [ℓ,u] w^⊤ x + b and M^- = min_x ∈ [ℓ,u] w^⊤ x + b can be computed in linear time in d. We assume M^+ > 0 and M^- < 0, otherwise the function can be replaced by z = 0 or z = w^⊤ x + b. These constraints ensure that z is the output of the ReLU: If ζ = 0, then they are reduced to z = 0 ≥ w^⊤ x + b, and if ζ = 1, then they become z = w^⊤ x + b ≥ 0. 

This can be extended to the ReLU network in (<ref>) by chaining copies of intermediate ReLU formulations. More precisely, if the ReLU Q-network has m_j neurons in layer j∈{2, …, K}, for any given state x∈ X, the max-Q problem can be reformulated as the following MIP:

    q^*_x=max      c^⊤ z_K
    s.t.      z_1:=a ∈(a, Δ),
       (z_j-1, z_j,i, ζ_j,i) ∈ R(W_j,i, b_j,i, ℓ_j-1, u_j-1),  j∈{ 2, …, K},  i ∈{ 1, …, m_j},

where ℓ_1=a-Δ, u_1=a+Δ are the (action) input-bound vectors. Since the output layer of the ReLU NN is linear, the MIP objective is linear as well. Here, W_j, i∈^m_j and b_j,i∈ are the weights and bias of neuron i in layer j. Furthermore, ℓ_j,u_j are interval bounds for the outputs of the neurons in layer j for j ≥ 2, and computing them can be done via interval arithmetic or other propagation methods <cit.> from the initial action space bounds (see Appendix <ref> for details). As detailed by <cit.>, this can be further tightened with additional constraints, and its implementation can be found in the tf.opt package described therein. As long as these bounds are redundant, having these additional box constraints will not affect optimality. 
We emphasize that the MIP returns provably global optima, unlike GA and CEM. Even when interrupted with stopping conditions such as a time limit, MIP often produces high-quality solutions in practice.

In theory, this MIP formulation can be solved in time exponential on the number of ReLUs and polynomial on the input size (e.g., by naively solving an LP for each binary variable assignment).
In practice however, a modern MIP solver combines many different techniques to significantly speed up this process, such as branch-and-bound, cutting planes, preprocessing techniques, and primal heuristics <cit.>.
Versions of this MIP model have been used in neural network verification <cit.> and analysis <cit.>, but its application to RL is novel. While
<cit.> also proposed a MIP formulation to solve the planning problem with non-linear state transition dynamics model learned with a NN, it is different than ours, which solves the max-Q problem. 






























  
Gradient Ascent
GA <cit.> is a simple first-order optimization method for finding the (local) optimum of a differentiable objective function, such as a neural network Q-function. At any state x∈ X, given a “seed”

action a_0, the optimal action max_a Q_θ (x, a) is computed iteratively by a_t+1← a_t + η∇_aQ_θ(x,a), 
where η>0 is a step size (either a tunable parameter or computed using back-tracking line search <cit.>). This process repeats until convergence, |Q_θ(x, a_t+1) - Q_θ(x, a_t)| < ϵ, or  a maximum iteration count is reached.





  
Cross-Entropy Method
CEM <cit.> is a derivative-free optimization algorithm. At any given state x∈ X, it samples a batch of N actions {a_i}_i=1^N from A using a fixed distribution (e.g., a Gaussian) and ranks the corresponding Q-values {Q_θ(x,a_i)}_i=1^N. Using the top K<N actions, it then updates the sampling distribution, e.g., using the sample mean and covariance to update the Gaussian. This is repeated until convergence or a maximum iteration count is reached.





 §.§ Action Function



In traditional Q-learning, the policy π^* is “implemented” by acting greedily w.r.t. the learned Q-function: 
π^*(x) = max_a Q_θ (x, a).[Some exploration strategy may be incorporated as well.]
However, computing the optimal action can be expensive in the continuous case, which may be especially problematic
at inference time (e.g.,

when computational power is limited in, say embedded systems, or  real-time response is critical).
To mitigate the problem, we can use an action function π_w:X→ A—effectively a trainable actor network—to approximate the greedy-action mapping π^*.

We train π_w using training data  B={(x_i,q^*_i)}_i=1^|B|,

where q^*_i is the max-Q label at state x_i.

Action function learning is then simply a supervised regression problem: w^* ∈min_w∑_i=1^|B|(q^*_i-Q_θ(x_i, π_w(x_i)))^2. 
This is similar to the notion of “distilling” an optimal policy from max-Q labels, as in actor-expert <cit.>. Unlike actor-expert—a separate stochastic policy network is jointly learned with the Q-function to maximize the likelihood with the underlying optimal policy—our method learns a state-action mapping to approximate max_a Q_θ (x, a)—this does not require distribution matching and is
generally more stable. The use of action function in CAQL is simply optional to
accelerate data collection and inference. 




















 

§ ACCELERATING MAX-Q COMPUTATION

 



In this section, we propose three methods to speed up the computationally-expensive max-Q solution during training:  (i) dynamic tolerance, (ii) dual filtering, and (iii) clustering.




  
Dynamic Tolerance

 Tolerance plays a critical role in the stopping condition of nonlinear optimizers. Intuitively, in the early phase of CAQL, when the Q-function estimate has high Bellman error, it may be wasteful
 to compute a highly accurate max-Q label when a crude estimate can already guide the gradient of CAQL to minimize the Bellman residual.
We can speed up the max-Q solver by dynamically adjusting its tolerance τ>0 based on (a) the TD-error, which measures the estimation error of the optimal Q-function, and (b) the training step t>0, which ensures the bias of the gradient (induced by the sub-optimality of max-Q solver) vanishes asymptotically so that CAQL converges to a stationary point.
While relating tolerance with the Bellman residual is intuitive, it is impossible to calculate that without knowing the max-Q label.  To resolve this circular dependency,
notice that the action function π_w approximates the optimal policy, i.e., π_w(·|x)≈max_aQ_θ(x,·).
We therefore replace the optimal policy with the action function in Bellman residual and propose the dynamic tolerance:
τ_t:=1/|B|∑_i=1^|B||r_i+γ Q_θ^target_t(x'_i,π_w_t(x'_i)) -Q_θ_t(x_i,a_i)|· k_1 · k_2^t,
where k_1>0 and k_2∈[0,1) are tunable parameters. Under standard assumptions, CAQL with dynamic tolerance {τ_t} converges a.s. to a stationary point (Thm. 1, <cit.>).






  
Dual Filtering

The main motivation of dual filtering is to reduce the number of max-Q problems at each CAQL training step. For illustration, consider the formulation of hinge Q-learning  in (<ref>).
Denote by q^*_x',θ^target the max-Q label w.r.t. 
the target Q-network and next state x'.
The structure of the hinge penalty means the TD-error corresponding to sample (x,a,x',r) is inactive whenever
q^*_x',θ^target≤ (Q_θ(x,a)-r)/γ—this data can be discarded.
In dual filtering, we efficiently estimate an upper bound on q^*_x',θ^target using
some convex relaxation to determine which data can be discarded before max-Q optimization.
Specifically, recall that the main source of non-convexity in (<ref>) comes from the equality constraint of the ReLU activation function at each NN layer. Similar to MIP formulation, 
assume we have component-wise bounds (l_j, u_j), j = 2,…,K-1 on the neurons, such that l_j ≤_j ≤ u_j. 
The ReLU 

equality constraint 
(l,u):= {(h,k)∈^2 : h ∈ [l,u], k = [h]_+} can be relaxed using a convex outer-approximation <cit.>:
(l,u) := {(h,k) ∈^2 :  k ≥ h, k ≥ 0, -uh + (u-l)k ≤ -ul }.
We use this approximation to define the relaxed NN equations, which replace the 

nonlinear equality constraints in (<ref>) with the convex set (l,u).

We denote the optimal Q-value w.r.t. the relaxed NN as q̃^*_x', which is by definition an upper bound on q^*_x'_i.
 Hence, the condition: q̃^*_x',θ^target≤ (Q_θ(x,a)-r)/γ is a conservative certificate for checking whether the data (x,a,x',r) is inactive. 
For further speed up, we estimate q̃^*_x' with its dual upper bound (see Appendix <ref> for derivations) q̃_x' := -(_1)^⊤a - m·_1_q -(_1)^⊤ x' + ∑_j=2^K-1∑_s ∈_j l_j(s)[ν_j(s)]_+ - ∑_j=1^K-1ν_j+1^⊤ b_i,
where ν is defined by the following recursion “dual" network:  ν_K := - c,  _j := W_j^⊤ν_j+1,    j = 1,…, K-1,   ν_j := D_j _j,    j= 2,…, K-1,  
and D_s is a diagonal matrix with
[D_j] (s,s) =  1{s ∈_j} +  u_j(s)/(u_j(s)-l_j(s))·1{s ∈_j}, and replace the above certificate with an even more conservative one: 
q_x',θ^target≤(Q_θ(x,a)-r)/γ. 

Although dual filtering is derived for hinge Q-learning, it also applies to the ℓ_2-loss counterpart by replacing the optimal value q^*_x',θ^target with its dual upper-bound estimate q_x',θ^target whenever the verification condition holds (i.e.,  the TD error is negative). Since the dual estimate is greater than the primal, the modified loss function will be a lower bound of the original in (<ref>), i.e., (r+γq̃_x',θ^target -Q_θ(x,a))^2≤ (r+γ q^*_x',θ^target -Q_θ(x,a))^2 whenever r+γq̃_x',θ^target -Q_θ(x,a)≤ 0,
which can stabilize training by reducing over-estimation error.

One can utilize the inactive samples in the action function (π_w) learning problem by replacing the max-Q label q^*_x',θ with its dual approximation q_x',θ. 
Since q_x',θ≥ q^*_x',θ, this replacement will not affect optimality. [One can also use the upper bound q_x',θ as the label for training the action function in Section 3.2. Empirically, this approach often leads to better policy performance.]






  
Clustering

To reduce the number of max-Q solves further still, we apply online state aggregation <cit.>, which picks a number of centroids from the batch of next states B' as the centers of p-metric balls with radius b>0, such that the union of these balls form a minimum covering of B'. 
Specifically, at training step t∈{0,1,…}, denote by C_t(b)⊆ B' the set of next-state centroids.
 For each next state c'∈ C_t(b), we compute the max-Q value q^*_c',θ^target=max_a'Q_θ^target(c',a'), where a^*_c' is the corresponding optimal action. 
 For all remaining next states x'∈ B'∖ C_t(b), we approximate their max-Q values via first-order Taylor series expansion  q̂_x',θ^target:=q^*_c',θ^target+⟨∇_x' Q_θ^target(x', a')|_x'=c',a'=a^*_c', (x'-c')⟩ in which c' is the closest centroid to x', i.e., c'∈min_c'∈ C_t(b)x'-c'_p. By the envelope theorem for arbitrary choice sets <cit.>, the gradient ∇_x'max_a'Q_θ^target(x', a') is equal to ∇_x' Q_θ^target(x', a')|_a'=a^*_x'. 
In this approach the cluster radius r>0 controls the number of max-Q computations, which trades complexity for accuracy in Bellman residual estimation. 
This parameter can either be a tuned or adjusted dynamically (similar to dynamic tolerance), e.g., r_t=k_3· k_4^t with hyperparameters k_3>0 and k_4∈[0,1).
 Analogously,  with this exponentially-decaying cluster radius schedule we can argue that the bias of CAQL gradient (induced by max-Q estimation error due to clustering) vanishes asymptotically, and the corresponding Q-function converges to a stationary point.
 To combine clustering with dual filtering, we define B'_df as the batch of next states that are inconclusive after dual filtering, i.e.,  B'_df={x'∈ B':q_x',θ^target > (Q_θ(x,a)-r)/γ}. Then instead of applying clustering to B' we apply this method onto the refined batch B'_df. 

Dynamic tolerance not only speeds up training, but also improves CAQL's performance (see Tables <ref> and <ref>); thus, we recommend using it by default. Dual filtering and clustering both trade off training speed with performance. These are practical options—with tunable parameters—that allow practitioners to explore their utility in specific domains.





§ EXPERIMENTS ON MUJOCO BENCHMARKS




To illustrate the effectiveness of CAQL, we (i) compare several CAQL variants with several state-of-the-art RL methods on multiple domains, and (ii) assess the trade-off between max-Q computation speed and policy quality via ablation analysis. 





  
Comparison with Baseline RL Algorithms

We compare CAQL with four baseline methods, DDPG <cit.>, TD3 <cit.>, and SAC <cit.>—three popular policy-based deep RL algorithms—and NAF <cit.>, a value-based method using an action-quadratic Q-function. We train CAQL using three different max-Q optimizers, MIP, GA, and CEM.
Note that CAQL-CEM counterpart is similar to QT-Opt <cit.> and CAQL-GA
 reflects some aspects actor-expert <cit.>. These CAQL variants allow assessment of
 the degree to which policy quality is impacted by Q-learning with optimal Bellman residual (using
 MIP) rather than an approximation (using GA or CEM), at the cost of steeper computation.
 
 
To match the implementations of the baselines, we use ℓ_2 loss when training CAQL.
Further ablation analysis on CAQL with ℓ_2 loss vs. hinge loss is provided in Appendix <ref>.

We evaluate CAQL on one classical control benchmark (Pendulum) and five MuJoCo benchmarks (Hopper, Walker2D, HalfCheetah, Ant, Humanoid).[Since the objective of these experiments is largely to evaluate different RL algorithms, we do not exploit problem structures, e.g., symmetry, when training policies.] Different than most previous work, we evaluate the RL algorithms on domains not just with default action ranges, but also using smaller, constrained action ranges (see Table <ref> in Appendix <ref> for action ranges used in our experiments).[Smaller action ranges often induce easier MIP problems in max-Q computation.  However, given the complexity of MIP in more complex environments such as Walker2D, HalfCheetah, Ant, and Humanoid, we run experiments only with action ranges smaller than the defaults.]
The motivation for this is two-fold:
(i) To simulate real-world problems <cit.>, where the restricted ranges represent the safe/constrained action sets; (ii) To validate the hypothesis that action-distribution learning in policy-based methods cannot easily handle such constraints, while CAQL does so, illustrating
its flexibility.
For problems with longer horizons, a larger neural network is often required to learn a good policy, which in turn significantly increases the complexity of the MIP. To reduce this computational cost, we reduce episode length in each experiment from 1000 to 200 steps,

and parameterize the Q-function with a relatively simple 32 × 16 feedforward ReLU network. With shorter episodes and smaller networks, the returns of our experiments are lower than those reported in state-of-the-art RL benchmarks <cit.>.

Details on network architectures and hyperparameters are described in Appendix <ref>.


For the more difficult MuJoCo environments (i.e., Ant, HalfCheetah, Humanoid), the number of training steps is set to 500,000, while for simpler ones (i.e., Pendulum, Hopper, Walker2D), it is set to 200,000.
Policy performance is evaluated every 1000 training iterations, using a policy with
no exploration.
Each measurement is an average return over 10 episodes, each generated using a separate random seed.
To smooth learning curves, data points are averaged over a sliding window of size 6.
Similar to the setting of <cit.>, CAQL measurements are based on trajectories that are
generated by the learned action function instead of the optimal action w.r.t. the Q-function. 










Table <ref> and Figure <ref> show the average return of CAQL and the baselines under the best hyperparameter configurations.
CAQL significantly outperforms NAF on most benchmarks, as well as DDPG, TD3, and SAC on 11 of 14 benchmarks.
Of all the CAQL policies, those trained using MIP are among the best performers in low-dimensional benchmarks (e.g., Pendulum and Hopper). This verifies our conjecture about CAQL:
Q-learning with optimal Bellman residual (using MIP) performs better than using approximation
(using GA, CEM) when the Q-function has sufficient representation power (which is more likely in low-dimensional tasks). Moreover,  CAQL-MIP policies have slightly lower variance than those trained with GA and CEM on most benchmarks.
Table <ref> and Figure <ref> show summary statistics of the returns of CAQL and the baselines on all 320 configurations (32 hyperparameter combinations× 10 random seeds) and illustrates the sensitivity to hyperparameters of each method.
CAQL is least sensitive in 11 of 14 tasks, and policies trained using MIP optimization, specifically,
are best in 6 of 14 tasks. This corroborates the hypothesis that value-based methods are generally more robust to hyperparameters than their policy-based counterparts. 
Table <ref> in Appendix <ref> compares the speed (in terms of average elapsed time) of various max-Q solvers (MIP, GA, and CEM), with MIP clearly the most computationally intensive.

We note that CAQL-MIP suffers from performance degradation in several high-dimensional environments with large action ranges (e.g., Ant [-0.25, 0.25] and Humanoid [-0.25, 0.25]). In these experiments,
its performance is even worse than that of CAQL-GA or CAQL-CEM.
We speculate that this is due to the fact that the small ReLU NN (32 × 16) doesn't have enough representation power to accurately model the Q-functions in more complex tasks, and therefore optimizing for the true max-Q value using an inaccurate function approximation impedes learning.

We also test CAQL using the standard MuJoCo 1000-step episode length, using gradient ascent as the optimizer, and a Q-function is parameterized with a 200 × 100 feedforward ReLU network for Hopper and with 400 × 300 for the rest benchmarks. CAQL-GA is trained using dynamic tolerance and an action function but without dual filtering or clustering. Figure <ref> in Appendix <ref> shows that CAQL-GA performs better than, or similar to, the best of the baseline methods, except on Hopper [-0.25, 0.25]—SAC performed best in that setting, however, it suffers from very high performance variance.





  
Ablation Analysis

We now study the effects of using dynamic tolerance, dual filtering, and clustering on CAQL via two ablation analyses. 
For simplicity, we experiment on standard benchmarks (with full action ranges), and primarily test CAQL-GA using an ℓ_2 loss. Default values on tolerance and maximum iteration are 1e-6 and 200, respectively.

Table <ref> shows how reducing the number of max-Q problems using dual filtering and clustering affects performance of CAQL. Dual filtering (DF) manages to reduce the number of
max-Q problems (from 3.2% to 26.5% across different benchmarks), while maintaining similar performance with the unfiltered CAQL-GA. On top of dual filtering we apply clustering (C) to the set of inconclusive next states B'_df, in which the degree of approximation is controlled by the cluster radius. With a small cluster radius (e.g., b=0.1), clustering further reduces max-Q solves without significantly impacting training performance (and in some cases it actually improves performance), though further increasing the radius would significant degrade performance. To illustrate the full trade-off of max-Q reduction versus policy quality, we also include the Dual method, which eliminates all max-Q computation with the dual approximation. 
Table <ref> shows how dynamic tolerance influences the quality of CAQL policies. Compared with the standard algorithm, with a large tolerance (τ=100) GA achieves a
notable speed up (with only 1 step per max-Q optimization) in training but incurs a loss in performance. GA with dynamic tolerance attains the best of both worlds—it significantly reduces inner-maximization steps (from 29.5% to 77.3% across different problems and initial τ settings), while achieving good performance. 

Additionally, Table <ref> shows the results of CAQL-MIP with dynamic tolerance (i.e., optimality gap). This method significantly reduces both median and variance of the MIP elapsed time, while having better performance. Dynamic tolerance eliminates the high latency in MIP observed in the early phase of training (see Figure <ref>).
































































































































§ CONCLUSIONS AND FUTURE WORK




We proposed Continuous Action Q-learning (CAQL), a general framework for handling continuous actions in value-based RL, in which the Q-function is parameterized by a neural network.
While generic nonlinear optimizers can be naturally integrated with CAQL, we illustrated how the inner maximization of Q-learning can be formulated as mixed-integer programming when the Q-function is parameterized with a ReLU network. CAQL (with action function learning) is a general Q-learning framework that includes many existing value-based methods
such as QT-Opt and actor-expert.

Using several benchmarks with varying degrees of action constraint, we showed that the policy learned by CAQL-MIP generally outperforms those learned by CAQL-GA and CAQL-CEM; and CAQL is competitive
with several state-of-the-art policy-based RL algorithms, and often outperforms
them (and is more robust) in heavily-constrained environments.
Future work includes: extending CAQL to the full batch learning setting, in which the optimal Q-function is trained using only offline data; speeding up the MIP computation of the max-Q problem to make CAQL more scalable; and applying CAQL to real-world RL problems.





iclr2020_conference






§ HINGE Q-LEARNING



Consider an MDP with states X, actions A, transition probability function P, discount factor γ∈[0,1), reward function R, and initial state distribution β.  
We want to find an optimal Q-function by solving the following optimization problem:

    min_Q∑_x∈ X ,a∈ A   p(x,a) Q(x,a) 
    
        Q(x,a)   ≥ R(x,a)+γ∑_x'∈ XP(x'|x,a)max_a'∈ AQ(x',a'),  ∀ x∈ X,a∈ A.

The formulation is based on the LP formulation of MDP (see <cit.> for more details). Here the distribution p(x,a) is given by the data-generating distribution of the replay buffer B. (We assume that the replay buffer is large enough such that it consists of experience from almost all state-action pairs.) It is well-known that one can transform the above constrained optimization problem into an unconstrained one by applying a penalty-based approach (to the constraints). For simplicity, here we stick with a single constant penalty parameter λ≥ 0 (instead of going for a state-action Lagrange multiplier and maximizing that), and a hinge penalty function (·)_+. With a given penalty hyper-parameter λ≥0 (that can be separately optimized), we propose finding the optimal Q-function by solving the following optimization problem:

    min_Q∑_x∈ X ,a∈ Ap(x,a) Q(x,a) +λ(R(x,a)+γ∑_x'∈ XP(x'|x,a)max_a'∈ AQ(x',a') -Q(x,a))_+.


Furthermore, recall that in many off-policy and offline RL algorithms (such as DQN), samples in form of {(x_i,a_i,r_i,x'_i)}_i=1^|B| are independently drawn from the replay buffer, and instead of the optimizing the original objective function, one goes for its unbiased sample average approximation (SAA). However, viewing from the objective function of problem (<ref>), finding an unbiased SAA for this problem might be challenging, due to the non-linearity of hinge penalty function (·)_+. Therefore, alternatively we turn to study the following unconstrained optimization problem:

    min_Q∑_x∈ X ,a∈ Ap(x,a) Q(x,a) +λ∑_x'∈ X P(x'|x,a)(R(x,a)+γmax_a'∈ AQ(x',a') -Q(x,a))_+.


Using the Jensen's inequality for convex functions, one can see that the objective function in (<ref>) is an upper-bound of that in (<ref>). Equality of the Jensen's inequality will hold in the case when transition function is deterministic. (This is similar to the argument of PCL algorithm.) Using Jensen's inequality one justifies that optimization problem (<ref>) is indeed an eligible upper-bound optimization to problem (<ref>).

Recall that p(x,a) is the data-generation distribution of the replay buffer B. The unbiased SAA of problem (<ref>) is therefore given by

    min_Q1/N∑_s=1^N Q(x_i,a_i) +λ(r_i+γmax_a'∈ AQ(x'_i,a') -Q(x_i,a_i))_+,

where {(x_i,a_i,r_i,x'_i)}_s=1^N are the N samples drawn independently from the replay buffer. In the following, we will find the optimal Q function by solving this SAA problem. In general when the state and action spaces are large/uncountable, instead of solving the Q-function exactly (as in the tabular case), we turn to approximate the Q-function with its parametrized form Q_θ, and optimize the set of real weights θ (instead of Q) in problem (<ref>).





§ CONTINUOUS ACTION Q-LEARNING ALGORITHM






 
 

§ DETAILS OF DUAL FILTERING

 
 

Recall that the Q-function NN has a nonlinear activation function, which can be viewed as a nonlinear equality constraint, according to the formulation in (<ref>). To tackle this constraint, <cit.> proposed a convex relaxation of the ReLU non-linearity. Specifically, first, they assume that for given x'∈ X and a' ∈(a) such that z_1=(x',a'), there exists a collection of component-wise bounds (l_j, u_j), j = 2,…,K-1 such that l_j ≤_j ≤ u_j. As long as the bounds are redundant, adding these constraints into primal problem q^*_x' does not affect the optimal value. Second, the ReLU non-linear equality constraint is relaxed using a convex outer-approximation. In particular, for a scalar input a within the real interval [l,u], the exact ReLU non-linearity acting on a is captured by the set 

    (l,u):= {(h,k)∈^2 : h ∈ [l,u], k = [h]_+}.

Its convex outer-approximation is given by:

    (l,u) := {(h,k) ∈^2 :  k ≥ h, k ≥ 0, -uh + (u-l)k ≤ -ul }.

Analogously to (<ref>), define the relaxed NN equations as:


    z_1    = (x',a'),  a' ∈(a,Δ) 
    _j   = W_j-1 z_j-1 + b_j-1,    j = 2,…, K 
    
        (_j, z_j)    ∈(l_j,u_j),    j = 2,…,K-1,



where the third equation above is understood to be component-wise across layer j for each j ∈{2,…,K-1}, i.e., 

    (_j(s), z_j(s)) ∈(l_j(s), u_j(s)),    s = 1,…, n_j,

where n_j is the dimension of hidden layer j. Using the relaxed NN equations, we now propose the following relaxed (convex) verification problem:

  
    q̃^*_x' := max_,z      c^⊤_K + δ_(a̅)(a') + ∑_j=2^K-1δ_(l_j,u_j) (_j,z_j) 
    s.t.     _j = W_j-1 z_j-1 + b_j-1,    j = 2,…,K,


where δ_Λ(·) is the indicator function for set Λ (i.e., δ_Λ(x) = 0 if x ∈Λ and ∞ otherwise). 
Note that the indicator for the vector-ReLU in cost function above is understood to be component-wise, i.e., 

    δ_(l_j,u_j) (_j,z_j) = ∑_s=1^n_jδ_(l_j(s),u_j(s)) (_j(s),z_j(s)),    j = 2,…,K-1.

The optimal value of the relaxed problem, i.e., q̃^*_x' is an upper bound on the optimal value for original problem q^*_x'_i. Thus, the certification one can obtain is the following: if q̃^*_x'≤ (Q_θ(x,a)-r)/γ, then the sample (x,a,x') is discarded for inner maximization. However, if q̃^*_x' > (Q_θ(x,a)-r)/γ, the sample (x,a,x') may or may not have any contribution to the TD-error in the hinge loss function. 

To further speed up the computation of the verification problem, by looking into the dual variables of problem (<ref>), in the next section we propose a numerically efficient technique to estimate a sub-optimal, upper-bound estimate to q̃^*_x', namely q_x'. Therefore, one verification criterion on whether a sample drawn from replay buffer should be discarded for inner-maximization is check whether the following inequality holds:

    q_x'≤Q_θ(x,a)-r/γ.




 §.§ Sub-Optimal Solution to the Relaxed Problem
 

In this section, we detail the sub-optimal lower bound solution to the relaxed problem in (<ref>) as proposed in <cit.>. Let ν_j, j = 2,…, K denote the dual variables for the linear equality constraints in problem (<ref>). The Lagrangian for the relaxed problem in (<ref>) is given by:

    L(,z,ν) =    ( c^⊤_K + ν_K^⊤_K ) + ( δ_(a̅)(a') - ν_2^⊤ W_1 z_1 ) + 
       ∑_j=2^K-1( δ_(l_j,u_j) (_j,z_j) + ν_j^⊤_j - ν_j+1^⊤ W_j z_j ) - ∑_j=1^K-1ν_j+1^⊤ b_j.

Define _j := W_j^⊤ν_j+1 for j= 1,…,K-1, and define ^x'_1=(W^x'_1)^⊤ν_2, ^a'_1=(W^a'_1)^⊤ν_2. Then, given the decoupled structure of L in (_j,z_j), minimizing L w.r.t. (,z) yields the following dual function:

    g(ν) =  -δ^⋆_(a)(^a'_1) - (^x'_1)^⊤ x'- ∑_j=2^K-1δ^⋆_(l_j,u_j)( [ -ν_j;   _j ]) - ∑_j=1^K-1ν_i+1^⊤ b_i      if ν_K = -c 
    
                -∞     else.


Recall that for a real vector space X ⊆^n, let X^* denote the dual space of X with the standard pairing ⟨·, ·⟩ : X × X^* →. For a real-valued function f: X →∪{∞,-∞}, let f^*: X^* →∪{∞,-∞} be its convex conjugate, defined as:
f^*(y) = -inf_x ∈ X( f(x) - ⟨ y,x⟩) = sup_x ∈ X( ⟨ y,x⟩ - f(x) ), ∀ y ∈ X^*. Therefore, the conjugate for the vector-ReLU indicator above takes the following component-wise structure:

    δ^⋆_(l_j,u_j)( [ -ν_j;   _j ]) = ∑_s=1^n_jδ^⋆_(l_j(s),u_j(s)) (-ν_j(s),_j(s)),    j = 2,…, K-1.

Now, the convex conjugate of the set indicator function is given by the set support function. Thus, 

    δ^⋆_(a)(^a'_1) = a^⊤^a'_1 + Δ^a'_1_q,

where ·_q is the l_p-dual norm defined by the identity 1/p + 1/q = 1. To compute the convex conjugate for the ReLU relaxation, we analyze the scalar definition as provided in (<ref>). Specifically, we characterize δ^⋆_(l,u)(p,q) defined by the scalar bounds (l,u), for the dual vector (p,q) ∈^2. There exist 3 possible cases:


Case I: l < u ≤ 0: 

    δ^⋆_(l,u)(p,q) =  p · u       if  p > 0 
    
                                                    p · l       if  p < 0 
    
                                                    0     if  p = 0.

Case II: 0 ≤ l < u:

    δ^⋆_(l,u)(p,q) =  (p + q) · u       if  p + q > 0 
    
                                                    (p + q) · l       if  p + q < 0 
    
                                                    0     if  p = -q.

Case III: l < 0 < u: For this case, the sup will occur either on the line -ux + (u-l)y = -ul or at the origin. Thus, 

    δ^⋆_(l,u)(p,q)    = [ sup_h ∈ [l,u] p· h + uu-l· (h-l)· q ]_+
       = [ sup_h ∈ [l,u]( p + q·uu-l) · h - q· l·uu-l]_+
       = [ (p+q)· u ]_+      if ( p + q·uu-l) > 0 
    
                                            [p· l]_+       if ( p + q·uu-l) < 0 
    [ - q· l·uu-l]_+ = [p· l]_+      if ( p + q·uu-l) = 0.

Applying these in context of equation (<ref>), we calculate the Lagrange multipliers by considering the following cases. 

Case I: l_j(s) < u_j(s) ≤ 0: In this case, since z_j(s) = 0 regardless of the value of _j(s), one can simply remove these variables from problems (<ref>) and (<ref>) by eliminating the j^th row of W_j-1 and b_j-1 and the j^th column of W_i. Equivalently, from (<ref>), one can remove their contribution in (<ref>) by setting ν_j(s) = 0.

Case II: 0 ≤ l_j(s) < u_j(s): In this case, the ReLU non-linearity for (_j(s),z_j(s)) in problems (<ref>) and (<ref>) may be replaced with the convex linear equality constraint z_j(s) = _j(s) with associated dual variable μ. Within the Lagrangian, this would result in a modification of the term 

    δ_(l_j(s),u_j(s)) (_j(s),z_j(s)) + ν_j(s)_j(s) - _j(s) z_j(s)

to 

    μ (z_j(s)-_j(s)) + ν_j(s)_j(s) - _j(s) z_j(s).

Minimizing this over (_j(s),z_j(s)), a non-trivial lower bound (i.e., 0) is obtained only if ν_j(s) = _j(s) = μ. Equivalently, from (<ref>), we set ν_j(s) = _j(s).

Case III: For the non-trivial third case, where l_j(s) < 0 < u_j(s), notice that due to , the dual function g(ν) is not decoupled across the layers. In order to get a sub-optimal, but analytical solution to the dual optimization, we will optimize each term within the first sum in (<ref>) independently. To do this, notice that the quantity in sub-case I in (<ref>) is strictly greater than the other two sub-cases. Thus, the best bound is obtained by using the third sub-case, which corresponds to setting:

    ν_j(s) = _j(s) u_j(s)u_j(s)-l_j(s).


Combining all the previous analysis, we now calculate the dual of the solution to problem (<ref>). Let _j := {s ∈ℕ_n_j : u_j(s) ≤ 0 }, _j := {s ∈ℕ_n_j: l_j(s) ≥ 0}, and _j := ℕ_n_j∖ (_j ∪_j). Using the above case studies, a sub-optimal (upper-bound) dual solution to the primal solution J̃_x' in problem (<ref>) is given by

    q_x' := -(^a'_1)^⊤a - Δ^a'_1_q -(^x_1)^⊤ x + ∑_j=2^K-1∑_s∈_j l_j(s)[ν_j(s)]_+ - ∑_j=1^K-1ν_j+1^⊤ b_i,

where ν is defined by the following recursion, termed the “dual" network:
  
    ν_K := - c,  _j := W_j^⊤ν_j+1,    j = 1,…, K-1 ,  ν_j := D_j _j,    j = 2,…, K-1,

and D_j is a diagonal matrix with

    [D_j] (s,s) =  0       if  s ∈_j 
    
                                    1       if  s ∈_j 
    u_j(s)u_j(s)-l_j(s)      if  s∈_j.




 §.§ Computing Pre-Activation Bounds


For k ∈{3,…,K-1}, define the k-partial NN as the set of equations:
  
    z_1 = (x',a'),  _j = W_j-1 z_j-1 + b_j-1,    j=2,…,k,   z_j = h(_j),    j = 2,…,k-1.

Finding the lower bound l_k for _k involves solving the following problem:

    min_,z      e_s^⊤_k 
    s.t.      z_1 = (x',a'),    a' ∈(a,Δ),  eq. (<ref>),

where e_s is a one-hot vector with the non-zero element in the s-th entry, for s ∈{1,…,n_k}. Similarly, we obtain u_k by maximizing the objective above. Assuming we are given bounds {l_j, u_j}_j=2^k-1, we can employ the same convex relaxation technique and approximate dual solution as for the verification problem (since we are simply optimizing a linear function of the output of the first k layers of the NN). Doing this recursively allows us to compute the bounds {l_j, u_j} for j=3,…,K-1. The recursion is given in Algorithm 1 in <cit.> and is based on the matrix form of the recursion in (<ref>), i.e., with c replaced with I and -I, so that the quantity in (<ref>) is vector-valued.





§ EXPERIMENTAL DETAILS









We use a two hidden layer neural network with ReLU activation (32 units in the first layer and 16 units in the second layer) for both the Q-function and the action function.
The input layer for the Q-function is a concatenated vector of state representation and action variables.
The Q-function has a single output unit (without ReLU).
The input layer for the action function is only the state representation.
The output layer for the action function has d units (without ReLU), where d is the action dimension of a benchmark environment.
We use SCIP 6.0.0 <cit.> for the MIP solver.
A time limit of 60 seconds and a optimality gap limit of 10^-4 are used for all experiments.
For GA and CEM, a maximum iterations of 20 and a convergence threshold of 10^-6 are used for all experiments if not stated otherwise.




§ ADDITIONAL EXPERIMENTAL RESULTS






 §.§ Optimizer Scalability



Table <ref> shows the average elapsed time of various optimizers computing max-Q in the experiment setup described in Appendix <ref>.
MIP is more robust to action dimensions than GA and CEM.
MIP latency depends on the state of neural network weights.
It takes longer time with highly dense NN weights, but on the other hand, it can be substantially quicker with sparse NN weights.
Figure <ref> shows the average elapsed time of MIP over training steps for various benchmarks.
We have observed that MIP is very slow in the beginning of the training phase but it quickly becomes faster.
This trend is observed for most benchmarks except Humanoid.
We speculate that the NN weights for the Q-function are dense in the beginning of the training phase, but it is gradually structurized (e.g, sparser weights) so that it becomes an easier problem for MIP.















 §.§ Additional Results











 §.§ Ablation Analysis










































































































































































































































































































