{'fraction_non_alphanumeric': 0.05011206880842611, 'fraction_numerical': 0.01066020372833792, 'mean_word_length': 4.223988576868158, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Policy Optimization via Importance Sampling

Policy optimization is an effective reinforcement learning approach to solve continuous control tasks. Recent achievements have shown that alternating online and offline optimization is a successful choice for efficient trajectory reuse. However, deciding when to stop optimizing and collect new trajectories is non-trivial, as it requires to account for the variance of the objective function estimate. In this paper, we propose a novel, model-free, policy search algorithm, POIS, applicable in both action-based and parameter-based settings. We first derive a high-confidence bound for importance sampling estimation; then we define a surrogate objective function, which is optimized offline whenever a new batch of trajectories is collected. Finally, the algorithm is tested on a selection of continuous control tasks, with both linear and deep policies, and compared with state-of-the-art policy optimization methods.


Introduction
In recent years, policy search methods [9] have proved to be valuable Reinforcement Learning (RL) [49] approaches thanks to their successful achievements in continuous control tasks [e.g., 22, 41, 43,42], robotic locomotion [e.g., 52,19] and partially observable environments [e.g., 27]. These algorithms can be roughly classified into two categories: action-based methods [50,33] and parameter-based methods [44]. The former, usually known as policy gradient (PG) methods, perform a search in a parametric policy space by following the gradient of the utility function estimated by means of a batch of trajectories collected from the environment [49]. In contrast, in parameterbased methods, the search is carried out directly in the space of parameters by exploiting global optimizers [e.g., 40, 15,47,51] or following a proper gradient direction like in Policy Gradients with Parameter-based Exploration (PGPE) [44,62,45]. A major question in policy search methods is: how should we use a batch of trajectories in order to exploit its information in the most efficient way? On one hand, on-policy methods leverage on the batch to perform a single gradient step, after which new trajectories are collected with the updated policy. Online PG methods are likely the most widespread policy search approaches: starting from the traditional algorithms based on stochastic policy gradient [50], like REINFORCE [63] and G(PO)MDP [3], moving toward more modern methods, such as Trust Region Policy Optimization (TRPO) [41]. These methods, however, rarely exploit the available trajectories in an efficient way, since each batch is thrown away after just one gradient update. On the other hand, off-policy methods maintain a behavioral policy, used to explore the environment and to collect samples, and a target policy which is optimized. The concept of offpolicy learning is rooted in value-based RL [61,29,26] and it was first adapted to PG in [8], using an actor-critic architecture. The approach has been extended to Deterministic Policy Gradient (DPG) [46], which allows optimizing deterministic policies while keeping a stochastic policy for exploration.
More recently, an efficient version of DPG coupled with a deep neural network to represent the policy has been proposed, named Deep Deterministic Policy Gradient (DDPG) [22]. In the parameter-based framework, even though the original formulation [44] introduces an online algorithm, an extension has been proposed to efficiently reuse the trajectories in an offline scenario [66]. Furthermore, PGPE-like approaches allow overcoming several limitations of classical PG, like the need for a stochastic policy and the high variance of the gradient estimates. 1 While on-policy algorithms are, by nature, online, as they need to be fed with fresh samples whenever the policy is updated, off-policy methods can take advantage of mixing online and offline optimization. This can be done by alternately sampling trajectories and performing optimization epochs with the collected data. A prime example of this alternating procedure is Proximal Policy Optimization (PPO) [43], that has displayed remarkable performance on continuous control tasks. Off-line optimization, however, introduces further sources of approximation, as the gradient w.r.t. the target policy needs to be estimated (off-policy) with samples collected with a behavioral policy. A common choice is to adopt an importance sampling (IS) [28,16] estimator in which each sample is reweighted proportionally to the likelihood of being generated by the target policy. However, directly optimizing this utility function is impractical since it displays a wide variance most of the times [28]. Intuitively, the variance increases proportionally to the distance between the behavioral and the target policy; thus, the estimate is reliable as long as the two policies are close enough. Preventing uncontrolled updates in the space of policy parameters is at the core of the natural gradient approaches [1] applied effectively both on PG methods [17,32,62] and on PGPE methods [25]. More recently, this idea has been captured (albeit indirectly) by TRPO, which optimizes via (approximate) natural gradient a surrogate objective function, derived from safe RL [17,34], subject to a constraint on the Kullback-Leibler divergence between the behavioral and target policy. 2 Similarly, PPO performs a truncation of the importance weights to discourage the optimization process from going too far. Although TRPO and PPO, together with DDPG, represent the state-of-the-art policy optimization methods in RL for continuous control, they do not explicitly encode in their objective function the uncertainty injected by the importance sampling procedure. A more theoretically grounded analysis has been provided for policy selection [10], model-free [55] and model-based [53] policy evaluation (also accounting for samples collected with multiple behavioral policies), and combined with options [14]. Subsequently, in [54] these methods have been extended for policy improvement, deriving a suitable concentration inequality for the case of truncated importance weights. Unfortunately, these methods are hardly scalable to complex control tasks. A more detailed review of the state-of-the-art policy optimization algorithms is reported in Appendix A.
In this paper, we propose a novel, model-free, actor-only, policy optimization algorithm, named Policy Optimization via Importance Sampling (POIS) that mixes online and offline optimization to efficiently exploit the information contained in the collected trajectories. POIS explicitly accounts for the uncertainty introduced by the importance sampling by optimizing a surrogate objective function. The latter captures the trade-off between the estimated performance improvement and the variance injected by the importance sampling. The main contributions of this paper are theoretical, algorithmic and experimental. After revising some notions about importance sampling (Section 3), we propose a concentration inequality, of independent interest, for high-confidence "off-distribution" optimization of objective functions estimated via importance sampling (Section 4). Then we show how this bound can be customized into a surrogate objective function in order to either search in the space of policies (Action-based POIS) or to search in the space of parameters (Parameter-bases POIS). The resulting algorithm (in both the action-based and the parameter-based flavor) collects, at each iteration, a set of trajectories. These are used to perform offline optimization of the surrogate objective via gradient ascent (Section 5), after which a new batch of trajectories is collected using the optimized policy. Finally, we provide an experimental evaluation with both linear policies and deep neural policies to illustrate the advantages and limitations of our approach compared to state-of-the-art algorithms (Section 6) on classical control tasks [11,56]. The proofs for all Theorems and Lemmas are reported in Appendix B. The implementation of POIS can be found at https://github.com/T3p/pois.

Preliminaries
A discrete-time Markov Decision Process (MDP) [36] is defined as a tuple M = (S, A, P, R, γ, D) where S is the state space, A is the action space, P (·|s, a) is a Markovian transition model that assigns for each state-action pair (s, a) the probability of reaching the next state s , γ ∈ [0, 1] is the discount factor, R(s, a) ∈ [−R max , R max ] assigns the expected reward for performing action a in state s and D is the distribution of the initial state. The behavior of an agent is described by a policy π(·|s) that assigns for each state s the probability of performing action a. A trajectory τ ∈ T is a sequence of state-action pairs τ = (s τ,0 , a τ,0 , . . . , s τ,H−1 , a τ,H−1 , s τ,H ), where H is the actual trajectory horizon. The performance of an agent is evaluated in terms of the expected return, i.e., the expected discounted sum of the rewards collected along the trajectory: is the trajectory return. We focus our attention to the case in which the policy belongs to a parametric policy space Π Θ = {π θ : θ ∈ Θ ⊆ R p }. In parameter-based approaches, the agent is equipped with a hyperpolicy ν used to sample the policy parameters at the beginning of each episode. The hyperpolicy belongs itself to a parametric hyperpolicy space N P = {ν ρ : ρ ∈ P ⊆ R r }. The expected return can be expressed, in the parameter-based case, as a double expectation: one over the policy parameter space Θ and one over the trajectory space T : where p(τ |θ) = D(s 0 ) H−1 t=0 π θ (a t |s t )P (s t+1 |s t , a t ) is the trajectory density function. The goal of a parameter-based learning agent is to determine the hyperparameters ρ * so as to maximize J D (ρ). If ν ρ is stochastic and differentiable, the hyperparameters can be learned according to the gradient ascent update: Since the stochasticity of the hyperpolicy is a sufficient source of exploration, deterministic action policies of the kind π θ (a|s) = δ(a − u θ (s)) are typically considered, where δ is the Dirac delta function and u θ is a deterministic mapping from S to A. In the action-based case, on the contrary, the hyperpolicy ν ρ is a deterministic distribution ν ρ (θ) = δ(θ − g(ρ)), where g(ρ) is a deterministic mapping from P to Θ. For this reason, the dependence on ρ is typically not represented and the expected return expression simplifies into a single expectation over the trajectory space T : An action-based learning agent aims to find the policy parameters θ * that maximize J D (θ). In this case, we need to enforce exploration by means of the stochasticity of π θ . For stochastic and differentiable policies, learning can be performed via gradient ascent:

Evaluation via Importance Sampling
In off-policy evaluation [55,53], we aim to estimate the performance of a target policy π T (or hyperpolicy ν T ) given samples collected with a behavioral policy π B (or hyperpolicy ν B ). More generally, we face the problem of estimating the expected value of a deterministic bounded function f ( f ∞ < +∞) of random variable x taking values in X under a target distribution P , after having collected samples from a behavioral distribution Q. The importance sampling estimator (IS) [6,28] corrects the distribution with the importance weights (or Radon-Nikodym derivative or likelihood ratio) w P/Q (x) = p(x)/q(x): where x = (x 1 , x 2 , . . . , x N ) T is sampled from Q and we assume q(x) > 0 whenever f (x)p(x) = 0. This estimator is unbiased (E x∼Q [ µ P/Q ] = E x∼P [f (x)]) but it may exhibit an undesirable behavior due to the variability of the importance weights, showing, in some cases, infinite variance. Intuitively, the magnitude of the importance weights provides an indication of how much the probability measures P and Q are dissimilar. This notion can be formalized by the Rényi divergence [39,58], an information-theoretic dissimilarity index between probability measures.
Rényi divergence Let P and Q be two probability measures on a measurable space (X , F) such that P Q (P is absolutely continuous w.r.t. Q) and Q is σ-finite. Let P and Q admit p and q as Lebesgue probability density functions (p.d.f.), respectively. The α-Rényi divergence is defined as: where dP/ dQ is the Radon-Nikodym derivative of P w.r.t. Q and α ∈ [0, ∞]. Some remarkable cases are: α = 1 when D 1 (P Q) = D KL (P Q) and α = ∞ yielding D ∞ (P Q) = log ess sup X dP/ dQ. Importing the notation from [7], we indicate the exponentiated α-Rényi divergence as d α (P Q) = exp (D α (P Q)). With little abuse of notation, we will replace D α (P Q) with D α (p q) whenever possible within the context.
The Rényi divergence provides a convenient expression for the moments of the importance weights: [7]. To mitigate the variance problem of the IS estimator, we can resort to the self-normalized importance sampling estimator (SN) [6]: where is the self-normalized importance weight. Differently from µ P/Q , µ P/Q is biased but consistent [28] and it typically displays a more desirable behavior because of its smaller variance. 3 Given the realization x 1 , x 2 , . . . , x N we can interpret the SN estimator as the expected value of f under an approximation of the distribution P made by N deltas, i.e., p( The problem of assessing the quality of the SN estimator has been extensively studied by the simulation community, producing several diagnostic indexes to indicate when the weights might display problematic behavior [28]. The effective sample size (ESS) was introduced in [21] as the number of samples drawn from P so that the variance of the Monte Carlo estimator µ P/P is approximately equal to the variance of the SN estimator µ P/Q computed with N samples. Here we report the original definition and its most common estimate: The ESS has an interesting interpretation: if d 2 (P Q) = 1, i.e., P = Q almost everywhere, then ESS = N since we are performing Monte Carlo estimation. Otherwise, the ESS decreases as the dissimilarity between the two distributions increases. In the literature, other ESS-like diagnostics have been proposed that also account for the nature of f [23].

Optimization via Importance Sampling
The off-policy optimization problem [54] can be formulated as finding the best target policy π T (or hyperpolicy ν T ), i.e., the one maximizing the expected return, having access to a set of samples collected with a behavioral policy π B (or hyperpolicy ν B ). In a more abstract sense, we aim to determine the target distribution P that maximizes E x∼P [f (x)] having samples collected from the fixed behavioral distribution Q. In this section, we analyze the problem of defining a proper objective function for this purpose. Directly optimizing the estimator µ P/Q or µ P/Q is, in most of the cases, unsuccessful. With enough freedom in choosing P , the optimal solution would assign as much probability mass as possible to the maximum value among f (x i ). Clearly, in this scenario, the estimator is unreliable and displays a large variance. For this reason, we adopt a risk-averse approach and we decide to optimize a statistical lower bound of the expected value E x∼P [f (x)] that holds with high confidence. We start by analyzing the behavior of the IS estimator and we provide the following result that bounds the variance of µ P/Q in terms of the Renyi divergence.
Lemma 4.1. Let P and Q be two probability measures on the measurable space (X , F) such that P Q. Let x = (x 1 , x 2 , . . . , x N ) T i.i.d. random variables sampled from Q and f : X → R be a 3 Note that µ P/Q ≤ f ∞. Therefore, its variance is always finite.
bounded function ( f ∞ < +∞). Then, for any N > 0, the variance of the IS estimator µ P/Q can be upper bounded as: When P = Q almost everywhere, we get Var x∼Q µ Q/Q ≤ 1 N f 2 ∞ , a well-known bound on the variance of a Monte Carlo estimator. Recalling the definition of ESS (6) we can rewrite the previous bound as: Var x∼Q µ P/Q ≤ f 2 ∞ ESS(P Q) , i.e., the variance scales with ESS instead of N . While µ P/Q can have unbounded variance even if f is bounded, the SN estimator µ P/Q is always bounded by f ∞ and therefore it always has a finite variance. Since the normalization term makes all the samples w P/Q (x i )f (x i ) interdependent, an exact analysis of its bias and variance is more challenging. Several works adopted approximate methods to provide an expression for the variance [16]. We propose an analysis of bias and variance of the SN estimator in Appendix D.

Concentration Inequality
Finding a suitable concentration inequality for off-policy learning was studied in [55] for offline policy evaluation and subsequently in [54] for optimization. On one hand, fully empirical concentration inequalities, like Student-T, besides the asymptotic approximation, are not suitable in this case since the empirical variance needs to be estimated with importance sampling as well injecting further uncertainty [28]. On the other hand, several distribution-free inequalities like Hoeffding require knowing the maximum of the estimator, which might not exist (d ∞ (P Q) = ∞) for the IS estimator. Constraining d ∞ (P Q) to be finite often introduces unacceptable limitations. For instance, in the case of univariate Gaussian distributions, it prevents a step that selects a target variance larger than the behavioral one from being performed (see Appendix C). 4 Even Bernstein inequalities [4], are hardly applicable since, for instance, in the case of univariate Gaussian distributions, the importance weights display a fat tail behavior (see Appendix C). We believe that a reasonable trade-off is to require the variance of the importance weights to be finite, that is equivalent to require d 2 (P Q) < ∞, i.e., σ P < 2σ Q for univariate Gaussians. For this reason, we resort to Chebyshev-like inequalities and we propose the following concentration bound derived from Cantelli's inequality and customized for the IS estimator. Theorem 4.1. Let P and Q be two probability measures on the measurable space (X , F) such that P Q and d 2 (P Q) < +∞. Let x 1 , x 2 , . . . , x N be i.i.d. random variables sampled from Q, and f : X → R be a bounded function ( f ∞ < +∞). Then, for any 0 < δ ≤ 1 and N > 0 with probability at least 1 − δ it holds that: The bound highlights the interesting trade-off between the estimated performance and the uncertainty introduced by changing the distribution. The latter enters in the bound as the 2-Rényi divergence between the target distribution P and the behavioral distribution Q. Intuitively, we should trust the estimator µ P/Q as long as P is not too far from Q. For the SN estimator, accounting for the bias, we are able to obtain a bound (reported in Appendix D), with a similar dependence on P as in Theorem 4.1, albeit with different constants. Renaming all constants involved in the bound of Theorem 4.1 as λ = f ∞ (1 − δ)/δ, we get a surrogate objective function. The optimization can be carried out in different ways. The following section shows why using the natural gradient could be a successful choice in case P and Q can be expressed as parametric differentiable distributions.

Importance Sampling and Natural Gradient
We can look at a parametric distribution P ω , having p ω as a density function, as a point on a probability manifold with coordinates ω ∈ Ω. If p ω is differentiable, the Fisher Information Matrix (FIM) [38, 2] is defined as: F(ω) = X p ω (x)∇ ω log p ω (x)∇ ω log p ω (x) T dx. This matrix is, up to Algorithm 1 Action-based POIS Initialize θ 0 0 arbitrarily for j = 0, 1, 2, ..., until convergence do Collect N trajectories with π θ j 0 for k = 0, 1, 2, ..., until convergence do Algorithm 2 Parameter-based POIS Initialize ρ 0 0 arbitrarily for j = 0, 1, 2, ..., until convergence do Sample N policy parameters θ j i from ν ρ j 0 Collect a trajectory with each π θ j i for k = 0, 1, 2, ..., until convergence do a scale, an invariant metric [1] on parameter space Ω, i.e., κ(ω − ω) T F(ω)(ω − ω) is independent on the specific parameterization and provides a second order approximation of the distance between p ω and p ω on the probability manifold up to a scale factor κ ∈ R. Given a loss function L(ω), we define the natural gradient [1,18] as ∇ ω L(ω) = F −1 (ω)∇ ω L(ω), which represents the steepest ascent direction in the probability manifold. Thanks to the invariance property, there is a tight connection between the geometry induced by the Rényi divergence and the Fisher information metric.
, and for the exponentiated This result provides an approximate expression for the variance of the importance weights, as . It also justifies the use of natural gradients in off-distribution optimization, since a step in natural gradient direction has a controllable effect on the variance of the importance weights.

Policy Optimization via Importance Sampling
In this section, we discuss how to customize the bound provided in Theorem 4.1 for policy optimization, developing a novel model-free actor-only policy search algorithm, named Policy Optimization via Importance Sampling (POIS). We propose two versions of POIS: Action-based POIS (A-POIS), which is based on a policy gradient approach, and Parameter-based POIS (P-POIS), which adopts the PGPE framework. A more detailed description of the implementation aspects is reported in Appendix E.

Action-based POIS
In Action-based POIS (A-POIS) we search for a policy that maximizes the performance index J D (θ) within a parametric space Π Θ = {π θ : θ ∈ Θ ⊆ R p } of stochastic differentiable policies. In this context, the behavioral (resp. target) distribution Q (resp. P ) becomes the distribution over trajectories p(·|θ) (resp. p(·|θ )) induced by the behavioral policy π θ (resp. target policy π θ ) and f is the trajectory return R(τ ) which is uniformly bounded as |R(τ )| ≤ R max 5 The surrogate loss function cannot be directly optimized via gradient ascent since computing d α p(·|θ ) p(·|θ) requires the approximation of an integral over the trajectory space and, for stochastic environments, to know the transition model P , which is unknown in a model-free setting. Simple bounds to this quantity, like d α p(·|θ ) p(·|θ) ≤ sup s∈S d α (π θ (·|s) π θ (·|s)) H , besides being hard to compute due to the presence of the supremum, are extremely conservative since the Rényi divergence is raised to the horizon H. We suggest the replacement of the Rényi divergence with an estimate H−1 t=0 d 2 (π θ (·|s τi,t ) π θ (·|s τi,t )) defined only in terms of the policy Rényi divergence (see Appendix E.2 for details). Thus, we obtain the following surrogate objective: where . We consider the case in which π θ (·|s) is a Gaussian distribution over actions whose mean depends on the state and whose covariance is stateindependent and diagonal: N (u µ (s), diag(σ 2 )), where θ = (µ, σ). The learning process mixes online and offline optimization. At each online iteration j, a dataset of N trajectories is collected by executing in the environment the current policy π θ j 0 . These trajectories are used to optimize the surrogate loss function L A−POIS λ . At each offline iteration k, the parameters are updated via gradient ascent: is a positive semi-definite matrix (e.g., F(θ j k ), the FIM, for natural gradient) 6 . The pseudo-code of POIS is reported in Algorithm 1.

Parameter-based POIS
In the Parameter-based POIS (P-POIS) we again consider a parametrized policy space Π Θ = {π θ : θ ∈ Θ ⊆ R p }, but π θ needs not be differentiable. The policy parameters θ are sampled at the beginning of each episode from a parametric hyperpolicy ν ρ selected in a parametric space The goal is to learn the hyperparameters ρ so as to maximize J D (ρ). In this setting, the distributions Q and P of Section 4 correspond to the behavioral ν ρ and target ν ρ hyperpolicies, while f remains the trajectory return R(τ ). The importance weights [66] must take into account all sources of randomness, derived from sampling a policy parameter θ and a trajectory τ : νρ(θ) . In practice, a Gaussian hyperpolicy ν ρ with diagonal covariance matrix is often used, i.e., N (µ, diag(σ 2 )) with ρ = (µ, σ). The policy is assumed to be deterministic: π θ (a|s) = δ(a − u θ (s)), where u θ is a deterministic function of the state s [e.g., 45,13]. A first advantage over the action-based setting is that the distribution of the importance weights is entirely known, as it is the ratio of two Gaussians and the Rényi divergence d 2 (ν ρ ν ρ ) can be computed exactly [5] (see Appendix C). This leads to the following surrogate objective: where each trajectory τ i is obtained by running an episode with action policy π θi , and the corresponding policy parameters θ i are sampled independently from hyperpolicy ν ρ , at the beginning of each episode. The hyperpolicy parameters are then updated offline as ρ j Algorithm 2 for the complete pseudo-code). A further advantage w.r.t. the action-based case is that the FIM F(ρ) can be computed exactly, and it is diagonal in the case of a Gaussian hyperpolicy with diagonal covariance matrix, turning a problematic inversion into a trivial division (the FIM is block-diagonal in the more general case of a Gaussian hyperpolicy, as observed in [25]). This makes natural gradient much more enticing for P-POIS.

Experimental Evaluation
In this section, we present the experimental evaluation of POIS in its two flavors (action-based and parameter-based). We first provide a set of empirical comparisons on classical continuous control tasks with linearly parametrized policies; we then show how POIS can be also adopted for learning deep neural policies. In all experiments, for the A-POIS we used the IS estimator, while for P-POIS we employed the SN estimator. All experimental details are provided in Appendix F.

Linear Policies
Linear parametrized Gaussian policies proved their ability to scale on complex control tasks [37]. In this section, we compare the learning performance of A-POIS and P-POIS against TRPO [41] and PPO [43] on classical continuous control benchmarks [11]. In Figure 1, we can see that both versions of POIS are able to significantly outperform both TRPO and PPO in the Cartpole environments, especially the P-POIS. In the Inverted Double Pendulum environment the learning curve of P-POIS is remarkable while A-POIS displays a behavior comparable to PPO. In the Acrobot task, P-POIS displays a better performance w.r.t. TRPO and PPO, but A-POIS does not keep up. In Mountain Car, we see yet another behavior: the learning curves of TRPO, PPO and P-POIS are almost one-shot (even if PPO shows a small instability), while A-POIS fails to display such a fast convergence. Finally, in the Inverted Pendulum environment, TRPO and PPO outperform both versions of POIS. This example highlights a limitation of our approach. Since POIS performs an importance sampling procedure at trajectory level, it cannot assign credit to good actions in bad trajectories. On the contrary, weighting each sample, TRPO and PPO are able also to exploit good trajectory segments. In principle, this problem can be mitigated in POIS by resorting to per-decision importance sampling [35], in which the weight is assigned to individual rewards instead of trajectory returns. Overall, POIS displays a performance comparable with TRPO and PPO across the tasks. In particular, P-POIS displays a better performance w.r.t. A-POIS. However, this ordering is not maintained when moving to more complex policy architectures, as shown in the next section.
In Figure 2 we show, for several metrics, the behavior of A-POIS when changing the δ parameter in the Cartpole environment. We can see that when δ is small (e.g., 0.2), the Effective Sample Size (ESS) remains large and, consequently, the variance of the importance weights (Var[w]) is small. This means that the penalization term in the objective function discourages the optimization process from selecting policies which are far from the behavioral policy. As a consequence, the displayed behavior is very conservative, preventing the policy from reaching the optimum. On the contrary, when δ approaches 1, the ESS is smaller and the variance of the weights tends to increase significantly. Again, the performance remains suboptimal as the penalization term in the objective function is too light. The best behavior is obtained with an intermediate value of δ, specifically 0.4.

Deep Neural Policies
In this section, we adopt a deep neural network (3 layers: 100, 50, 25 neurons each) to represent the policy. The experiment setup is fully compatible with the classical benchmark [11]. While A-POIS can be directly applied to deep neural networks, P-POIS exhibits some critical issues. A highly dimensional hyperpolicy (like a Gaussian from which the weights of an MLP policy are  sampled) can make d 2 (ν ρ ν ρ ) extremely sensitive to small parameter changes, leading to overconservative updates. 7 A first practical variant comes from the insight that d 2 (ν ρ ν ρ )/N is the inverse of the effective sample size, as reported in Equation 6. We can obtain a less conservative (although approximate) surrogate function by replacing it with 1/ ESS(ν ρ ν ρ ). Another trick is to model the hyperpolicy as a set of independent Gaussians, each defined over a disjoint subspace of Θ (implementation details are provided in Appendix E.5). In Table 1, we augmented the results provided in [11] with the performance of POIS for the considered tasks. We can see that A-POIS is able to reach an overall behavior comparable with the best of the action-based algorithms, approaching TRPO and beating DDPG. Similarly, P-POIS exhibits a performance similar to CEM [51], the best performing among the parameter-based methods. The complete results are reported in Appendix F.

Discussion and Conclusions
In this paper, we presented a new actor-only policy optimization algorithm, POIS, which alternates online and offline optimization in order to efficiently exploit the collected trajectories, and can be used in combination with action-based and parameter-based exploration. In contrast to the state-ofthe-art algorithms, POIS has a strong theoretical grounding, since its surrogate objective function derives from a statistical bound on the estimated performance, that is able to capture the uncertainty induced by importance sampling. The experimental evaluation showed that POIS, in both its versions (action-based and parameter-based), is able to achieve a performance comparable with TRPO, PPO and other classical algorithms on continuous control tasks. Natural extensions of POIS could focus on employing per-decision importance sampling, adaptive batch size, and trajectory reuse. Future work also includes scaling POIS to high-dimensional tasks and highly-stochastic environments. We believe that this work represents a valuable starting point for a deeper understanding of modern policy optimization and for the development of effective and scalable policy search methods.
[21] Augustine Kong. A note on importance sampling using standardized weights.

Index of the Appendix
In the following, we briefly recap the contents of the Appendix.
-Appendix A shows a more detailed comparison of POIS with the policy-search algorithms. Table 2 summarizes some features of the considered methods.

A Related Works
Policy optimization algorithms can be classified according to different dimensions ( Table 2). It is by now established, in the policy-based RL community, that effective algorithms, either on-policy or off-policy, should account for the variance of the gradient estimate. Early attempts, in the class of action-based algorithms, are the usage of a baseline to reduce the estimated gradient variance without introducing bias [3,33]. A similar rationale is at the basis of actor-critic architectures [20,50,32], in which an estimate of the value function is used to reduce uncertainty. Baselines are typically constant (REINFORCE), time-dependent (G(PO)MDP) or state-dependent (actor-critic), but these approaches have been recently extended to account for action-dependent baselines [57,64]. Even though parameter-based algorithms are, by nature, affected by smaller variance w.r.t. action-based ones, similar baselines can be derived [65]. A first dichotomy in the class of policy-based algorithms comes when considering the minimal unit used to compute the gradient. Episode-based (or episodic) approaches [e.g., 63,3] perform the gradient estimation by averaging the gradients of each episode which need to have a finite horizon. On the contrary, step-based approaches [e.g., 41, 43, 22], derived from the Policy Gradient Theorem [50], can estimate the gradient by averaging over timesteps. The latter requires a function approximator (a critic) to estimate the Q-function, or directly the advantage function [42]. When coming to the on/off-policy dichotomy, the previous distinction has a relevant impact. Indeed, episode-based approaches need to perform importance sampling on trajectories, thus the importance weights are the products of policy ratios for all executed actions within a trajectory, whereas step-based algorithms need just to weight each sample with the corresponding policy ratio. The latter case helps to keep the value of the importance weights close to one, but the need to have a critic prevents from a complete analysis of the uncertainty since the bias/variance injected by the critic is hard to compute [20]. Moreover, in the off-policy scenario, it is necessary to control some notion of dissimilarity between the behavioral and target policy, as the variance increases when moving too far. This is the case of TRPO [41], where the regularization constraint based on the Kullback-Leibler divergence helps controlling the importance weights but originates from an exact bound on the performance improvement. Intuitively, the same rationale applies to the truncation of the importance weights, employed by PPO, that avoids performing too large steps in the policy space. Nevertheless, the step size in TRPO and the truncation range in PPO are just hyperparameters and have a limited statistical meaning. On the contrary, other actor-critic architectures have been proposed including also experience replay methods, like [60] in which the importance weights are truncated, but the method is able to account for the injected bias. The authors propose to keep a running mean of the best policies seen so far to avoid a hard constraint on the policy dissimilarity. Differently from these methods, POIS directly models the uncertainty due to the importance sampling procedure. The bound in Theorem 4.1 introduces the unique hyperparameter δ which has a precise statistical meaning as confidence level. The optimal value of δ (like the step size in TRPO and in PPO) is task-dependent and might vary during the learning procedure. Furthermore, POIS is an episode-based approach in which the importance weights account for the whole trajectory at once; this might prevent from assigning credit to valuable subtrajectories (like in the case of Inverted Pendulum, see Figure 1). A possible solution is to resort to per-decision importance sampling [35].

B Proofs and Derivations
Lemma 4.1. Let P and Q be two probability measures on the measurable space (X , F) such that P Q. Let x = (x 1 , x 2 , . . . , x N ) T i.i.d. random variables sampled from Q and f : X → R be a bounded function ( f ∞ < +∞). Then, for any N > 0, the variance of the IS estimator µ P/Q can be upper bounded as: Proof. From the fact that xi are i.i.d. we can write: Theorem 4.1. Let P and Q be two probability measures on the measurable space (X , F) such that P Q and d 2 (P Q) < +∞. Let x 1 , x 2 , . . . , x N be i.i.d. random variables sampled from Q, and f : X → R be a bounded function ( f ∞ < +∞). Then, for any 0 < δ ≤ 1 and N > 0 with probability at least 1 − δ it holds that: Proof. We start from Cantelli's inequality applied on the random variable µ P/Q = 1 By calling δ = 1 1+ λ 2 Var x∼Q [ µ P /Q ] and considering the complementary event, we get that with probability at least 1 − δ we have: By replacing the variance with the bound in Theorem 4.1 we get the result.

C Analysis of the IS estimator
In this Appendix, we analyze the behavior of the importance weights when the behavioral and target distributions are Gaussians. We start providing a closed-form expression for the Rényi divergence between multivariate Gaussian distributions [5]. Let P ∼ N (µ P , Σ P ) and Q ∼ N (µ Q , Σ Q ) and α ∈ [0, ∞]: (14) where Σ α = αΣ Q + (1 − α)Σ P under the assumption that Σ α is positive-definite.
From now on, we will focus on univariate Gaussian distributions and we provide a closed-form expression for the importance weights and their probability density function f w . We consider Q ∼ N (µ Q , σ 2 Q ) as behavioral distribution and P ∼ N (µ P , σ 2 P ) as target distribution. We assume that σ 2 Q , σ 2 P > 0 and we consider the two cases: unequal variances and equal variances. For brevity, we will indicate with w(x) the weight w P/Q (x).

C.1 Unequal variances
When σ 2 Q = σ 2 P , the expression of the importance weights is given by: is unbounded but it admits a minimum of value A. Let us investigate the probability density function. Proposition C.1. Let Q ∼ N (µ Q , σ 2 Q ) be the behavioral distribution and P ∼ N (µ P , σ 2 P ) be the target distribution, with σ 2 Q = σ 2 P . The probability density function of w(x) = p(x)/q(x) is given by: Proof. We look at w(x) as a function of random variable x ∼ Q. We introduce the following symbols: Let us start computing the c.d.f.: We distinguish the two cases according to the sign of τ and we observe that x = µQ + σQz where z ∼ N (0, 1): , thus we have: where Φ is the c.d.f. of a normal standard distribution. By taking the derivative w.r.t. y we get the p.d.f.: where φ is the p.d.f. of a normal standard distribution.
τ < 0: The derivation takes similar steps, all it takes is to call , then the c.d.f. becomes: and the p.d.f. is: To unify the two cases we set σ 2 = It is interesting to investigate the properties of the tail of the distribution when w is unbounded. Indeed, we discover that the distribution displays a fat-tail behavior.
Proof. Let us call z = y/A and let a > 0 be a constant, then it holds that for sufficiently large y we have: To get the result, we observe that for z > 1 we have exp √ log z ≥ 1. Now, by replacing z with y/A we just need to change the constant a into c > 0.
As a consequence, the α-th moment of w(x) does not exist for , this prevents from using Bernstein-like inequalities for bounding in probability the importance weights. The non-existence of finite moments is confirmed by the α-Rényi divergence. Indeed, the α-Rényi divergence is defined when σ 2

C.2 Equal variances
If σ 2 Q = σ 2 P = σ 2 , the importance weights have the following expression: for x ∼ Q. The weight w(x) is clearly unbounded and has 0 as infimum value. Let us investigate its probability density function.
Proof. We start computing the c.d.f.: First, we consider the case µP − µQ > 0 and observe that x = µQ + σz, where z ∼ N (0, 1): We call µ = µ P −µ Q 2σ and σ = σ µ P −µ Q and we have: We take the derivative in order to get the density function: For the case µP − µQ < 0 the derivation is symmetric and the p.d.f. differs only by a minus sign. We account for this fact by considering | σ| in the final formula.
In the case of equal variances, the tail behavior is different.
Proposition C.4. If σ 2 P = σ 2 Q then for any α > 0 there exist c > 0 and y 0 > 0 such that for any y ≥ y 0 , the p.d.f. can be upper bounded as f w (y) ≤ cy −α . Proof. Condensing all the constants in c, the p.d.f. can be written as: For any α > 0, let us solve the following inequality: Thus, for y ≥ exp 2 This is sufficient to ensure the existence of the moments of any order, indeed the corresponding Rényi divergence is: . By the way, the distribution of w(x) remains subexponential, as 2 ≥ e −ηy for sufficiently large y.

D Analysis of the SN Estimator
In this Appendix, we provide some results regarding bias and variance of the self-normalized importance sampling estimator. Let us start with the following result, derived from [7], that bounds the expected squared difference between non-self-normalized weight w(x) and self-normalized weight w(x). Lemma D.1. Let P and Q be two probability measures on the measurable space (X , F) such that P Q and d 2 (P Q) < +∞. Let x 1 , x 2 , . . . , x N i.i.d. random variables sampled from Q. Then, for N > 0 and for any i = 1, 2, . . . , N it holds that: Proof. The result derives from simple algebraic manipulations and from the fact that Varx∼Q w P/Q (x) = d2(P Q) − 1.
N Var A similar argument can be used to derive a bound on the bias of the SN estimator. Proposition D.1. Let P and Q be two probability measures on the measurable space (X , F) such that P Q and d 2 (P Q) < +∞. Let x 1 , x 2 , . . . , x N i.i.d. random variables sampled from Q and f : X → R be a bounded function ( f ∞ < ∞). Then, the bias of the SN estimator can be bounded as: Proof. Since it holds that | µ P/Q | ≤ f ∞ the bias cannot be larger than 2 f ∞. We now derive a bound for the bias that vanishes as N → ∞. We exploit the fact that the IS estimator is unbiased, i.e., Ex∼Q where (24) follows from (23) by applying Cauchy-Schwartz inequality and (25) is obtained by observing that Bounding the variance of the SN estimator is non-trivial since the the normalization term makes all the samples interdependent. Exploiting the boundedness of µ P/Q we can derive trivial bounds like: Var x∼Q µ P/Q ≤ f 2 ∞ . However, this bound does not shrink with the number of samples N . Several approximations of the variance have been proposed, like the following derived using the delta method [59,28]: We will not use the approximate expression for the variance, but we will directly bound the Mean Squared Error (MSE) of the SN estimator, which is the sum of the variance and the bias squared. Proposition D.2. Let P and Q be two probability measures on the measurable space (X , F) such that P Q and d 2 (P Q) < +∞. Let x 1 , x 2 , . . . , x N i.i.d. random variables sampled from Q and f : X → R be a bounded function ( f ∞ < +∞). Then, the MSE of the SN estimator can be bounded as: Proof. First, recall that µ P/Q is bounded by f ∞ thus its MSE cannot be larger than 4 f 2 ∞ . The idea of the proof is to sum and subtract the IS estimator µ P/Q : where line (29) follows from line (28) by applying the inequality (a + b) 2 ≤ 2(a 2 + b 2 ), (31) follows from (30) by observing that We can use this result to provide a high confidence bound for the SN estimator. Proposition D.3. Let P and Q be two probability measures on the measurable space (X , F) such that P Q and d 2 (P Q) < +∞. Let x 1 , x 2 , . . . , x N i.i.d. random variables sampled from Q and f : X → R be a bounded function ( f ∞ < +∞). Then, for any 0 < δ ≤ 1 and N > 0 with probability at least 1 − δ: Proof. The result is obtained by applying Cantelli's inequality and accounting for the bias. Consider the random variable µ P/Q = 1 Now we apply Cantelli's inequality: and considering the complementary event, we get that with probability at least 1 − δ we have: Then we bound the bias term Ex∼P [f (x)] − Ex∼P µ P/Q with equation (22) and the variance term with the MSE in equation (27). With some simple algebraic manipulation we have: where the last line follows from the fact that √ a + √ b ≤ 2 √ a + b for any a, b ≥ 0. Finally, recalling that the range of the SN estimator is 2 f ∞ we get the result.
It is worth noting that, apart for the constants, the bound has the same dependence on d 2 as in Theorem 4.1. Thus, by suitably redefining the hyperparameter λ we can optimize the same surrogate objective function for both IS and SN estimators.

E Implementation details
In this Appendix, we provide some aspects about our implementation of POIS.

E.1 Line Search
At each offline iteration k the parameter update is performed in the direction of G(θ j k ) −1 ∇ θ j k L(θ j k /θ j 0 ) with a step size α k determined in order to maximize the improvement. For brevity we will remove subscripts and dependence on θ j 0 from the involved quantities. The rationale behind our line search is the following. Suppose that our objective function L(θ), restricted to the gradient direction G −1 (θ)∇ θ L(θ), represents a concave parabola in the Riemann manifold having G(θ) as Riemann metric tensor. Suppose we know a point θ 0 , the Riemann gradient in that point G(θ 0 ) −1 ∇ θ L(θ 0 ) and another point: . For both points we know the value of the loss function: L 0 = L(θ 0 ) and L l = L(θ l ) and indicate with ∆L l = L l − L 0 the objective function improvement. Having this information we can compute the vertex of that parabola, which is its global maximum. Let us call l(α) = L θ 0 + αG −1 (θ 0 )∇ θ L(θ 0 ) − L(θ 0 ), being a parabola it can be expressed as l(α) = aα 2 + bα + c. Clearly, c = 0 by definition of l(α); a and b can be determined by enforcing the conditions: Therefore, the parabola has the form: Clearly, the parabola is concave only if ∆L l < ∇ θ L(θ 0 ) 2 G −1 (θ0) α l . The vertex is located at: To simplify the expression, like in [24] we define α l = l / ∇ θ L(θ 0 ) 2 G −1 (θ0) . Thus, we get: Of course, we need also to manage the case in which the parabola is convex, i.e., ∆L l ≥ ∇ θ L(θ 0 ) 2 G −1 (θ0) α l . Since our objective function is not really a parabola we reinterpret the two cases: i) ∆L l > ∇ θ L(θ 0 ) 2 G −1 (θ0) α l , the function is sublinear and in this case we use (38) to determine the new step size α l+1 = l+1 / ∇ θ L(θ 0 ) 2 G −1 (θ0) ; ii) ∆L l ≥ ∇ θ L(θ 0 ) 2 G −1 (θ0) α l , the function is superlinear, in this case we increase the step size multiplying by η > 1, i.e., α l+1 = ηα l . Finally the update rule becomes: The procedure is iterated until a maximum number of attempts is reached (say 30) or the objective function improvement is too small (say 1e-4). The pseudocode of the line search is reported in Algorithm 3.

