{'fraction_non_alphanumeric': 0.02708009187226791, 'fraction_numerical': 0.00759428021041713, 'mean_word_length': 4.705981822024942, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Disturbing Reinforcement Learning Agents with Corrupted Rewards

Reinforcement Learning (RL) algorithms have led to recent successes in solving complex games, such as Atari or Starcraft, and to a huge impact in real-world applications, such as cybersecurity or autonomous driving. In the side of the drawbacks, recent works have shown how the performance of RL algorithms decreases under the influence of soft changes in the reward function. However, little work has been done about how sensitive these disturbances are depending on the aggressiveness of the attack and the learning exploration strategy. In this paper, we propose to fill this gap in the literature analyzing the effects of different attack strategies based on reward perturbations, and studying the effect in the learner depending on its exploration strategy. In order to explain all the behaviors, we choose a sub-class of MDPs: episodic, stochastic goal-only-rewards MDPs, and in particular, an intelligible grid domain as a benchmark. In this domain, we demonstrate that smoothly crafting adversarial rewards are able to mislead the learner, and that using low exploration probability values, the policy learned is more robust to corrupt rewards. Finally, in the proposed learning scenario, a counterintuitive result arises: attacking at each learning episode is the lowest cost attack strategy.


Introduction
Reinforcement Learning (RL) is a type of machine learning whose main goal is finding an action policy that makes the agent act optimally in an environment, generally formulated as a Markov Decision Process (MDP). Recently, RL has been successfully used in complex computer games (e.g., Atari [11], or Starcraft [19]), but also in real-world applications where robustness is a key factor (e.g., robotic tasks [8], cyber security [4] or autonomous driving [7]). However, the robustness of RL algorithms is in doubt due to recent works showing that they are vulnerable to adversarial attacks. In Adversarial RL [2], the most usual of these attacks tries to slightly change the observation (i.e., the state) that the agent perceives from the environment [1], similarly to adversarial examples for classifiers [18]. Such attacks can be carried out during the training [6] or the test phase [5], and the objective is to disturb as little as possible the original state so as not to be detected, while achieving a system failure, i.e., to make the agent believe that it is in a situation when it is really in another one.
Besides the state perception, another sensitive target to attack is the reward function. In real-world applications, we can obtain rewards that differ from the original due to several factors such as incorrect measurements from sensors, noise in the transmission channel, but also due to attacks that intentionally perturb the reward signal. However, this attack source has received very little attention [16,20], and as far as we know, there are no studies about how sensitive the learning process is depending on the aggressiveness of the reward perturbations and the exploration strategy. In spite of that, we consider that such an analysis is essential for everyone who works in the emerging area of Adversarial RL both designing attacks and defense mechanisms.
In this paper, we contribute to fill this gap in the literature. In particular, we address a sub-class of MDPs: episodic, stochastic goal-only-rewards MDPs [15]. For goal-only-reward MDPs, a reward is only given if a goal state is reached. Although this is a strict restriction, many decision tasks are modeled with goal-only-rewards from classical control problems such as the Mountain Car or the Cart Pole, to more complex problems such as real robot manipulation tasks [12]. However, we focus on an intelligible 20×20 grid domain with goal states and obstacles. Focusing on an on-policy RL algorithm, SARSA, and two well-known exploration strategies ( -greedy and softmax), this paper address a primary question: how the disturbances in the reward function when a goal state is reached affect the convergence of a learning agent depending on the exploration strategy selected? Therefore, our contribution is twofold: first, a threat model for the reward function in goal-only-rewards MDPs; second, a comprehensive study in order to analyze the robustness of the learning process depending on the probability of reward perturbations and the exploration strategy. Results show that small exploration probabilities are more resilient to adversary presence, and that attacking at each learning episode is the lowest cost attack strategy.

Background
In the literature, we identify three different attack targets where one can inject Adversarial Examples in any RL algorithm. Figure 1 shows these attack targets where each adversary represents a different kind of attack. These possible attack points are the state perceived, the action selected or the reward function: Figure 1. RL proccess during training phase. Each adversary represents a target where the RL training process can be perturbed.
1. State perception. Most works focus on attacking the state perception in training [6,13] or testing [5,14]. All these works have the common objective of delaying, perturbing or falsifying under malicious attacks the state s perceived by the learning agent. 2. Action selected. There are also actuator attacks where the objective is to drive the learner agent to undesired states by perturbing at each time step the action a executed by the learning agent [17]. 3. Training reward. Finally, there are reward attacks. These attacks refer to the perturbation of the reward produced by the environment in response to the actions applied by a RL agent [3].
This paper is included in the last category. However, very few works have explicitly studied the modification of the reward function in order to mislead the agent. In one of the first works [3], the authors propose to modify a set of states where the perceived reward is different from the real. Then, if the agent reaches these states the enemy performs an attack. Unlike our approach, we establish an attack probability just when the agent achieves a goal state, which significantly reduces the number of attacks. Another possibility is to generate surrogate rewards [20] from previous noisy rewards to train its agent avoiding the interference of the corruption. Because of this, the learning agent is unable to find the right policy, but also requires a large number of attacks. Instead, modifying the reward with a certain probability following some probability distribution [16] reduces the attack cost. But in the case where the agent learns without enemy presence, the agent receives wrong reward estimators. Therefore, its performance decreases in a free adversary scenario. Another novel approach also modifies rewards driving the learner to the desired goal [10]. However, unlike our approach, they need more knowledge about the problem, the whole training dataset, and the actions the learner can perform. Recently, a framework to perform offline and online attacks on the Stochastic multiarmed bandit problem has been published [9]. The adversary produces a linear regret on the bandit algorithm with only a logarithmic cost applying their adaptive attack strategy. As in this approach, our work investigates how to reduce the attacking cost. Therefore, compared to the works mentioned above, our work has a completely different objective: we develop a comprehensive study to characterize how the perturbation probabilities and exploration strategies impact on the convergence of the learning agent in order to find the best configuration from the point of view of the learner but also the adversary. As far as we know, such study has never been carried out before.

Problem Formulation
We define this task as a stochastic goal-only-rewards MDP that is represented by the tuple: (S , A, G, P, r, γ, s0), where S and A are state spaces of states s and actions a respectively, and G ⊂ S is the set of goal states. In the simplest case, goalonly rewards are given for states s ∈ G, and zero-reward is given elsewhere. P : S × A × S → R is the unknown transition probability, r : S × A → R is the reward function, also unknown. γ is the discount factor and s0 is the initial state. In our study, we use an on-policy RL algorithm, SARSA. This on-policy algorithm learns the Q-value based in the next action performed by the current policy instead of taking the best action as the Q-learning algorithm. We update the Q table values with the following function: where st ∈ S represents the current state, at ∈ A is the current action performed, rt is the reward received in this time-step, st+1 ∈ S is the next state and at+1 ∈ A is the action performed in the next state. α is the learning rate.

Exploration Strategies and Learner Objective
In this paper, we study two exploration/exploitation strategies: -greedy and softmax. -greedy chooses the best action with a probability 1− , and a random action with probability , as shown in Equation 2.
A ← argmax a Q(s, a) with probability 1 − a random action with probability (2) Instead, softmax assigns a probability of choosing each action as described in Equation 3.
In Equation 3, τ is the temperature parameter. If the value of this parameter is close to 0, the agent will behave totally greedy. On the contrary, if this value is greater, all the actions will be equally probable of performing it.
The goal is to maximize the expected discounted reward per episode as described in Equation 4: where γ is the discount factor, and N is the maximum number of steps allowed in an episode. It is important to note that this discounted reward per episode will be zero if a goal state is not reached.

Threat Model
We assume that the adversary does not have information about the learner (black-box attack). The adversary can only create bounded perturbations to the true reward signal when the learner reaches a goal state, i.e., ∀s ∈ G, r = 0. In this case, the action of the adversary is limited to changing the sign of the true reward as shown in Equation 5: where r is the true reward perceived from the environment, andr is the corrupt reward. Algorithm 1 describes how the adversary operates during the learning process. The adversary receives as input parameter an attack probability, p. Then, it is continuously sniffing the reward channel between the environment and the learning agent as described in Figure 1 (line 2 of Algorithm 1). If the perceived reward corresponds to a goal state, i.e., r = 0 (line 3), then the adversary generates a random number ϕ ∈ [0, 1] (line 5). If ϕ is less or equal to p, the adversary injects a corrupt reward in the reward channel (lines 6-7). Therefore, at each time t the learning agent reaches a goal state, instead of observing r directly, the agent only observes with probability p a falsified rewardr, ignoring the presence of the adversary.

Algorithm 1 Enemy Injection Algorithm
if ϕ ≤ p then 6:r ← −r 7: inject(r) 8: until stop criterion becomes true 9: return In the experiments, we will evaluate the performance of the adversary according to two criteria. First, the performance of the learning agent according to Equation 4, and then, we count the number of attacks performed. Therefore, the worse the learning agent performance and the lower the number of attacks, the better adversary behavior.

Evaluation
The experiments aim to study the behavior of a learning agent and an adversary in a goal-only reward MDP. The following sections describe the evaluation environment, the evaluation settings, and the results achieved. Figure 2 shows an example random 20x20 grid used to perform the experiments. We run a random scenario generator to create different learning episodes. The green cell denotes the initial state where the learning agent is starting, the red cells denote the goals it has to reach, and the brown cells denote obstacles. The agent has the actions A = {↑, ↓, ←, →}. An action a ∈ A takes the agent in the denoted direction if possible. With a probability of 0.1, the agent is not transported to the desired direction but to one of the three remaining directions. In total, we generate 50 different grids placing the goal states at a similar distance from the starting point. We put these goals between 20 and 25 steps from the initial state. The results show the average of all the scenarios. The learning agent starts in the initial position and it can move until one of the goal states or until a maximum number number of steps per episode is reached. We establish this maximum number of steps to 500, a enough number of steps to allow the agent to explore and to reach one goal considering the size of the grid. We establish a different reward for each goal r = {0.25, 0.5 or 1}, and r = 0 otherwise.

Evaluation Settings
We have performed two sets of experiments. In our first experiments, both exploration strategies fix the probability of exploring and exploiting. For the second set of experiments, we dynamically adjust the exploration probability of -greedy instead of fixing it. In particular, our set of experiments are based on: 1. Using Fixed Exploration Probabilities. In this first set, for each -greedy experiment, we choose values in the range = [0.0, 1.0], in steps of 0.1. In respect to softmax, we select the same range values for τ as but ignoring the 0.0 value because it causes a mathematical error. Instead of this value, we choose a value close to zero in order to replicate greedy behavior. In case of tie, we randomly select an action between all the tie actions. Additionally, in this first set of experiments, we consider a learning scenario where the adversary lets the agent learn a policy without perturbing any corrupted rewards and then it starts to craft attacks. In this case, the adversary starts to inject attacks from episode 1.000 to ensure that the learner has learned a policy at this episode. 2. Using Dynamic Exploration Probabilities. In this set of experiments, we dynamically adjust the exploration probability, , of -greedy instead of fixing it. The training starts with total exploration and ends with total exploitation. We use Equation 6 to update the exploration probability at each episode of the learning process. This value decreases as a linear function.
where we obtain the dynamic exploration rate dividing the number of the current episode, et, by the number of total episodes of the training phase, L. In the experiments, we set L to 5.000 episodes.
The adversary's goal is to produce the maximum deterioration in the learner policy performing the minimum number of attacks, so in the next section we study the results according to two criteria: the performance of the learning agent according to the Equation 4, and the number of attacks injected. Finally, for all experiments α is fixed to 0.125 and γ to 0.95, which are classical values in these kind of environments, so the results would be generalizeble to other settings.

Results
Results in this section show the average of ten runs for each configuration and also, we use a slide window of a hundred episodes to reduce the variations between episodes. Following, we describe the results of each set of experiments.

Learning without attacks
First of all, in the first set of experiments, we show the performance of the learner agent without an enemy presence in Figure 3. Both plots show different learning curves each one corresponding to a different exploration rate. All configurations reach the goal before a thousand episodes. However, softmax takes more episodes for reaching their maximum values than -greedy.

Using Fixed Exploration Probabilities
In Figure 3, both exploration strategies show that the agent reaches the goal in fewer steps using low values of exploration. A higher rate of exploration performs more exploratory than exploitative actions and, although the agent still reaches the goal, the path is longer. On the contrary, low exploration rates lead the agent to perform more exploitative than exploratory actions, which cause to fall in local minimum from which the agent is not able to escape. Finally, Figure 3 also shows that the agent behaves almost randomly when or the temperature parameter are larger than 0.7.
Once we analyzed the performance using a free-of-attacks scenario, we study how perturbations affect the system. In this set of experiments, the enemy injects adversarial rewards since episode 1000. At this time, a policy to reach one of the goals is learned by both exploration strategies.
In the learning processes of Figure 5, we fix the attack probability p to p = 0.3. In the case of -greedy, Figure 5 shows this attack probability is enough to destroy a total exploitation strategy policy. We observe that all the exploration rates obtain their worst results a few episodes after the emergence of corrupted rewards. After that, the learning processes associated to low exploration rates are able to improve their behaviors but without achieving the initial performances.
A similar analysis can be made with the softmax strategy at the right in Figure 5. Few episodes later the irruption of corrupted rewards the performance of all configurations drops drastically. However, interestingly and in contrast to -greedy, these agents are not able to slightly recover their performance. Figure 5 demonstrates that low exploration rates are more resilient to small probabilities of attack. The reason is that these configurations allow the agent to reach a goal more frequently and, hence, it still receives more positives than negatives rewards, but it is unable to repair the policy.
Nevertheless, both strategies significantly decrease their performance under corrupted rewards, even with a low attack rate. When the adversary increases this rate, the agent is completely lost with attack probabilities higher that than p = 0.4. In these cases, all the learned policies are wrong. Agents can occasionally reach the goal cell using exploration rates higher than 0.7, but it is not enough to repair their policies.
One of the main objective of the adversary is to avoid being detected. Its objective is to reduce the discounted reward of the learner and also the number of attacks. Each attack has a cost associated. In this problem, we measure the cost as the number of attacks performed by the adversary. In Figure 4, we combine the performance of the agent learner in the vertical axis and the cost in the x-axis. In this way, Figure 4 shows the two metrics the adversary wants to optimize. The lowerleft the better for the adversary and the other way around for the learner. We show an interesting pattern in the first attacks which are the most harmful to deteriorate the policy. We confirm that low exploration rates need more attacks to reduce their performances and, also, that few attacks affect considerably the highest exploration rates.
When we increase the attack probability p, the performance of all configurations decrease. We show in Figure 6 the minimum attack probability which is able to worsen any behavior. Also, we analyze the number of attacks needed to corrupt their policies. However, exploration strategies with exploration rates higher than 0.6 reach one of the goals randomly. For this reason, we only compare configurations which use the learned policy. Comparing the Figures 4 and 6, we observe that the higher the attack rate, the fewer number of attacks needed to destroy the policy. In the Figure 4, the adversary performs more than 1000 attacks to destroy the policies with the highest exploration rates. On the other plot, the adversary needs only less than 400 attacks to break the configurations which follow a policy, this means that the second attack strategy reduces the number of attacks more than 50%. In addition, attacking at each learning episode obtains the lowest cost for all configurations. Here, the adversary is able to destroy all the policies using only half as much as the setting used in the Figure 6.
Due to exploration strategies, softmax keeps reaching at least one of the problem goals. This explains why softmax performs a higher number of attacks.
The cause of this reduction is that report negative rewards frequently produces changes in the Q-table. The update function changes the value of the optimal actions for one negative and the agent selects actions that keep him away from the goal. For this reason, we consider consecutive attacks as the main factor to create successfully attack strategies.
In the light of the findings, we can conclude that softmax needs more episodes to learn and it suffers from adversarial perturbations further than -greedy. In addition, it is required an exhaustive tuning of its temperature parameter in order to reach an appropiatte performance.

Using Dynamic Exploration Probabilities
In the second set of experiments, we use a dynamic probability of exploration, starting with the maximum exploration rate    (i.e., = 1) and ending with total exploitation (i.e., = 0). In this way, the agent totally explores until it learns a policy and, in future episodes, starts to follow its policy. In Figure 7, we show the performance during the training updating the exploration rate every episode. In this set of experiments, unlike the former set, each line uses a different attack probability p. We increase this probability from p = 0.0 to p = 1.0 in steps of 0.1. The adversary return corrupted rewards from the beginning of the task. We use the configuration without adversary presence as reference to compare with the rest of experiments. In contrast to the first set of experiments, the agent takes more time to achieve its maximum performance. In particular, the agent obtains the best result at the end of the training. Focusing on the behavior of the corrupted rewards, we observe that the learner is able to reach the goal in few steps more than using the optimal policy with attack probabilities lower than p = 0.3. Using attack probabilities of p = 0.3 or p = 0.4 produces that the policies get worsen when the agent reduces significantly its exploration rate. In addition, attack probabilities higher of p = 0.5 or higher produce that the agent gets lost in all episodes. Figure 7 demonstrate that the dynamic configuration is more robust to corrupted rewards than the fixed. In the fixed exploration experiments, we visualize huge variations between episodes when the agent is under enemy perturbations. On the contrary, the configuration with our adaptive exploration strategy achieves an almost identical behavior when the attack rate is low. Additionally, in terms of cost, the adversary needs to increase significantly the number of perturbations. This occurs because the attacked agent is still reaching the goal and the adversary continues crafting corrupted rewards. In this way, the adversary needs a greater number of attacks to destroy the learned policy and the agent may detect the insider.

Conclusion
In this paper, we execute an exhaustive evaluation to test the robustness of different exploration/exploitation strategies. We use two set of experiments: fixed and dynamic exploration. The former modifies the probability of exploration and we compare these configurations under different adversary attack rates. In the latter, we use a dynamic exploration strategy to analyze the effects under different enemy strategies. Both set of experiments show that the highest probabilities of exploration are not able to reach the goal under the influence of an adversary, even with a low attack probability. Also, increasing the attack probability over the 40%, the adversary destroys all the policies in a few steps. As a result, we demonstrate that the first attacks after a learned policy and the consecutive adversary injections are the most harmful to deteriorate the agent behavior.
From the adversary point of view, it aims to avoid being detected, so we propose a method to inject adversarial rewards reducing the number of attacks and the hardness of craft. In terms of cost, the adversary obtains its best performance attacking in each episode. This strategy produces policy failures performing less than 400 corrupted rewards in all the configurations. To decrease the number of attacks, we propose to attack only when the learner reaches the goal state. Also, we modify the attack probability to identify the best configuration for the adversary. Attacking at each learning episode is the cheapest adversary strategy.
The experiments presented in this paper demonstrate some characteristics about exploration strategies in the presence of Adversarial perturbations.
1. -greedy is more robust than softmax. The probability of performing actions that differ from the policy learned in addition to the complexity of finding the right temperature parameters cause softmax obtains worse results than -greedy. 2. Low exploration ratios are more resilient to attacks than larger values. Larger values of exploration produce a significant number of random actions aiming to reach any goal, regardless the number of steps or even the reward the agent receives. 3. Dynamic exploration strategy is more resistant to perturbations. The dynamic exploration agent is able to resist perturbation rates below 0.3 even from the beginning of the training and it obtains a performance similar to the free adversary scenario. We consider that this strategy is an excellent alternative to train an agent when there are chances of obtaining disturbances in the reward function. 4. As opposed to what one might think, performing attacks every episode becomes the cheapest option. Performing consecutive attacks are more harmful because the agent can not adjust their Q table values to correct these pertur- bations in future episodes.
In future work, we would generalize our approach using other domains such as the Atari games used in Deep RL. Also, we would analyze the behavior of other agent configurations. Testing more elaborate attacks strategies such as introducing intermediate rewards or developing smart adversary behaviors are some examples of an exciting topic for future research.

Acknowledgment
This research is granted by Repsol, the Spanish Goverment (Ministerio de Economia y Empresa) and FEDER, UE funds under project TIN2017-88476-C2-2-R. This research was funded in part by JPMorgan Chase & Co. Any views or opinions expressed herein are solely those of the authors listed, and may differ from the views and opinions expressed by JPMorgan Chase & Co. or its affiliates. This material is not a product of the Research Department of J.P. Morgan Securities LLC. This material should not be construed as an individual recommendation for any particular client and is not intended as a recommendation of particular securities, financial instruments or strategies for a particular client. This material does not constitute a solicitation or offer in any jurisdiction.