Manuscript Offprint
arXiv:2611.02055Rare Event Constrained Reinforcement Learning with Large Deviations
ARTICLE INFO
Keywords:
Constrained Markov decision processes
reinforcement learning
rare events
large deviations
Lundberg coefficient
safe learning
ABSTRACT
We study finite-horizon reinforcement learning with a safety constraint on the probability of reaching a failure set. In contrast to the well-studied safe reinforcement learning literature, we consider problems where the probability of reaching the failure set is vanishingly small, but the consequences of reaching the failure set are catastrophic. Direct simulation and estimation of the optimal policy is naturally ineffective when the failure probability is extremely small. Moreover, on a real system the controller can only choose actions, and this is not enough to make failures frequent. In contrast to the rare event simulation literature, our goal is not to estimate the probability of the rare event occurrence, but to upper bound it such that the failure constraint is satisfied. Thus, instead of sampling failures, we use the large deviations principle. We define a damage variable that on exceeding a certain threshold indicates failure. We study the cumulant generating function (CGF) as its positive root provides an upper bound on the failure probability via Cramér's theorem. We extend this approach to Markov decision processes with hitting times through state-action CGFs, and give finite-horizon and state-dependent versions of the bound. The state-action CGFs do not depend on the policy and can be estimated from regular transitions, so the bound can be checked for any policy a priori. This gives a policy improvement algorithm in which every policy satisfies the failure constraint with high probability.
A classic example is Siegmund's algorithm [18]. To estimate the probability that a random walk with negative drift ever climbs a level , it samples the steps from the tilted law, times the original transition law, where is the positive root of the cumulant generating function (CGF) (Lundberg's coefficient). Under the tilted law, the walk drifts up and always reaches , and the likelihood ratio is at most , so the number of samples needed does not grow with . All these methods [2, 17, 1, 16, 20] need a simulator in which the transition law can be changed, and they consider a fixed chain, while in reinforcement learning the policy itself changes how rare the failure is. On a real system the
controller can only choose actions, and this is not enough to make failures frequent in a useful way.
In contrast to the rare event simulation literature, our goal is not to estimate the probability of the rare event occurrence, but to upper bound it, as this is enough to satisfy the failure constraint. This is the idea behind our approach. We use Lundberg's inequality to bound the failure probability to be at most [8, 3]. This bound needs only the CGF in steps, and can be estimated from normal operation. So instead of sampling from the tilted law, we estimate the Lundberg coefficient from data and use it to bound the constraint. This does not mean that failures play no role. We still need to know what a failure is, the damage potential, and the failure level (Assumption 1). What we do not need is to observe the failure event on the system we control. During normal operation the damage moves up and down, and from these steps we bound the probability of damage reaching the failure set. Without observed failures the failure probability cannot be estimated, but it can still be bounded from above. We extend this to Markov decision processes, where the transition law depends on the state action pair, through state-action CGFs and state-dependent Lundberg coefficients. The resulting bound is an exponential supermartingale, or a stochastic barrier certificate [15, 19]. Such certificates have been learned together with controllers [13, 22], usually with known dynamics and for regular probability values. Here the certificate comes from large deviations principle and it is estimated from data, unlike risk-sensitive control where the CGF is optimized as an exponential cost [21, 7].
Contributions.
(C1) A safety certificate for MDPs with hitting times developed via state-action CGFs and state-dependent Lundberg coefficients (Theorem 2, Corollaries 1 and 2).
(C2) We estimate of the safety certificate from trajectories (Lemma 2).
*Corresponding author rmi@es.aau.dk (R. Misra) ORCID(s):
R. Misra: Preprint submitted to Elsevier
Page 1 of 8
(C3) A simple learning algorithm that checks each new policy before it is run, so that every policy run during learning satisfies the constraint with high probability (Algorithm 1, Proposition 1).
2. Preliminaries
Consider a finite-horizon Markov decision process defined on a finite state space , with finite control action space , having cost function , and transition kernel . The control policy is a distribution over the control action set , parametrized by parameter vector . We define a failure set and a goal set . Both sets are absorbing and disjoint, on , and we write for the remaining states. For finite time , the hitting time for is
and the failure probability is . Consider the following optimization, for a given ,
Setting. The kernel is unknown. The controller runs a policy on the system and observes the states, actions and costs. It cannot start the system from a state of its choice and it cannot change the randomness of . The constraint in (1) needs to be satisfied by all control policies at all times. Crude Monte Carlo requires trajectories merely to observe failures and trajectories for estimating up to relative error [4]. Failure is usually the end of an accumulation, such as wear, energy or the distance to a limit. We describe this as the following damage potential .
Assumption 1. There exist and with , and the increments satisfy for a known constant .
We define as the distance to failure. The constant is the maximum possible damage in one step. This is usually a physical limit, such as the maximum wear or energy change per time step. Assumption 1 is required for the following reasons. Firstly, it makes the CGFs of Section 3 finite, so that the Lundberg coefficient exists (light tails). Secondly, it gives the known range of that is needed to learn the CGF from data in Lemma 2.
We shall now define the failure h-function. For a fixed policy , we define the finite-horizon failure h-function,
The -function gives the probability of eventual failure before the specified horizon, from the current state and time. For any running time , where ,
At the terminal time T, for a nonfailure state ,
For and , the -function satisfies the following backward recursion,
(4)
where is the kernel and is the state-action h-function
Thus, is harmonic (or satisfies the recursion (4)), and the failure probability appearing in the constraint is . For a fixed , the optimal zero-variance change of measure for estimating is the kernel,
As is conditioned on the failure event happening, every trajectory hits . Note that the controller can only choose and cannot obtain as it depends on the underlying environment. The kernel (5) can be split into a part the controller can control and a part it cannot control. For , define the tilted policy
which is a distribution by (4). Multiplying it by and summing over gives (5). So the Doob transform first tilts the action and then tilts the environment. In practice, the controller can sample its actions from , but it cannot tilt the environment.
Example 1 (Damage chain). We use the following example throughout the paper to illustrate the theory. To illustrate the policy dependence of the failure -function, consider with . The state represents accumulated damage for an expensive machine such as a wind turbine. The target set is , corresponding to safe termination, and the failure set is , corresponding to catastrophic failure. Both are absorbing. At each interior state the controller selects an action from , where denotes a safe operating mode and a less costly but riskier mode, with . The policy is
The expected one-step cost is . The induced probability of transition towards failure is
R. Misra: Preprint submitted to Elsevier
Page 2 of 8
Therefore, for an interior state,
From (2), (3), (4), the h-function satisfies the conditions,
and for , ,
This MDP satisfies Assumption 1 with , and , and the distance to failure is . Increasing lowers the cost per step but makes episodes longer. The risky mode is optimal only if . We take , , , , , and , which satisfies this condition. Then grows from at to at , and falls from 3.333 to 2.457. With the exact optimum is with . Crude Monte Carlo needs about episodes to estimate to 10% near . Both modes move the damage up with positive probability, so every action can lead to failure, and sampling the actions from does not reduce the variance.
3. Large Deviations Principle
This section summarizes useful large deviation concepts. We first state them for independent steps and then define their state-dependent versions for the MDP. Let be i.i.d., , and let the cumulant generating function (CGF) be
For simplicity we assume for all , which holds under Assumption 1. is convex, and . Its Legendre transform,
is the rate function. It is convex, nonnegative, and zero only at . The next theorem quantifies the probability of observing large deviations from the expected value.
Theorem 1 (Cramér [14, Thm. 3.12], [8, Thm. 2.2.3]). For ,
The proof of Theorem 1 is in [14, Sec. 3.4] and [8, Sec. 2.2]. The idea is a change of measure that makes the rare event likely [4, Sec. VI.2]. Let be the law of and, for , define the exponentially tilted law . It is a probability law because , and its mean is . Since is convex, is increasing, so a larger puts more weight on large steps. Choose with . Under the mean step is , so is no longer rare and by the central limit theorem its probability tends to . The price of the change is the likelihood ratio of a path,
which equals on paths with , since the supremum in (6) is attained at . So is about times a probability that is not small. In other words, the rare event happens in the least unlikely way, as all steps behave as if their mean were , and is the cost (or energy required) per step of this change. It is also the relative entropy of with respect to . In our problem setting, we are interested in the damage which might increase by at some time , instead of the average damage. Therefore, we need to modify the rare event to , and this is done via Lundberg's coefficient. Assume and . Then has a second root ,
called the Lundberg coefficient [3], also known as the Cramér root or the adjustment coefficient [4, Sec. VI.2a]. Since , the process is a martingale, and stopping it when gives Lundberg's inequality
The next lemma connects the Lundberg coefficient to the rate function in (6).
Lemma 1. , and the minimum is attained at .
Proof. By (6) with , for all . At the supremum in (6) is attained at , so .
Lemma 1 explains (8) with Cramér's theorem. A path that increases damage to at speed needs steps and has probability about . The cheapest speed is , and its cost is . The tilted transition law, times the original law, has mean . This is the idea behind Siegmund's algorithm [18].
Example 1 (continued). Under the damage moves by with up-probability , so and . Tilting a step by results in up-probability and mean and this is the harmonic Doob -transform with (7).
We now drop the i.i.d assumption and consider controlled Markov chains or MDP's. Now the CGF depends on the state and the action. For , and we define the state-action CGF and the policy CGF
R. Misra: Preprint submitted to Elsevier
Page 3 of 8