Algorithm 3 Parabolic Line Search
otherwise end for

E.2 Estimation of the Rényi divergence
In A-POIS, the Rényi divergence needs to be computed between the behavioral p(·|θ) and target p(·|θ ) distributions on trajectories. This is likely impractical as it requires to integrate over the trajectory space. Moreover, for stochastic environments it cannot be computed unless we know the transition model P . The following result provides an exact, although loose, bound to this quantity in the case of finite-horizon tasks. Proposition E.1. Let p(·|θ) and p(·|θ ) be the behavioral and target trajectory probability density functions. Let H < ∞ be the task-horizon. Then, it holds that: Proof. We prove the proposition by induction on the horizon H. We define dα,H as the α-Rényi divergence at horizon H. For H = 1 we have: where the last but one passage follows from Holder's inequality. Suppose that the proposition holds for any H < H, let us prove the proposition for H.
where we applied Holder's inequality again and the last passage is obtained for the inductive hypothesis.
The proposed bound, however, is typically ultraconservative, thus we propose two alternative estimators of the α-Rényi divergence. The first estimator is obtained by simply rephrasing the definition (4) into a sample-based version: where x i ∼ Q. This estimator is clearly unbiased and applies to any pair of probability distributions. However, in A-POIS P and Q are distributions over trajectories, their densities are expressed as products, thus the α-Rényi divergence becomes: P (s τ,t+1 |s τ,t , a τ,t ) H−1 t=0 π θ (a τ,t |s τ,t ) π θ (a τ,t |s τ,t ) π θ (a τ,t |s τ,t ) α dτ.
Since both π θ and π θ are known we are able to compute exactly for each state d α (π θ (·|s) π θ (·|s)) with no need to sample the action a. Therefore, we suggest to estimate the Rényi divergence between two trajectory distributions as:

E.3 Computation of the Fisher Matrix
In A-POIS the Fisher Information Matrix needs to be estimated off-policy from samples. We can use, for this purpose, the IS estimator: ∇ θ log π θ (a τi,t |s τi,t ) T H−1 t=0 ∇ θ log π θ (a τi,t |s τi,t ) .
The SN estimator is obtained by replacing w θ /θ (τ i ) with w θ /θ (τ i ). Those estimators become very unreliable when θ is far from θ, making them difficult to use in practice. On the contrary, in P-POIS in presence of Gaussian hyperpolicies the FIM can be computed exactly [48]. If the hyperpolicy has diagonal covariance matrix, i.e., ν µ,σ = N (µ, diag(σ 2 )), the FIM is also diagonal: where I is a properly-sized identity matrix.

E.4 Practical surrogate objective functions
In practice, the Rényi divergence term d 2 in the surrogate objective functions presented so far, either exact in P-POIS or approximate in A-POIS, tends to be overly-conservative. To mitigate this problem, by observing that d 2 (P Q)/N = 1/ESS(P Q) from equation (6) we can replace the whole quantity with an estimator like ESS(P Q), as presented in equation (6). This leads to the following approximated surrogate objective functions: , .
Moreover, in all the experiments, we use the empirical maximum reward in place of the true R max .

