{'fraction_non_alphanumeric': 0.03412202869974806, 'fraction_numerical': 0.009091904918391938, 'mean_word_length': 4.850368471643704, '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}}
Reinforcement Learning Your Way: Agent Characterization through Policy Regularization

The increased complexity of state-of-the-art reinforcement learning (RL) algorithms have resulted in an opacity that inhibits explainability and understanding. This has led to the development of several post-hoc explainability methods that aim to extract information from learned policies thus aiding explainability. These methods rely on empirical observations of the policy and thus aim to generalize a characterization of agents' behaviour. In this study, we have instead developed a method to imbue a characteristic behaviour into agents' policies through regularization of their objective functions. Our method guides the agents' behaviour during learning which results in an intrinsic characterization; it connects the learning process with model explanation. We provide a formal argument and empirical evidence for the viability of our method. In future work, we intend to employ it to develop agents that optimize individual financial customers' investment portfolios based on their spending personalities.


Introduction
Recent advances in reinforcement learning (RL) have increased complexity which, especially for deep RL, has brought forth challenges related to explainability [1]. The opacity of state-of-the-art RL algorithms has led to model developers having a limited understanding of their agents' policies and no influence over learned strategies [2]. While concerns surrounding explainability have been noted for AI in general, it is only more recently that attempts have been made to explain RL systems [3,1,4,5]. These attempts have resulted in a wide suite of methods requiring various degrees of expert knowledge, either about the state-action domain or about the specific RL algorithm. Further, they typically rely on post-hoc analysis of learned policies which give only observational assurances of agents' behaviour. We instead propose an intrinsic method of regularizing agents' actions based on a given prior. While current methods for RL regularization aim to improve training performancee.g., by maximizing the entropy of the action distribution [6], or by minimising the distance to a prior sub-optimal state-action distribution [7] -our aim is the characterization of our agents' behaviours.
We also extend the current regularization techniques to accommodate multi-agent systems which allows intrinsic characterization of individual agents. We provide a formal argument for the rationale of our method and demonstrate its efficacy in a toy problem where agents learn to navigate to a destination on a grid by performing, e.g., only right turns (under the premise that right turns are considered safer than left turns [8]). There are several useful applications beyond this toy problem, such as financial advice based on personal goals.

Agent Characterization
There have been several approaches to characterizing RL agents, with most -if not all -employing some form of post-hoc evaluation technique. Some notable examples are: Probabilistic argumentation [9] in which a human expert creates an 'argumentation graph' with a set of arguments and sub-arguments; sub-arguments attack or support main arguments which attack or support discrete actions. Sub-arguments are labelled as 'ON' or 'OFF' depending on the state observation for each time-step. Main arguments are labelled as 'IN', 'OUT', or 'UNDECIDED' in the following RL setting: states are the union of the argumentation graph and the learned policy, actions are the probabilistic 'attitudes' towards given arguments, and rewards are based on whether an argument attacks or supports an action. The learned 'attitudes' towards certain arguments are used to characterize agents' behaviour.
Structural causal modelling (SCM) [10] learns causal relationships between states and actions through 'action influence graphs' that trace all possible paths from a given initial state to a set of terminal states, via all possible actions in each intermediate state. The learned policy then identifies a causal chain as the single path in the action influence graph that connects the initial state to the relevant terminal state. The explanation is the vector of rewards along the causal chain. Counter-explanations are a set of comparative reward vectors along chains originating from counter-actions in the initial state. Characterizations are made based on causal and counterfactual reasons for agents' choices of action.
Reward decomposition [11,12] decomposes the reward into a vector of intelligible reward classes using expert knowledge. Agent characterization is done by evaluation of the reward vector for each action post training.
Hierarchical reinforcement learning HRL [13,14] divides agents' tasks into sub-tasks to be learned by different agents. This simplifies the problem to be solved by each agent, making their behaviour easier to interpret and thereby making them easier to characterize.
Introspection (interesting elements) [15] is a statistical post-hoc analysis of the policy. It considers elements such as the frequency of visits to states, the estimated values of states and state-action pairs, state-transition probabilities, how much of the state space is visited, etc. Interesting statistical properties from this analysis are used to characterize the policy.

Multi-Agent Reinforcement Learning and Policy Regularization
We consider the multi-agent setting of partially observable Markov decision processes (POMDPs) [16]: for N agents, let S be a set of states, A i a set of actions, and O i a set of incomplete state observations where i ∈ [1, .., N ] and S → O i . Agents select actions according to individual policies π θi (O i ) → A i and receive rewards according to individual reward functions r i (S, A i ) → R, where θ i is the set of parameters governing agent i's policy. Finally, agents aim to maximize their total discounted rewards: where T is the time horizon and γ ∈ [0, 1] is a discount factor. For single-agent systems, the deep deterministic policy gradient algorithm (DDPG) defines the gradient of the objective J(θ) = E s∼p µ [R(s, a)] as [17]: where p µ is the state distribution, D is an experience replay buffer storing observed state transition tuples (s, a, r, s ′ ), and Q µ θ (s, a) is a state-action value function where actions are selected according to a policy µ θ (S) → A. In DDPG, the policy µ -also called the actor -and the value function Q -also called the critic -are modelled by deep neural networks. Equation (1) is extended to a multi-agent setting; the multi-agent deep deterministic policy gradient algorithm (MADDPG) learns individual sets of parameters for each agent θ i [18]: where o i ∈ O i and the experience replay buffer D contains tuples In this work, we further extend MADDPG by adding a regularization term to the actors' objective functions, thus encouraging them to mimic the behaviours specified by simple predefined prior policies. There have been several approaches to regularizing RL algorithms, mostly for the purpose of improved generalization or training performance. In [7], the authors defined an objective function with a regularization term related to the statistical difference between the current policy and a predefined prior: where α is a hyperparameter scaling the relative contribution of the regularization term -the Kullback-Leibler (KL) divergence (D KL ) -and π 0 is the prior policy which the agent attempts to mimic while maximising the reward. The KL divergence is a statistical measure of the difference between two probability distributions, formally: where P and Q are discrete probability distributions on the same probability space X. The stated objective of KL regularization is increased learning performance by penalising policies that stray too far from the prior. The KL divergence is often also called the relative entropy, with KL-regularized RL being the generalization of entropy-regularized RL [19]; specifically if π 0 is the uniform distribution, Equation 3 reduces to, up to a constant, the objective function for entropy-regulated RL as described in [6]: where H(π) = P (π) log(P (π)) is the statistical entropy of the policy. The goal of entropyregularized RL is to encourage exploration by maximising the policy's entropy and is used as standard in certain state-of-the-art RL algorithms, such as soft actor-critic (SAC) [6]. Other notable regularization methods include control regularization where, during learning, the action of the actor is weighted with an action from a sub-optimal prior: µ k = 1 1+λ µ θ + λ 1+λ µ prior and temporal difference regularization which adds a penalty for large differences in the Qvalues of successive states: [20,21].
While our algorithm is based on regularization of the objective function, it could be argued that it shares similar goals as those of algorithms based on constrained RL, namely the intrinsic manipulation of agents' policies towards given objectives. One example of constrained RL is [22] which finds a policy whose long-term measurements lie within a set of constraints by penalising the reward function with the Euclidean distance between the state and a given set of restrictions, e.g., an agent's location relative to obstacles on a map. Another example is [23] which penalises the value function with the accumulated cost of a series of actions, thus avoiding certain state-action situations. However, where constrained RL attempts to avoid certain conditions -usually through a penalty based on expert knowledge of the state -regularized RL aims to promote desired behaviours, such as choosing default actions during training or maximizing exploration by maximising action entropy. The advantage of our system is that it does not require expert knowledge of the state-action space to construct constraints; our regularization term is independent of the state which allows agents to learn simple behavioural patterns, thus improving the interpretability of their characterization.

Methodology
We regulate our agents based on a state-independent prior to maximize rewards while adhering to simple, predefined rules. In a toy problem, we demonstrate that agents learn to find a destination on a map by taking only right turns. Intuitively, we supply the probability distribution of three actions left, straight, and right -as a regularization term in the objective function, meaning the agents aim to mimic this given probability distribution while maximising rewards. Such an agent can thus be characterized as an agent that prefers, e.g., right turns over left turns. As opposed to post-hoc characterization, ours is an intrinsic method that inserts a desirable characteristic into an agent's behaviour during learning.

Action Regularization
We modify the objective function in Equation (4) and replace the regularization term H[π θ (s, a)] = P (π) log(P (π)) with the mean squared error of the expected action and a specified prior π 0 : where λ is a hyperparameter that scales the relative contribution of the regularization term L, a j is the j th action in a vector of M actions, π θ is the current policy, and π 0 is the specified prior distribution of actions which the agent aims to mimic while maximising the reward. Note that π 0 (a) is independent of the state and (a j |π 0 (a)) is therefore constant across all observations and timesteps. This is an important distinction from previous work, and results in a prior that is simpler to construct and a characterization that can be interpreted by non-experts. Since this is a special case of Equation (4), it follows from the derivation given in [6].
We continue by extending our objective function to support a multi-agent setting. From Equation (5) and following the derivation in [18], we derive a multi-agent objective function with i ∈ [1, N ] where N is the number of agents: Further, in accordance with the MADDPG algorithm, we model actions and rewards with actors and critics, respectively [18]: Through simple substitution of Equations (8) and (9) into Equation (7) we formulate our multi-agent regularized objective function: Algorithm 1 optimizes the policies of multiple agents given individual regularization constraints π 0i .

Empirical Setup
We created a toy problem in which one or more agents navigate a 6 × 6 grid through a set of three actions: We ran two sets of experiments, one for a single-agent setting, and one for a dual-agent setting. We sized all networks in these two settings with two fully connected feed-forward layers; the single agent networks had 200 nodes in each layer, while the dual-agent networks had 700 nodes in Algorithm 1 Action-regularized MADDPG algorithm Set the number of agents N ∈ N for i in 1, N do ⊲ For each agent Initialize actor network µ θµ,i with random parameters θ µ,i Initialize critic network Q θQ,i with random parameters θ Q,i Initialize target actor network µ ′ θ µ ′ ,i with parameters θ µ ′ ,i ← θ µ,i Initialize target critic network Q ′ θ Q ′ ,i with parameters θ Q ′ ,i ← θ Q,i Set the desired prior action distribution π 0i Set the number of actions M i ← |π 0i | end for Initialize replay buffer D Set regularization weight λ for e = 1, Episodes do Initialise random function F (e) ∼ N (0, σ e ) for exploration Reset environment and get the state observation Apply compounded action a t Retrieve rewards r [1..N ],t and observations Done ← T rue end if end while Sample a random batch from the replay buffer B ⊂ D for i in 1, N do ⊲ For each agent Update critic parameters θ Q,i by minimising the loss: Update the actor parameters θ µ,i by minimising the loss: ⊲ From Equation 10 Update target network parameters: end for end for each layer. Actor networks had a softmax activation layer, while the critic networks remained unactivated. Our training runs consisted of 3 000 iterations and we tuned the hyperparameters using a simple one-at-a-time parameter sweep. We used training batches of 256 time-steps and sized the reply buffers to hold 2 048 time-steps. In each iteration we collected 256 time-steps and ran two training epochs. We tuned the learning rates to 0.04 for the actors and 0.06 for the critics, the target network update parameters τ to 0.06, and the discount factors γ to 0.95. We specified the regularization coefficient λ = 2, the regularization prior for the single-agent setting as π 0 = [P (A 1 ), P (A 2 ), P (A 3 )] = [0.0, 0.6, 0.4], and the regularization priors for the dual-agent setting as π 0,1 = [0.0, 0.6, 0.4] and π 0,2 = [0.4, 0.6, 0.0]. This meant that the single agent was regularized to not take any left turns, while slightly favouring going straight above turning right. For the dual agents, agent 1 was to avoid left turns while agent 2 was to instead avoid right turns; we did this to demonstrate the characterization of the agents as preferring either left or right turns while navigating to their destinations.

Results
In the single agent setting of our toy problem, we used our algorithm to encourage an agent to prefer right turns over left turns; we used a regularization prior π 0 = [0.0, 0.6, 0.4] to regulate the probability of left actions to 0.0, straight actions to 0.6, and right actions to 0.4. Figure 1 shows three different trajectories that demonstrate such an agent's behaviour for destinations which lie either to the left, straight ahead, or to the right of the agent's starting location. As expected, the agent never turned left and always took the shortest route to its destination given its constraints.     Figure 2 it is clear that the two agents consistently took the shortest path to their respective destinations while adhering to their individual constraints. We therefore characterize them as agents that preferred to take right and left turns, respectively. Crucially, this is an intrinsic property of the agents imposed by the regularization of the objective function. This separates our method of intrinsic characterization from post-hoc characterization techniques. Finally, Figure 3 shows a typical curve of training and testing returns across the 3 000 training iterations. The agents clearly demonstrate a good learning response with steadily increasing returns both in training and testing. (c) Both agents' destinations were located such that they could perform their preferential turn -either to the left, or to the rightaccording to their regularization priors π0,i   Figure 3: Training and testing returns for a typical training run. The learning process clearly followed a steady increase in returns.

Conclusions and Direction for Future Work
Our objective was the intrinsic characterization of RL agents. To this end, we investigated and briefly summarized the relevant state-of-the-art in explainable RL and found that these methods have typically been relying on post-hoc evaluations of a learned policy. Policy regularization is a method that modifies a policy; however, it has typically been employed to enhance training performance which does not necessarily aid in policy characterization. We therefore adapted entropy regularization from maximizing the entropy in the policy to minimizing the mean squared difference between the expected action and a given prior. This encourages the agent to mimic a predefined behaviour while maximizing its reward during learning. Finally, we extended MADDPG with our regularization term. We provided a formal argument for the validity of our algorithm and empirically demonstrated its functioning in a toy problem. In this problem, we characterized two agents to follow different approaches when navigating to a destination in a grid; while one agent performed only right turns, the other performed only left turns. We conclude that our fundamentally sound algorithm was able to imbue specific characteristic behaviours into our agents' policies. In future work, we intend to use this algorithm to develop a set of financial advisors that will optimize individual customers' investment portfolios according to their individual spending personalities [24]. While maximising portfolio values, these agents may prefer, e.g., property investments over crypto currencies which are analogous to right turns and left turns in our toy problem.