Figure 1: Left: CGF of one step of Example 1 with and its positive root, the Lundberg coefficient . Right: the rate function and the line , which touches it at the cheapest speed (Lemma 1).
is the CGF of the next under and is convex in . The state-dependent Lundberg coefficient is
It is positive when the damage drifts down at , and zero when it drifts up. By convexity, for all . The central idea is to replace the single CGF in i.i.d case with a state dependent CGF that is only conditioned on the current state due to the Markov property.
4. The safety certificate
The next theorem specifies the conditions for constructing a safety certificate that bounds .
Theorem 2. Let , , and satisfy
where (10) is required for and . Then
Equality holds for and , with (10) multiplied by .
Proof. Let be the history up to time and consider the process stopped at failure,
where is the minimum between and . It is nonnegative and . We first show that for . If , the process is stopped and . If , then and , also when , since then . Given , the action is drawn from and the next state from , so by (10),
If , then because is absorbing, and by the second condition in (11). Since implies , these three cases cover all paths, so is a supermartingale. Taking expectations and repeating over gives . On the failure event we have by the first condition in (11). Hence
which is the claim. No limit in is taken, so the bound holds for every finite horizon. For and , (2) gives on and on , so (11) holds. Multiplied by , (10) is the recursion (4), which holds with equality. The bound is then .
Condition (10) says that , or is a supermartingale, and we can upper bound the failure probability. Now, for constructing a certificate, we have to choose in terms of damage (Assumption 1), and here choosing satisfies (9), and substituting it in condition (10) results in
For an MDP, the increments depends on the state and there may not be a single satisfying (12). The following two corollaries address this.
Corollary 1. Let . Under Assumption 1,
In particular, if for some , then for every .
R. Misra: Preprint submitted to Elsevier
Page 4 of 8
Proof. Fix , write , let , and
We now check the conditions of Theorem 2. On we have , so . For every , , thus satisfying (11). For and , with , so by the definition (9) the left side of (10) is
As , Theorem 2 gives . This holds for every , which gives (13). If for , , then , and the bound becomes , which no longer depends on .
Thus, if there exists a positive , we can obtain a time-independent bound. Otherwise, a larger produces a lower bound for small . When does not depend on and lies below , the damage is a random walk until absorption, and (13) is tight. If and grow with fixed, and have the same limit. This is the finite-time ruin asymptotics of [3, Ch. V], and Section 7 checks it numerically. The maximum over states makes (13) conservative when the dynamics change with the damage. Splitting the states into cells with common state-dependent Lundberg coefficients removes most of the conservatism. Another reason for introducing cells is that it allows us to group states based on damage , and in normal operation the failure states might not be visited often, so we can combine safe states with similar CGF in a cell. The splitting of states into cells will be based on a decay rate , and this is stated in the following corollary.
Corollary 2. Let be nonincreasing with for all . Then for every ,
Proof. Let , and take for all and . On , and give , and the condition on holds with equality since does not depend on . Let and . Since is nonincreasing, for and for , so for every ,
With it gives , , so the left side of (10) is at most . Since , and (10) holds. Theorem 2 gives , which is (14).
By (14), each unit of distance from the failure level at damage lowers the bound by about the factor . In practice, we use cells. Let and define cell . Let on , on , with , and for all . Then (14) is,
where is the length of . A cell where nothing is known can be given , because for any dynamics. The bound then loses the part that this cell would add, but it stays valid. Since the decay rates may not increase, all cells above it also get .
Example 1 (continued). Here does not depend on , and the policy CGF is for every . So the maximum over in Corollary 1 is not conservative. Table 1 compares the bound (13) with the exact failure probability.
5. Estimating the certificate from data
The certificate needs only the state-action CGFs, and these do not depend on the policy. So transitions observed under any policy can be used to check any other policy. We split into cells and assume the following.
Assumption 2. For each cell and action , the distribution of next increment given , is the same for all and all .
Assumption 2 allows us to define as the common state-action CGF on or the cell CGF.
Example 1 (continued). The up-probability of each mode does not depend on the state, so one cell satisfies Assumption 2. Every step taken with mode is then a sample of , whichever policy chose the mode.
A cell can be a single state, and then Assumption 2 is the Markov property. Under Assumption 2 and the Markov property, the increments seen right after successive uses of action in cell (not the increments along the path) are i.i.d., for any policy that chose these actions (due to Doob's optional skipping theorem [9]). Let be the sample mean , and fix a grid with points.
Lemma 2. Under Assumptions 1 and 2, with probability at least , for all and at once,
(16)
Proof. Fix and , and let be the increment observed the -th time that action is used in cell . Given everything
R. Misra: Preprint submitted to Elsevier
Page 5 of 8
Algorithm 1 Certified policy improvement
1: Input: safe initial policy , , , step , episodes
2: for do
3: Run for episodes; add the observed increments to the data
4: Estimate from the same episodes
5:
6: while do 7: 8: end while
9: if , else
10: end for
observed before that time, has the law of Assumption 2, by the Markov property. So is independent of and has the same law, whatever policy chose the actions, also when the policy was chosen from earlier data. Hence are i.i.d. with , and is the mean of the first values of . By Assumption 1, , an interval of length . Hoeffding's inequality [12, Thm. 2], applied to , gives, for each and ,
We take . A union bound over the choices of and over bounds the probability that (16) fails anywhere by .
Write for the logarithm of the right side of (16), with if action was never used in . Since (9) increases with each , using in place of gives a policy CGF that is an upper bound of . We define the data certificate as (13) with and the minimum over , or as (15) with the decay rates . On the event of Lemma 2, for all at the same time, whatever data were used. It is important to note the following limitations. A policy that uses an action never tried in some cell cannot be certified. A cell that was never visited gets decay rate zero, so the certificate becomes larger but not optimistic. Because (16) holds for all , data can be added while the policy changes. However, an increment larger than that was never seen would invalidate the bound (Assumption 1). Thus, prior knowledge of is needed by any estimate of a probability that lies far below what the data show.
6. Certified Policy Improvement
The certificate can be computed for any from the data, before running , and can be used for learning without running unsafe policies, if the initial policy is safe.
Assumption 3. The initial policy satisfies and uses every action in every state with positive probability.

Figure 2: Bound on for every policy in Example 1 (), from one data set of steps of the policy and with the exact CGFs, together with the exact failure probability. The largest certified policy is where the bound crosses .
The second part ensures that every action is tried, so that its state-action CGF can be estimated.
Example 1 (continued). The policy uses both modes in every state and has , so it satisfies Assumption 3.
Proposition 1. Under Assumptions 1–3, with probability at least , every policy run by Algorithm 1 satisfies .
Proof. Let be the event of Lemma 2, so that . On , (16) holds for every sample size, so whatever data the algorithm has collected, for every cell, action and . Then , and Corollary 1 or 2 gives for every at once. We show by induction on that on . For this is Assumption 3. The next policy is either , which satisfies the constraint by the induction hypothesis, or a with , computed from the data collected up to round , before is run. On the second case gives . The event is the same for all rounds, so no union bound over the rounds is needed, although the data and the tested policies depend on the earlier rounds.
The cost is not a rare quantity, so its gradient can be estimated in the usual way from the episodes. In Example 1 we use the score-function estimator with the cost-to-go of each step and its mean as baseline. Algorithm 1 needs no multiplier and no gradient of the certificate. The iterates stay in the certified set, which grows as data are added.
Remark 1 (Gradient of the certificate). If a gradient of the certificate is needed, for example for a barrier method, it follows from (9),
R. Misra: Preprint submitted to Elsevier
Page 6 of 8

Figure 3: Learning on Example 1. Left: expected cost of the policy run in round k. Right: true failure probability of the policy run in round k (computed from the true model, for checking only). Algorithm 1 (blue) moves only when the data allows it and stays below . The primal-dual method (orange, ) moves first and corrects later.
Table 1 Exact failure probability and certificate (13), N = 20, .
| T | ||||
|---|---|---|---|---|
| 0 | 30 | 1.66 | ||
| 0 | 100 | 1.09 | ||
| 0.75 | 30 | 3.21 | ||
| 0.75 | 100 | 1.48 | ||
| 1 | 30 | 3.46 | ||
| 1 | 100 | 2.21 |
with the tilted policy . It is a one-step expectation and needs no failures.
Remark 2 (Why the constraint is for ). The certificate bounds only the failure probability from , as such constraints do not satisfy Bellman's principle. In the example of [11], the risk taken on a branch that is not followed limits what is allowed on the other branch, so the best action at an intermediate state depends on where the system started. At finite horizon this happens in general, because the failure probability always depends on the initial state. Algorithm 1 therefore checks whole policies from and never checks single decisions from intermediate states with the same .
7. Numerical Results
We return to Example 1. All numbers below are produced by the accompanying notebook, available at https://github.com/rahul-misra/Rare-Event-Constrained-Safe-Reinforcement-Learning-with-Large-Deviations-Principle. The true model is used only to check the results.
Validity and tightness. The certificate (13) upper-bounds for all 25 combinations of and , with ratios from 1.09 to 3.46 (Table 1). For with and , equals 0.3993, 0.3659 and 0.3649 at and 400, while for every .
Certificate from data. Table 2 shows the certificate with CGFs estimated by Lemma 2 ( , a grid of 601 points
Table 2 Certificate from steps of the policy over 200 data sets: share of data sets in which some policy is certified, median certified ( if none), and median cost above the optimum .
| n | certified | median | cost above optimum |
|---|---|---|---|
| 42% | 0 | 14.4% | |
| 100% | 0.466 | 7.9% | |
| 100% | 0.638 | 3.8% | |
| exact CGF | - | 0.727 | 0.9% |
on [0,3]) from steps of the policy , over 200 independent data sets. No failure was observed in any data set. If no policy is certified, we keep . The certified policy grows with towards the policy allowed by the exact CGFs, and the policy that was kept satisfied the constraint in every data set. Fig. 2 shows that the bound from one data set stays above for all .
Learning. We run Algorithm 1 for 60 rounds of episodes with , starting from , for which . For comparison we run a primal-dual method on the same certificate and the same gradient estimate, with multiplier step (Fig. 3). Algorithm 1 ends 3.7% above the exact optimum, and every policy it ran was checked before it was run. The primal-dual method ran 20 and 11 policies without a valid certificate at the time, and in both cases two of them had a true failure probability above , up to .
State-dependent damage. We change Example 1 so that the damage accelerates near failure: for and for , so that without a horizon. With cells and and the exact state-dependent Lundberg coefficients, Corollary 2 gives , 3.7 times the true value, while Corollary 1 gives . In episodes of normal operation the damage never went above 10, so cell has no data and gets . The certificate from data is , and it remains valid even if the up-probability in cell is 0.99.
R. Misra: Preprint submitted to Elsevier
Page 7 of 8
A transition model fitted to the same data, with the unseen states given the average up-probability, predicts , which is overly optimistic (hence unsafe) compared to the ground truth.
8. Conclusion
In contrast to the rare event simulation literature, the goal of this paper was not to estimate the probability of the rare event occurrence, but to upper bound it with a suitable constraint. In practice, the controller cannot make failures frequent in a useful way, but it can learn the state-action cumulant generating functions of the damage from regular transitions. Through the Lundberg coefficient and its state-dependent versions, these give an upper bound on the failure probability that holds at every horizon via the large deviation principle, and can be checked for any policy before it is run. This leads to a simple learning algorithm that runs only certified policies. The method needs bounded (light-tailed) increments. For heavy-tailed distributions, the CGF does not exist, and other tools are needed [6]. Choosing the cells and the damage potential from data, and the behavior of the cost of certification as , are future work. Theorem 2 holds for any W that satisfies (10), so a parametrized W, for example a neural network as in [13], could replace the certificates of Corollaries 1 and 2. This would be needed with function approximation, and is also future work.
References
[1] Aguilar, J., Gatto, R., 2024. Unified perspective on exponential tilt and bridge algorithms for rare trajectories of discrete Markov processes. Physical Review E 109, 034113.
[2] Ahamed, T.P.I., Borkar, V.S., Juneja, S., 2006. Adaptive importance sampling technique for Markov chains using stochastic approximation. Operations Research 54, 489–504.
[3] Asmussen, S., Albrecher, H., 2010. Ruin Probabilities. Second ed., World Scientific, Singapore.
[4] Asmussen, S., Glynn, P.W., 2007. Stochastic Simulation: Algorithms and Analysis. Springer.
[5] Biondini, G., 2015. An introduction to rare event simulation and importance sampling, in: Handbook of Statistics. Elsevier, volume 33, pp. 29–68. doi:10.1016/B978-0-444-63492-4.00002-2.
[6] Blanchet, J., Jorritsma, J., Zwart, B., 2025. Optimization under rare events: scaling laws for linear chance-constrained programs. arXiv:2407.11825v2.
[7] Borkar, V.S., 2002. Q-learning for risk-sensitive control. Mathematics of Operations Research 27, 294–311.
[8] Dembo, A., Zeitouni, O., 1998. Large Deviations Techniques and Applications. 2 ed., Springer.
[9] Doob, J.L., 1936. Note on probability. Annals of Mathematics 37, 363–367.
[10] Doob, J.L., 1957. Conditional Brownian motion and the boundary limits of harmonic functions. Bulletin de la Société Mathématique de France 85, 431–458.
[11] Haviv, M., 1996. On constrained markov decision processes. Operations research letters 19, 25–28.
[12] Hoeffding, W., 1963. Probability inequalities for sums of bounded random variables. Journal of the American Statistical Association 58, 13–30.
[13] Mathiesen, F.B., Calvert, S.C., Laurenti, L., 2023. Safety certification for stochastic systems via neural barrier functions. IEEE Control Systems Letters 7, 973–978. doi:10.1109/LCSYS.2022.3229865.
[14] Nair, J., Wierman, A., Zwart, B., 2022. The Fundamentals of Heavy Tails: Properties, Emergence, and Estimation. volume 53 of Cambridge Series in Statistical and Probabilistic Mathematics. Cambridge University Press. doi:10.1017/9781009062961.
[15] Prajna, S., Jadbabaie, A., Pappas, G.J., 2007. A framework for worst-case and stochastic safety verification using barrier certificates. IEEE Transactions on Automatic Control 52, 1415–1428.
[16] Rose, D.C., Mair, J.F., Garrahan, J.P., 2021. A reinforcement learning approach to rare trajectory sampling. New Journal of Physics 23, 013013.
[17] Rubinstein, R.Y., Kroese, D.P., 2004. The Cross-Entropy Method. Springer.
[18] Siegmund, D., 1976. Importance sampling in the Monte Carlo study of sequential tests. The Annals of Statistics 4, 673–684.
[19] Steinhardt, J., Tedrake, R., 2012. Finite-time regional verification of stochastic non-linear systems. The International Journal of Robotics Research 31, 901–923.
[20] Werner, P., Hartmann, A.K., 2026. Numerical estimation of limiting large-deviation rate functions. Physical Review E 113, 034117.
[21] Whittle, P., 1990. Risk-Sensitive Optimal Control. Wiley, Chichester.
[22] Žikelić, Đ., Lechner, M., Henzinger, T.A., Chatterjee, K., 2023. Learning control policies for stochastic systems with reach-avoid guarantees, in: Proceedings of the AAAI Conference on Artificial Intelligence, pp. 11926–11935. doi:10.1609/aaai.v37i10.26407.
R. Misra: Preprint submitted to Elsevier
Page 8 of 8