E.5 Practical P-POIS for Deep Neural Policies (N-POIS)
As mentioned in Section 6.2, P-POIS applied to deep neural policies suffers from a curse of dimensionality due to the high number of (scalar) parameters (which are ∼ 10 3 for the network used in the experiments). The corresponding hyperpolicy is a multi-variate Gaussian (diagonal covariance) with a very high dimensionality. As a result, the Rényi divergence, used as a penalty, is extremely sensitive even to small perturbations, causing an overly-conservative behavior. First, we give up the exact Rényi computation and use the practical surrogate objective function L P−POIS λ proposed in Appendix E.4. This, however, is not enough. The importance weights, being the products of thousands of probability densities, can easily become zero, preventing any learning. Hence, we decide to group the policy parameters in smaller blocks, and independently learn the corresponding hyperparameters. In general, we can define a family of M orthogonal policy-parameter subspaces {Θ m ≤ Θ} M m=1 , where V ≤ W reads "V is a subspace of W ". For each Θ m , we consider a multivariate diagonal-covariance Gaussian with Θ m as support, obtaining a corresponding hyperparameter subspace P m ≤ P. Then, for each P m , we compute a separate surrogate objective (where we employ self-normalized importance weights): where ρ m , ρ m ∈ P m , θ m ∈ Θ m . Each objective is independently optimized via natural gradient ascent, where the step size is found via a line search as usual. It remains to define a meaningful grouping for the policy parameters, i.e., for the weights of the deep neural policy. We choose to group them by network unit, or neuron (counting output units but not input units). More precisely, let denote a network unit as a function: , where x is the vector of the inputs to the unit (including a 1 that multiplies the bias parameter) and g(·) is an activation function. To each unit U m we associate a block Θ m such that θ m ∈ Θ m . In more connectivist-friendly terms, we group connections by the neuron they go into. For the network we used in the experiments, this reduces the order of the multivariate Gaussian hyperpolicies from ∼ 10 3 to ∼ 10 2 . We call this practical variant of our algorithm Neuron-Based POIS (N-POIS). Although some design choices seem rather arbitrary, and independently optimizing hyperparameter blocks clearly neglects some potentially meaningful interactions, the practical results of N-POIS are promising, as reported in Section 6.2. Figure 4 is an ablation study showing the performance of P-POIS variants on Cartpole. Only using both the tricks discussed in this section, we are able to solve the task (this experiment is on 50 iterations only).

