{'fraction_non_alphanumeric': 0.035686102586584834, 'fraction_numerical': 0.007628233231039018, 'mean_word_length': 4.801373346897253, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 2, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Can a Compact Neuronal Circuit Policy be Re-purposed to Learn Simple Robotic Control?

We propose a neural information processing system which is obtained by re-purposing the function of a biological neural circuit model, to govern simulated and real-world control tasks. Inspired by the structure of the nervous system of the soil-worm, C. elegans, we introduce Neuronal Circuit Policies (NCPs), defined as the model of biological neural circuits reparameterized for the control of an alternative task. We learn instances of NCPs to control a series of robotic tasks, including the autonomous parking of a real-world rover robot. For reconfiguration of the purpose of the neural circuit, we adopt a search-based optimization algorithm. Neuronal circuit policies perform on par and in some cases surpass the performance of contemporary deep learning models with the advantage leveraging significantly fewer learnable parameters and realizing interpretable dynamics at the cell-level.


I. INTRODUCTION
We wish to explore a new class of machine learning algorithms for robot control that is inspired by nature. Through natural evolution, the subnetworks within the nervous system of the nematode, C. elegans, structured a nearoptimal wiring diagram from the wiring economy principle 1 perspective [2], [1]. Its stereotypic brain composed of 302 neurons connected through approximately 8000 chemical and electrical synapses [3]. C. elegans exhibits distinct behavioral mechanisms to process complex chemical stimulations [4], avoid osmotic regions [5], sleep [6], show adaptive behavior [7], perform mechanosensation [8], and to control muscles [9]. The functions of many neural circuits within its brain have been identified [10], [11], [12], [6], and simulated [13], [14], [15], [16], [17], which makes it a suitable model organism to be investigated, computationally. The general network architecture in C. elegans establishes a hierarchical topology from sensory neurons through upper interneuron and command interneurons down to motor neurons (See Fig. 1A). In these neuronal circuits, typically interneurons establish highly recurrent wiring diagrams with each other while sensors and command neurons mostly realize feedforward connections to their downstream neurons. An example of such a structure is a neural circuit shown in Fig. 1B, the Tap-withdrawal (TW) circuit [18], which is responsible for inducing a forward/backward locomotion reflex when the worm is mechanically exposed to touch stimulus on its Left: C. elegans' general neuronal circuit structure. Right: Tap-Withdrawal (TW) neural circuit schematic. Total number of interneurons = N i + N C . We preserve the TW circuit wiring topology, model its dynamics by computational models, and deploy a search-based reinforcement learning algorithm to control robots.
body. The circuit has been characterized in terms of its neuronal dynamics [11]. The TW circuit comprises nine neuron classes which are wired together by means of chemical and electrical synapses. Behavior of the TW reflexive response is substantially similar to the control agent's reaction in some standard control settings such as a controller acting on driving an underpowered car, to go up on a steep hill, known as the Mountain Car [19], or a controller acting on the navigation of a rover robot that plans to go from point A to B, on a planned trajectory.
The biophysical neuronal and synaptic models express useful properties; 1) In addition to the nonlinearities exposed on the neurons' hidden state, synapses also are modeled by additional nonlinearity. This property results in realizing complex dynamics with a fewer number of neurons. 2) Their dynamics are set by grounded biophysical properties which ease the interpretation of the network hidden dynamics.
The trained networks obtained by learning the parameters of a fixed neural circuit structure are called neuronal circuit policies (NCP). We experimentally investigate NCP's properties in terms, their learning performance, their ability to solve tasks in different RL domains, and ways to interpret their internal dynamics. For this purpose, we preserve the wiring structure of an example NCP (the TW circuit) and adopt a search-based optimization algorithm for learning the arXiv:1809.04423v2 [cs.
LG] 16 Nov 2019 neuronal and synaptic parameters of the network. This paper contributes to the following: • Demonstration of a compact neuronal circuit policy (NCP) inspired by the brain of the C. elegans worm, as an interpretable controller in various control settings. • An optimization algorithm (Adaptive search-based) and experiments with NCPs in different control domains, including simulated and physical robots. • Autonomous parking of a mobile robot by re-purposing a compact neuronal circuit policy. • Interpretation of the internal dynamics of the learned policies. We introduce a novel computational method to understand continuous-time network dynamics. The technique (Definition 1) determines the relation between the kinetics of sensory/interneurons and a motor neuron's decision, We compute the magnitude of a neuron's contribution, (positive or negative), of these hidden nodes to the output dynamics in determinable phases of activity, during the simulation.
II. PRELIMINARIES In this section, we first briefly describe the structure and dynamics of the tap-withdrawal neural circuit. We then introduce the mathematical neuron and synapse models utilized to build up the circuit, as an instance of neuronal circuit policies.
A. Tap-Withdrawal Neural Circuit Revisit A mechanically exposed stimulus (i.e. tap) to the petri dish in which the worm inhabits, results in the animal's reflexive response in the form of a forward or backward movement. This response has been named as the tap-withdrawal reflex, and the circuit identified to underlay such behavior is known as the tap-withdrawal (TW) neural circuit [18]. The circuit is shown in Fig. 1B. It is composed of four sensory neurons, PVD and PLM (posterior touch sensors), AVM and ALM (anterior touch sensors), four interneuron classes (AVD, PVC, AVA and AVB), and two subgroup of motor neurons which are abstracted as a forward locomotory neurons, FWD, and backward locomotory neurons, REV. Interneurons recurrently synapse into each other with excitatory and inhibitory synaptic links.