F Experiments Details
In this Appendix, we report the hyperparameter values used in the experimental evaluation and some additional plots and experiments. We adopted different criteria to decide the batch size: for linear policies at each iteration 100 episodes are collected regardless of their length, whereas for deep neural policies, in order to be fully comparable with [11], 50000 timesteps are collected at each iteration regardless of the resulting number of episodes (the last episode is cut so that the number of timesteps sums up exactly to 50000). Clearly, this difference is relevant only for episodic tasks.

F.1 Linear policies
In the following we report the hyperparameters shared by all tasks and algorithms for the experiments with linear policies: • Policy architecture: Normal distribution N (u M (s), e 2Ω ), where the mean u M (s) = Ms is a linear function in the state variables with no bias, and the variance is state-independent and parametrized as e 2Ω , with diagonal Ω.
• Number of runs: 20 (95% c.i.)  Table 3 reports the hyperparameters that have been tuned specifically for each task selecting the best combination based on the runs corresponding to the first 5 seeds. Table 3: Task-specific hyperparameters for the experiments with linear policy. δ is the significance level for POIS while δ is the step-size for TRPO and PPO. In bold, the best hyperparameters found.  Table 4 reports the hyperparameters that have been tuned specifically for each task selecting the best combination based on the runs corresponding to the 5 seeds.

F.3 Full experimental results
In this section, we report the complete set of results we obtained by testing the two versions of POIS.
In Figure 5 we report additional plots w.r.t. Figure 2 for A-POIS when changing the δ parameter in the Cartpole environment. It is worth noting that the value of δ has also an effect on the speed with which the variance of the policy approaches zero. Indeed, smaller policy variances induce a larger Rényi divergence and thus with a higher penalization (small δ) reducing the policy variance is discouraged. Moreover, we can see the values of the bound before and after the optimization. Clearly, the higher the value of δ, the higher the value of the bound after the optimization process, as the penalization term is weaker. It is interesting to notice that when δ = 1 the bound after the optimization reaches values that are impossible to reach for any policy and this is a consequence of the high uncertainty in the importance sampling estimator. We report the comparative table taken from [11] containing all the benchmarked algorithms and the two versions of POIS (Table 5). In the following ( Figure 6) we show the learning curves of POIS in its two versions for the experiments with deep neural policies.