B. Neural circuit modeling revisit
Here, we briefly describe the neuron and synapse model model [20], [21], used to design neural circuit dynamics. Dynamics of neurȧ where V i (t) and V j (t) stand for the potential of the post and pre-synaptic neurons, respectively. E i,L and E i, j are the reversal potentials of the leakage and chemical channels. I i,L ,Î i, j , and I i, j present the currents flowing through the leak channel, electric-synapse, and chemical-synapse, with conductances ω i,L ,ω i, j , and ω i, j , respectively. g i, j (t) is the dynamic conductance of the chemical-synapse, and C i,m is the membrane capacitance. E i, j determines the whether a synapse is inhibitory or excitatory. For interacting with the environment, We introduced sensory and motor neuron models. A sensory component consists of two neurons S p , S n and an input variable, x. S p gets activated when x has a positive value, whereas S n fires when x is negative. The potential of the neurons S p , and S n , as a function of For simulating neural networks composed of such dynamic models, we adopted an implicit numerical solver [22]. Formally, we realized the ODE models in a hybrid fashion which combines both implicit and explicit Euler's discretization method [21]. (See Supplementary Materials Section 3, for a concrete discussion on the model implementation, and the choice of parameters.) Note that the solver has to serve as a real-time control system, additionally. For reducing the complexity, therefore, our method realizes a fixed-timestep solver. The solver's complexity for each time step ∆ t is O(|# neurons| + |# synapses|). In the next section, we introduce the optimization algorithm used to reparametrize the tap-withdrawal circuit.

III. SEARCH-BASED OPTIMIZATION ALGORITHM
In this section we formulate a Reinforcement learning (RL) setting for tuning the parameters of a given neural circuit to control robots. The behavior of a neural circuit can be expressed as a policy π θ (o i , s i ) → a i+1 , s i+1 , that maps an observation o i , and an internal state s i of the circuit, to an action a i+1 , and a new internal state s i+1 . This policy acts upon a possible stochastic environment Env(a i+1 ), that provides an observation o i+1 , and a reward, r i+1 . The stochastic return is given by R(θ ) := ∑ T t=1 r t . The objective of the Reinforcement learning is to find a θ that maximizes E R(θ ) .
Simple search based RL [23], as suggested in [24], in [25], and very recently in [26], can scale and perform competitively with gradient-based approaches, and in some cases even surpass their performance, with clear advantages

Algorithm 1: Adaptive Random Search
Input: A stochastic objective indicator f and a starting parameter θ , noise scale σ , adaption rate α ≥ 1 Output: such as skipping gradient scaling issues. Accordingly, we adopted a simple search-based algorithm to train the neuronal policies.
Our approach combines a Adaptive Random Search (ARS) optimization [27], with an Objective Estimate (OE) function f : θ → R + . The OE generates N rollouts with π θ on the environment and computes an estimate of E(R θ ) based on a filtering mechanism on these N samples. We compared two filtering strategies in this context; 1) taking the average of the N samples, and 2) taking the average of the worst k samples out of N samples.
The first strategy is equivalent to the Sample Mean estimator [24], whereas the second strategy aims to avoid getting misled by outlying high samples of E(R θ ). The objective for realizing the second strategy was the fact that a suitable parameter θ enforces the policy π θ control the environment in a reasonable way even in challenging situations (i.e. rollouts with the lowest return). The algorithm is outlined in Algorithm 1. We treat the filtering strategy as a hyperparameter.

IV. EXPERIMENTS
The goal of our experimentation is to answer the following questions: 1) How would a neural circuit policy with a preserved biological connectome, perform in basic standard control settings, compared to that of a randomly wired circuit? 2) When possible, how would the performance of our learned circuit compare to the other methods? 3) Can we transfer a policy from a simulated environment to a real environment? 4) How can we interpret the behavior of the neural circuit policies? We use four benchmarks for measuring and calibrating the performance of this approach including one robot application to parking for the TW sensory/motor neurons and then deployed our RL algorithm to learn the parameters of the TW circuit and optimize the control objective. The environments include I) Inverted pendulum of Roboschool [28], II) Mountain car of OpenAI Gym, III) Half-CHeetah from Mujoco, and IV) Parking a real rover robot with a transferred policy from a simulated environment. The code is available online. 3 The TW neural circuit (cf. Fig. 1B) allows us to incorporate four input observations and to take two output control actions. We evaluate our NCP in environments of different toolkits on a variety of dynamics, interactions, and reward settings.
A. How to map NCPs to environments?
The TW neural circuit is shown in Fig. 1B, contains four sensory neurons. It, therefore, allows us to map the circuit to four input variables. Let us assume we have an inverted pendulum environment which provides four observation variables The position of the cart x, together with its velocitẏ x, the angle of the pendulum ϕ. 4 along with its angular velocityφ. Since the main objective of the controller is to balance the pendulum in an upward position and make the car stay within the horizontal borders, we can feed ϕ (positive and negative values), and x (positive and negative), as the inputs to the sensors of the TW circuit. Control commands can be obtained from the motor neuron classes, FWD and REV. Likewise, any other control problem can be feasibly mapped to an NCP. We set up the search-based RL algorithm to optimize neurons' and synapses' parameters ω,ω, σ ,C m , E L and G L , within their corresponding range, shown in Table I. A video of different stages of the learned neuronal circuit policy for the inverted pendulum can be viewed at https://youtu.be/cobEtJVw3A4 In a simulated Mountaincar experiment, the environmental variables are the car's horizontal position, x, together with its linear velocity. The control signal applies force to the car to build up momentum until finally reaching the top of the hill. The TW circuit can then be learned by the searchbased RL algorithm. A video illustrating the control of the car at various episodes during the optimization process can be viewed at https://youtu.be/J7vXFsZz7EM.   Table S3 in the Supplementary Material for more details.
output variables. We add a linear layer that maps an arbitrary number of input variables to two continuous variables that are then fed into the four sensory neurons of the TW circuit, as shown in Fig. 2D. Similarly, we add a linear layer that maps the neuron potentials of the two motor neurons to the control outputs. A video of this experiment can be viewed at https://youtu.be/3EhHLINROo4.

C. Transfer learned NCPs to control real robot
In this experiment, we generalized our TW neuronal circuit policy to a real-world control test-bed. We let the TW circuit learn to park a rover robot on a determined spot, given a set of checkpoints form a trajectory, in a deterministic simulated environment. We then deploy the learned policy on a mobile robot in a real environment shown in Fig. 2A.
The key objective here is to show the capability of the method to perform well in a transformation from a simulated environment to a real setting. For doing this, we developed a custom deterministic simulated RL environment.
The rover robot provides four observational variables (start signal, position (x, y) and angular orientation θ ), together with two motor actions (linear and angular velocity, v and w). We mapped all four observatory variables, as illustrated in Fig. 2B, to the sensors of the TW. Note that here the geometric reference of the surrounding space is set at the initial position of the robot. Therefore, observation variables are positive. We mapped the linear velocity (which is a positive variable throughout the parking task) to one motor neuron and the same variable to another motor neuron. We determined two motor neurons for the positive and negative angular velocity. (See Table S3 in Supplementary for mapping details). 5 This configuration implies that the command neuron, AVA, controls two motor neurons responsible for the turn-right and forward motion-primitives, and AVB to control the turn-left and also forward motor neurons.
Optimization setup for the parking task -A set of checkpoints on a pre-defined parking trajectory were determined in the custom simulated environment. For every checkpoint, a deadline was assigned. At each deadline, a reward was given as the negative distance of the rover to the current checkpoint. The checkpoints are placed to resemble a real parking trajectory composed of a sequence of motion primitives: Forward, turn left, forward, turn right, forward, and stop. We then learned the TW circuit by the RL algorithm. The learned policy has been mounted on a Pioneer AT-3 mobile robot and performed a reasonable parking performance. The Video of the performance of the TW neuronal circuit policy on the parking task can be viewed at https://youtu.be/p0GqKf0V0Ew.

V. EXPERIMENTAL EVALUATION
In this section, we thoroughly assess the results of our experimentation. We qualitatively and quantitatively explain the performance of our neuronal circuit policies. We then benchmark our results where possible, with the existing methods and describe the main attributes of our methodology. Finally, we quantitatively interpret the dynamics of the learned policies.

A. Are NCPs better than random circuits?
We performed an experiment in which we designed circuits with randomly wired connectomes, with the same number of neurons and synapses used in the TW circuit. (11 neurons, 28 synapses). Connections between each neuron pair are set randomly by a random choice of the synapse type (excitatory, inhibitory or gap junction) with a simple rule that no synapse can be fed into a sensory neuron, which is a property of NCPs as well. The random circuits were then trained over a series of control tasks described earlier, and their performance is reported in Table II. We observe that NCPs significantly outperform the randomly wired networks, which is empirical evidence for the applicability of the NCPs.

B. Performance
The training algorithm was able to solve all the tasks, after a reasonable number of iterations, as shown in the learning curves in Fig. 3A-D. Jumps in the learning curves of the mountain car (Fig. 3B) are the consequence of the sparse reward. For the deterministic parking trajectory, the learning curve converges in less than 5000 iterations.

C. How does NCP + random search compares with policy gradient based RL algorithms?
NCPs + Random search algorithm demonstrates comparable performance to the state-of-the-art policy gradient RL algorithms such as Proximal Policy optimization (PPO) [28], and advantage actor critic (A2C) [29]. Table III reports the performance of the mentioned algorithms compared to NPC+RS. D. How does NCP compare to deep learning models?
The final return values for the basic standard RL tasks (provided in Table IV), matches that of conventional policies [30], and the state-of-the-art deep neural network policies learned by many RL algorithms [28], [31]. We compared the performance of the learned TW circuit to long short-term memory (LSTM) recurrent neural networks [32], multi-layer peceptrons (MLP), and random circuits. We select the same number of cells (neurons) for the LSTM and MLP networks, equal to size of the tap-withdrawal circuit. LSTM and MLP networks are fully connected while the TW circuit realizes a 77% network sparsity. In simple tasks experiments the TW circuit performs in par with the MLP and LSTM networks, while in the HalfCheetah experience, it significantly achieves a better performance. Results are summarized in Table IV.

E. Interpretability of the neuronal circuit policies
In this section, we introduce a systematic method for interpreting the internal dynamics of an NCP. The technique determines how the kinetics of sensory neurons and interneurons relate to a motor neuron's decision. Fig. 4B illustrates how various adaptive time-constants are realized in the parking environment. Interneurons (particularly PVC and AVA) change their time-constants significantly compared to the other nodes. This corresponds to their contribution to various dynamical modes and their ability to toggle between dynamic phases of an output decision. Fig. 4C visualizes the activity of individual TW neurons (lighter colors correspond to a more activation phase) over the parking trajectory. It becomes qualitatively explainable how individual neurons learned to contribute to performing autonomous parking. For instance, AVA which is the command neuron for turning the robot to the right-hand-side (Motor neuron RGT) while it is moving, gets highly activated during a right turn. Similarly, AVB and LFT neurons are excited during a left-turning phase. (See Fig. 4C). Next, we formalize a quantitative measure of a NCP element's contribution to its output decision. . Given the input dynamics, we quantify the way sensory neurons and interneurons contribute to motor neurons' dynamics, by computing the histogram of all Ωs, with a bin-size equal to l (i.e. Fig 4D), as follows: • If sum of bin-counts of all Ω > 0, is more than half of the sum of bin-counts in the Ω < 0, the overall contribution of N i to n j is considered to be positive. • If sum of bin-counts of all Ω < 0, is more than half of the sum of bin-counts in the Ω > 0, the overall contribution of N i to n j is negative, • Otherwise, N i contributes in phases (switching between antagonistic and phase-alighted) activity of n j , on determinable distinct periods in I. To exemplify the use of the proposed interpretability method, let us consider the neuronal activity of a learned circuit driving a rover robot autonomously on a parking trajectory. Fig. 4D presents the histograms computed by using Definition 1, for the RGT motor neuron dynamics (ie. the neuron responsible for turning the robot to the right) in respect to that of other neurons. Based on Definition 1, we mark AVM, AVD, AVA as positive contributors to the dynamics of the RGT motor neuron. We determine PVD, PLM, and PVC as antagonistic contributors. Neurons such as DVA and AVB realized phase-changing dynamics where their activity toggles between a positive and negative correlations,   periodically. (For the analysis of the full networks' activities visit Supplementary Materials Section 7). 6 Such analysis is generalizable to the other environments too. (See Supplementary Materials Section 7). In that case, the algorithm determines principal neurons in terms of neuron's contribution to a network's output decision in computable intervals within a finite simulation time.

VI. CONCLUSIONS
We showed the performance of neuronal circuit policies in control environments. We empirically demonstrated that the sub-networks taken directly from the nervous system of the small species perform significantly better than randomly wired circuits. We selected the tap-withdrawal neural circuit of the nematode worm as an example NCP, repurposed its parameters by a search based RL algorithm and governed simulated control tasks and generalized to a reallife robotic application. We experimentally demonstrated 6 Supplementary materials of the paper reside online at https: //github.com/mlech26l/neuronal_circuit_policies/ tree/master/supplementary_material the interpretable control performance of the learned circuits in action and introduced a quantitative method to explain networks' dynamics. The proposed method can also be utilized as a building block for the interpretability of recurrent neural networks, which despite a couple of fundamental studies [33], [34], [35], [36], is still a grand challenge to be addressed. Finally, we open-sourced our methodologies, to encourage other researchers to explore the attributes of neuronal circuit policies further and apply them to other control and reinforcement learning domains.