1 Introduction

The nematode C. elegans provides an excellent model for studying the chemotaxis behavior because its 302 neurons are clearly described and the neuronal connections are known (White et al. 1986). The nervous system of C. elegans can bedivided into 118 classes: 40 classes of sensory neurons, 48 classes of interneurons and 30 classes of motor neurons. With these neurons, C. elegans can achieve at least seven kinds of behaviors: chemotaxis, thermotaxis, mechanosensation, osmotic avoidance, dauer formation (a kind of hibernation), male mating, and egg laying. Among these behaviors, the firstfour are related to the locomotion behaviors that are widely investigated by four research groups from scientific aspects.

The first research group constructed an artificial neural network to replicate the chemotaxis behavior for food attraction through computer simulation (Ferée and Lockery 1998, 1999; Ferée et al. 1996). Later on, the excitatory, inhibitory and self-connections were found (Dunn and Lockery 2004) and different functional classes of neurons were identified by clustered neural dynamics methods (Dunn et al. 2006). The second research group explored the head turning (Suzuki et al. 2004), direction control (Suzuki et al. 2005a, 2005c), and touch response for forward or backward movement of C. elegans (Suzuki et al. 2005b). The third research group used the biological experiment results to construct an artificial network model to show howa sinusoid wave can be propagated through the body (Karbowski et al. 2008). The fourth research group investigated how themuscles and neurons of C. elegans generated the sinusoid wave and how the wave was propagated from the head to tail (Boyle and Cohen 2008; Boyle et al. 2008). Finally they identified that the gaits of crawling and swimming were the same (Berri et al. 2009).

The present study attempts to extend our preceding work (Xu and Deng 2010) in five aspects. First, we construct the chemotaxis behavioral models that are extracted biologically from neural wire diagram instead of artificial networks. Threechemotaxis behavioral models are constructed in this study for food attraction, toxin avoidance, and integrated foodattraction and toxin avoidance, respectively. The wire diagram for each model is represented by a dynamic neural network(DNN), and each neuron is described as a non-linear active function. DNN is suitable for chemotaxis behavioral model in gowing to its dynamical nature, since its connections can be made analogous to the nature ones such as synapses.

Second, the behaviors of food attraction and toxin avoidance are explored individually, and then an integrated chemotaxis behavioral model is exploited to perform the two behaviors simultaneously. For the chemotaxis behaviors, according to Suzuki et al. (2008), the time derivative of attractant concentration is used for navigation. In our models, thesensory neuron ASE receives the outside input. Furthermore, there should be a neuron remembering the concentration atprevious time for calculating the differentiation of concentration. It is known that biologically the neuron AIY serves as a memory neuron (Ye et al. 2008), which can record the concentration at previous time. Hence, C. elegans has the ability tocalculate the gradient information so that it can guide itself towards the food or escape from the toxin. To represent the chemotaxis behaviors, a set of nonlinear switching logic functions (SFLs) are introduced to map the temporal gradient information of concentration to motor neuron outputs that decide the navigation. DNN istrained to learn the switching logic functions. After training, DNN can regenerate the chemotaxis behavioral motions.

Third, based on the standpoint that the speed of C. elegans is not constant (Leung et al. 2008), we incorporate speed regulation mechanism into these chemotaxis behavioral models, so that the navigation is complete with the orientation control and speed control. In our work, C. elegans is able to not only approach the food source (avoid the toxin source), but also reduce its speed when getting close to the food source (far away from the toxin source).

Fourth, we test our models in different scenarios. In each scenario, C. elegans successfully approaches the food source orescapes from the toxin source. It verifies that SFLs can well capture the chemotaxis behaviors. Furthermore, once C. elegans is trained to learn the SFLs, it can perform its corresponding behaviors in different scenarios without re-training.

Fifth, we quantitatively analyze our results and compare them with other works. First, we analyze the neuronal connectivities of the resultant wire diagrams by following the method of Dunn (2006). In this way, we have investigatedthe similarity of these wire diagrams and simplified them to smaller networks. Next, we use quantitative analysis methodto compare the trajectories of the resultant wire diagrams with the experiment results provided by Pierce-Shimomuraet al. (1999) and Iino and Yoshida (2009). At last, we add the external noise and noise to the resultant wirediagrams and test their robustness. We also quantitatively analyze the trajectories of these wire diagrams affected by noises and compare them with the experiment data provided in Pierce-Shimomura et al. (1999), Iino and Yoshida (2009).

This paper is organized as follows. Section 2 provides several preliminary results for subsequent sections, including the kinematics of locomotion, distribution of food and toxin concentrations, DNN model, and the training method. Section 3 illustrates the locomotion behaviors of C. elegans and the way to construct the switching logic functions. Section 4 investigates the chemotaxis behavioral model for food attraction. Section 5 investigates the chemotaxis behavioral model for toxin avoidance. In Section 6, chemotaxis behavioral models of food attraction and toxin avoidance are integrated intoa single chemotaxis behavioral model to perform food attraction and toxin avoidance concurrently. In each section,the corresponding neural wire diagrams, switching logic functions and testing results are demonstrated indetails. Section 7 explores the similarity of the resultant wire diagrams and quantitatively analyzes thetrajectories of these wire diagrams with or without being affected by noises, while Section 8 concludes the paper.

2 Mathematic models and training method

In this section the mathematical kinematic models of C. elegans are provided first. Then we describe the attractant and repellent concentration distribution. Next, DNN model is constructed and the training method RTRL is demonstrated.

2.1 Kinematic model

In this work, C. elegans is modeled as a point source in the xy plane with velocity \(v(t)\) at head, and angle \(\theta (t)\) measured from the x-axis at time t, as shown in Fig. 1. The velocity \(v(t)\) in our model is variant because recent work (Iino and Yoshida 2009; Leung et al. 2008) indicates that the velocityof C. elegans will change according to the chemical stimulus. Thus we construct the kinematic model as:

$$x(t+1)=x(t)+v(t)T\cos \theta (t)$$
(1)
$$y(t+1)=y(t)+v(t)T \sin \theta (t)$$
(2)
$$\theta (t)=\theta (t-1)+\Delta \theta (t)$$
(3)
$$v(t)=\frac{1}{2}{{V}_{\max }} \cdot [{{V}_{\text{left}}}(t)+{{V}_{\text{right}}}(t)]$$
(4)
$$\Delta \theta (t)=\gamma (V_{\text{right}}(t)-V_{\text{left}}(t))T,$$
(5)

where \(x(t)\) and \(y(t)\) are the position values at time t. \(v(t)\) is the velocity of worm, which is the average value of the left and right output neurons multiplying by the worm’s maximum speed \(V_{\text {max}}\), 0.0022 m/s. \(\theta (t)\) is determined by the difference of left and right output neurons multiplying by one constant \(\gamma \), which is called turning rate Ferrée et al. (1996). T is the sampling period.

Fig. 1
figure 1

The coordinate of C. elegans in the xy plane. C. elegans is modeled as a point source in the xy plane with velocity \(v(t)\). The head angle \(\theta (t)\) measured from the x-axis at time t

From the above kinematic model, it can be seen that the speed \(v(t)\) is changing according to the summation of two outputs: \(V_{\text {left}}(t)+V_{\text {right}}(t)\), and the direction of the worm \(\theta \) is determined by the subtraction of two outputs: \(V_{\text {right}}(t)-V_{\text {left}}(t)\). When \(V_{\text {left}}(t)>V_{\text {right}}(t)\), the worm turns right, and vice versa. When \(V_{\text {left}}(t)=V_{\text {right}}(t)\), the worm goes straightly. When \(V_{\text {left}}(t)\) and \(V_{\text {right}}(t)\) become small and approach to 0, the worm slows down to stop. Thus, both the speed and the direction change concurrently.

2.2 Concentration distribution

The concentration distribution of both food and toxin is assumed in Gaussian distribution (Ferrée and Lockery 1999):

$$C(x,y)=C_{\text{max}} exp \left(-\frac{x^2+y^2}{S}\right),$$
(6)

where \(C_{\rm max}\) is the peak value of the attractant or repellent and S is the variance of the distribution. The unit of the concentration C is millimolar concentration (mmol/L, shorts for mM).

One example of concentration distribution is shown graphically in Fig. 2.

Fig. 2
figure 2

The potential field of concentration distributed in a square area with the range \([-0.2, 0.2]\) meters, where \(C_{\rm max}= 2\) mM and \(S=0.01\)

2.3 Dynamic neural network model

Each neuron in this paper is denoted as a dynamic neuron with self-feedback (Izquierdoand Lockery 2010). The state of the ith neuron can be represented as the voltage \(V_{i}\). In this paper, we adopt a discrete DNN:

$$\begin{array}{rll}{{V}_{i}}(t+1)&=&{{\alpha }_{i}}{{V}_{i}}(t)+{{\beta }_{i}} \cdot \text{tanh} \left(\sum\limits_{j=1,i\ne j}^{N}{{w}_{ij}}({{V}_{j}}(t)-{{\overline{V}}_{j}})\right) \\ && +\,{{b}_{i}}+\delta_{i}u_{i}(t),\end{array}$$
(7)

where the exogenous input \(u_{i}(t)\) is the instantaneous chemical concentration sensed by sensory neurons. The constant \(\overline {V}_{j}\) is the center of the conductance of the jth neuron (Ferrée and Lockery 1999), which means at this voltage there is no transmitter released from the jth neuron. \(w_{ij}\) represents the strength of synapticconnection from neuron j to i. \(b_{i}\) is a constant bias introduced here to adjust the resting potential value (Maass 1997). When neuron i is the sensor neuron, \(\delta _{i}=1\), otherwise \(\delta _{i}=0\). The parameters to be determined through training are \(\alpha _{i}\), \(\beta _{i}\), \(w_{ij}\), \(\overline {V}_{i}\), \(b_{i}\), for \(i,j=1, \cdots , N\).

2.4 Training method

To train the dynamic neural network, there are mainly two training algorithms, Back-propagation Through Time (BPTT), and Real-time Recurrent Learning (RTRL) (Williams and Zipser 1989). The BPTT is a kind of BPalgorithm which is suitable for layer-structured neural networks. However, since the wire diagram of C. elegans is biologically connected without layers, RTRL is an appropriate training method for parametric learning.

The RTRL first defines an error function:

$$E(t)=\frac{1}{2}\sum\limits_{i=1}^{N}{e_{i}^{2}(t)},$$
(8)

where \(e_{i}=d_{i}(t)-V_{i}(t)\), and \(d_{i}(t)\) is a desired output.

The updating law is

$$W(t+1)=W(t)+\Delta W(t), $$
(9)
$$\Delta W(t)=-\eta \frac{\partial E(t)}{\partial W(t)}=\eta \sum\limits_{i=1}^{N}{{{e}_{i}}(t)\frac{\partial {{V}_{i}}(t)}{\partial W(t)}},$$
(10)

where \(\eta \) is a learning rate, and \(W(t)\) denotes one of the parameters \(w_{ij}\), \(\overline {V}_{i}\), \(\alpha _{i}\), \(\beta _{i}\), and \(b_{i}\).

All DNN models are trained by RTRL to learn their specific switching logic functions. Training iteration for individual models varies from 8,000 to 50,000 epochs. All neural connection weights are set with initial values randomly between \(-0.5\) and 0.5. Learning rates are set to 0.002 for \(w_{ij}\) and 0.01 for other parameters. The lower learning rates ensure the convergence of training. Furthermore, there are three points should be noted for training.

First, the range of initial weights plays the important role for convergence. It is mentioned that the initial weights should not to be too large (Lee et al. 1991; Saseetharran 1996; Wu and Zhang 2002). Large initial weights are in the extreme regions of the sigmoid functions, hence difficult to adjust or update. This is because the gradient value of the sigmoid function is rather low at extreme regions due to the flatness of the sigmoid function (Lari-Najafi et al. 1989).

Remark 1

We also try the initial weights with the range \([-1,1]\) and \([-2,2]\). There are no obvious differences comparing with the range \([-0.5,0.5]\). When the initial range is between \([-5,5]\), neuronal active functions of the sigmoid function type, such as \(\text {tanh}(x)=({{e}^{x}}-{{e}^{-x}})/\) \(({{e}^{x}}+{{e}^{-x}})\), becomes either \(+1\) or \(-\)1 when x is nearby \(+5\) or \(-\)5. In our work, the active function is \(\text {tanh} \left (\sum \nolimits _{j=1,i\ne j}^{N}{{{w}_{ij}}({{V}_{j}}(t)-{{{\bar {V}}}_{j}})}\right )\)in Eq. (7). If the range of weights \(w_{ij}\) is between \([-5,5]\), the output of active function may become either \(+1\) or \(-\)1, namely, deeply saturated. The deep saturation makes the training difficult because the output of neuron would not vary while the inputs vary.

Second, to avoid the local minimum a randomly restart mechanism is adopted. As mentioned in Hamm et al. (2002), random restarts with a local gradient algorithm may be more effective than a global algorithm at obtaining a low value of the objective function. During the training, if the sum of squared error (SSE) is aconstant for a long period, or the SSE is larger than a value, the training procedure will be restarted byrandomly re-initializing the weights. We set that if the value of SSE is bigger than 0.01 and not changing for 400 epochs, or if the SSE is greater than 4 (except for the initialization), the training procedure will restart.

Third, the wire diagrams are trained with inputs ranging from 0 to 2. If a wider range of concentration inputs is given,we can introduce a scaling factor into the sensory neurons and normalize the inputs within the range [0,2], and the sametest results can be obtained without re-training.

3 Locomotion of C. elegans and switching logic functions

3.1 Locomotion of C. elegans

Biologically, C. elegans moves as a long series of sinusoidal movements, called a run, and it is interrupted approximately twice a minute by sharps turn and reversals (Gray et al. 2005; Pierce-Shimomura et al. 1999; Stephens et al. 2010). Sharp turn is called Omega turn because it shapes as the Greek alphabet \(\Omega \). For \(\Omega \) turn, C. elegans’ head curls back, touching or crossing the tail, and it continues to move forward with a sharp direction changing. For reversal, C. elegans moves backward for several seconds and then moves forward again following by a slight turn, \(\Omega \) turn, or going straightly. With these behaviors, C. elegans can navigates itself towards the food source, preferred temperature areas, or leave far away from the unpleasant places. These behaviors can be attributed to two strategies: klinokinesis and klinotaxis (Lockery 2011). For klinokinesis, C. elegans changes it turning frequency according to themagnitude of outer stimulus, and for klinotaxis, C. elegans moves forward with identical stimulus from bothleft and right sides. Furthermore, C. elegans has two distinct circuits for locomotion, one for forward and another for backward (Kawano et al. 2011). The circuit for forward locomotion achieves the dominant roleand it results in the frequency of backward locomotion far less than that of forward locomotion. Moreover, the activation of ASH can active the backward circuit (Piggott et al. 2011) that yields more reversals or \(\Omega \) turns. For orientation, the mechanism called biased random walk achieves the fundamental role for navigation (Pierce-Shimomura et al. 1999). In large time-scale, the biased random walk can be considered as the forward moving accompanied with the turning towards the preferred direction.

3.2 Switching logic functions

Since C. elegans does not have the sophisticated thinking ability, the complex chemotaxis behaviors can be modeled asinput-output mapping from external stimuli to corresponding motion, namely, from sensory neural inputs to motor neural outputs. In this work, we construct a set of nonlinear functions named SLFs to denote the input-output mapping.

We solve \({V}_{\text {left}}(t)\) and \({V}_{\text {right}}(t)\) from Eqs. (4) and (5):

$${{V}_{\text{left}}(t)}=\underbrace{\frac{v(t)}{V_{\text{max}}}}_{\text{speed}}-\underbrace{\frac{\Delta \theta(t)}{2\gamma T}}_{\text{orientation}},$$
(11)
$${{V}_{\text{right}}(t)}=\underbrace{\frac{v(t)}{V_{\text{max}}}}_{\text{speed}}+\underbrace{\frac{\Delta \theta(t) }{2\gamma T}}_{\text{orientation}},$$
(12)

From Eqs. (11) and (12), both \({V}_{\text {left}}(t)\) and \({V}_{\text {right}}(t)\) are determined by two components: speed and orientation. The speed of C. elegans is varying according to the chemical stimulus \(C(t)\). In ourmodel we assume that the worm chooses right-side turning as its preference. Furthermore, it is proved that the “turningbias” achieves a critical role for chemotaxis behaviors of C. elegans biologically, and the temporal concentration difference\(\Delta C(t)=C(t)-C(t-1)\) is used for navigation (Pierce-Shimomura et al. 2005). For food attraction, when \(\Delta C(t)>0\), C. elegans is heading the correct direction. When \(\Delta C(t)\le 0\), C. elegans is heading a wrong direction and it should turn. It is opposite for toxin avoidance.

As we assume that the right turning is preferred, hence the left-side motor neuron output is always higher than or equalto the right motor neuron. SLFs are constructed as:

$$V_{\text{left}}(t)=\underbrace{\phi ( {C}(t))}_{\text{speed}},$$
(13)
$$V_{\text{right}}(t)=\underbrace{\phi ( {C}(t))}_{\text{speed}}+\underbrace{\sigma ( {C}(t),\Delta C(t))}_{\text{orientation}},$$
(14)

where \(\phi ({C}(t))\) is a SLF of speed with the concentration input \({C}(t)\). \(\sigma ({C}(t),\Delta C(t))\) is a SLF of orientation withthe arguments \({C}(t)\) and temporal concentration difference, \(\Delta C(t)=C(t)-C(t-1)\). This SLF of orientation only appears in Eq. (14). For example, for food attraction, if the direction of C. elegans is correct, \(\Delta C(t)>0\), so \(\sigma ( {C}(t),\Delta C(t))=0\), which has noinfluence on \(V_{\text {right}}\). When \(\Delta C(t)\leq 0\), \(\sigma ( {C}(t),\Delta C(t))\) outputs a negative value that makes \(V_{\text {left}}(t)>V_{\text {right}}(t)\), so C. elegans turns right. It is opposite for toxin avoidance.

It should be noted that SLFs are constructed based on the logic of chemotaxis behaviors. Once the wire diagram is well trained, it can be put into different environments without re-training and there is no problem for it to perform similarbehaviors. It is worth pointing out that the SLFs constructed are not unique. Different SLFs can be designed as long asthe logic is correct. SLFs should be designed with smooth and continuous shape, because it is difficult for neural networks to approximate non-continuous and sharp gradient functions.

4 Chemotaxis behavioral model for food attraction

Finding food and avoiding toxin are the fundamental survival skills of C. elegans. The sensory neurons of C. elegans, such as ASE and ASH, are symmetrical biologically. However, the distance between left-side and right-side sensory neurons are too small, so they work as a single sensory neuron (Ferrée et al. 1996).

In this section, first the wire diagram for food attraction is extracted from biological neural connections. Second, the chemotaxis behavior of food attraction is depicted as a set of SLFs. Third, the wire diagram is trained to learn these SLFs and tested in simulated environment.

4.1 Wire diagram

According to anatomy, the biological wire diagram for food attraction is shown in Fig. 3. This wire diagram is extractedbased on the data provided by Altun and Hall (2006) and Bhatla (2009). We fix the sensory neuron ASE as input neuronfor food attraction (Bargmann and Horvitz 1991), two motor neurons DB and VB as the left and right output neurons, respectively. Other interneurons are added by two rules: (1) with the shortest paths from ASE to DB orVB (Bhatla 2009); (2) with the strongest synaptic connections from ASE to DB or VB (Altun and Hall 2006). The chemical synapse from one neuron to another is modeled as a unidirectional connection, andthe gap junction between two neurons is modeled as a bidirectional connection with two weights. If bothsynapses and gap junction exist between two neurons, we still model the wire as a bidirectional connection with two weights. Whether the weights are positive (active) or negative (inhibitory) is determined by the training.

Fig. 3
figure 3

The wire diagram for food attraction. Neuron ASE is the sensory neuron for food. Neuron AIY functions as the memory neuron recording the previous food concentration information \(C_{f}(t-1)\). The outputs are neurons DB and VB for left and right sides, and the rest are hidden neurons

As shown in Fig. 3, there are twelve interneurons in our model. By comparing to other research works (Gray et al.2005; Suzuki et al. 2004), it is interesting that we share the same eight interneurons: AIA, AIB, AIY, AIZ,DVA, AVA, AVB, and PVC. Biologically, these eight interneurons play the critical role for the locomotion behaviors. Half of all synaptic outputs from the amphid neurons are directed to the interneurons AIA, AIB, AIY, and AIZ (Gray et al. 2005). Furthermore, AIY functions as a memory neuron that records theprevious concentration information (Ye et al. 2008). AVD, AVB, AVA, and PVC are four critical commandneurons for movement (Riddle et al. 1997). It should be noted that the neuron AVD in our work representsboth AVD and AVE. The reason that we combine AVD and AVE together is because AVE has the same postsynaptic partners as AVD (Leung et al. 2008), and it is in accordance with the locomotion circuit of C. elegans in (Riddle et al. 1997), which deals with AVD and AVE as one neuron. Four additional neurons areinvolved in our model that function as interneurons: ADF, PVP, RIF, DVA. Biologically, ADF contributes to a residual chemotactic response after ASE is killed (Altun and Hall 2006), and DVA is an interneuron that serves as the stretch sensitive neuron which is significant for undulatory movement (Karbowski et al. 2008).

The model as shown in Fig. 3 is a simplified biological wire diagram with fifteen neurons. Each neuron in this model possesses an active function (Eq. 7), so the whole wire diagram is a DNN. DNN has the ability to approximate arbitrary nonlinear functions. If DNN can map the input-output relations of the chemotaxis behaviors, then DNN can perform the chemotaxis behaviors after training.

4.2 Switching logic functions for food attraction

SLFs for food attraction are designed as:

$$\phi ({{C}_{f}}(t)) = {{C}_{\max ,f}}-{{C}_{f}}(t),$$
(15)
$$\begin{array}{rll}\sigma ({{C}_{f}}(t),\Delta {{C}_{f}}(t))&=&({{C}_{\max ,f}}-{{C}_{f}}(t))\\&& \cdot\, (\tanh (\Delta {{C}_{f}}(t)+1)-1),\end{array}$$
(16)

where \(C_{f}(t)\) is the concentration input of food, and \(\Delta {{C}_{f}}(t)=C_{f}(t)-C_{f}(t-1)\) is the temporal food concentration difference between two time steps at t and \(t-1\). \({C}_{\max ,f}\) is the maximum value of the food concentration. The final motor neural outputs, \(V_{\text {left}}(t)\) and \(V_{\text {right}}(t)\) in Eqs. (13) and (14) as functions of arguments \(C_{f}(t)\) and \(\Delta C_{f}(t)\), are shown in Fig. 4.

Fig. 4
figure 4

The SLFs for food attraction. If \(C_{f}(t)>C_{f}(t-1)\), C. elegans moves in the correct direction and will move in the same direction. When \(C_{f}(t)\leq C_{f}(t-1)\) (wrong direction), the output of \(V_{\text {right}}\) is smaller than the \(V_{\text {left}}\), so C. elegans turns right. When the input \(C_{f}(t)\) is approaching to \(C_{\text {max},f}=2\) mM, the outputs of both motor neurons will approach to zero

For the speed regulation mechanism, as it is said in Leung et al. (2008), C. elegans will slow down its speed whenapproaching the food. For our model, we assume that if C. elegans arrives at the food source, it will slow down its speed tozero. Otherwise, it maintains a high speed to cruise. In the SLFs for food attraction, Eqs. (13)–(16), if \(C_{f}(t)\) is small, the outputs of \(V_{\text {left}}(t)\) and \(V_{\text {right}}(t)\) are large, and therefore the speed is high. When \(C_{f}(t)\) becomes larger, the amplitude of \(V_{\text {left}}(t)\) and \(V_{\text {right}}(t)\) decreases, which yields lower speed. For the orientation control, as shown in Fig. 5, when \(\Delta C_{f}>0\), C. elegans moves towards the correct direction. In this case, \(\sigma ({{C}_{f}}(t),\Delta {{C}_{f}}(t))=0\) in Eq. (16), that is \(V_{\text {left}}=V_{\text {right}}\), and C. elegans goes straightly. When \(\Delta C_{f}\leq 0\), which means C. elegans moves towards the wrong direction. \(\sigma ({{C}_{f}}(t),\Delta {{C}_{f}}(t))<0\) yields \(V_{\text {left}}>V_{\text {right}}\), so C. elegans turns right. As shown in Fig. 4, a large negative temporal concentration variationyields a large difference between left and right output neurons, which can generate the abrupt turn (\(\Omega \) turn), whereas a small negative temporal concentration variation yields a small difference between left and right output neurons, which produces the slight turn.

Fig. 5
figure 5

Movement demonstration for food attraction. If \(C_{f}(t) > C_{f}(t-1)\), C. elegans is in the correct direction, so \(V_{\text {left}}=V_{\text {right}}\) and it goes straightly. When \(C_{f}(t) \leq C_{f}(t-1)\) (wrong direction), the output of \(V_{\text {right}}\) is smaller than the output of \(V_{\text {left}}\), which makes C. elegans turn right

The choice of SLFs is not limited to Eqs. (15) and (16). \(\phi ({{C}_{f}}(t))\) should be reciprocal to \(C_{f}(t)\) for food attraction. C. elegans needs to stop when it reaches the food source, namely, \(C_{f}(t)\) reaches maximum. For the orientation control, \(\sigma ({{C}_{f}}(t),\Delta {{C}_{f}}(t))\) is reciprocal to \({C}_{f}(t)\) but proportional to \(\Delta {{C}_{f}}(t)\). Furthermore, when nearby the food source, sharp turning of C. elegans is not necessary even if \(\Delta {{C}_{f}}(t)\) is very negative. However, when C. elegans is far from the food source, a large \(\Delta {{C}_{f}}(t)\) leads toa sharp turning.

4.3 Testing results

The wire diagram for food attraction shown in Fig. 3 is trained to remember the input-output mapping for food attraction (Fig. 4).

For the training data, the input data include two terms, \(C_{f}(t)\) and \(C_{f}(t-1)\), which range from 0 to 2 with interval 0.1. To train this model, it needs two neurons to receive the input training data, \(C_{f}(t)\) and \(C_{f}(t-1)\). ASE functions as the attractant sensory neuron (Riddle et al. 1997) to receive the input \(C_{f}(t)\). As claimed by Yeet al. (2008), AIY has the memory ability. Based on this result, AIY is assigned by us to serve as the memory neuron to receivethe input \(C_{f}(t-1)\). However, as shown in Fig. 3, AIA, AIZ, and AIB share the similar connections and these neurons may serve as the memory neurons. To the best of our knowledge, there are not any references to mention their memory ability. ThusAIA, AIZ, and AIB only function as interneurons in our models. Target data for the two output neurons, \(V_{\text {left}}\) for DB and \(V_{\text {right}}\) for VB, are calculated according to Eqs. (13), (14), (15), and (16).

The testing results for food attraction are shown in Fig. 6. The food source is locatedat the point (0,0) with Gaussian distribution. C. elegans starts at five different locations (\(-0.11\),\(-0.07\)), (\(-0.08\),0.08), (0,\(-0.14\)), (0.04,0.14), and (0.12,\(-0.06\)) with random initial angle. C. elegans moves towards the food source and finally stops when it approaches the food after some right turns. The quantitative analysis of the trajectories in the simulation is discussed in Section 7.2 by comparing with the experiment results of Pierce-Shimomura et al. (1999) and Iino and Yoshida (2009).

Fig. 6
figure 6

Testing results for food attraction. Food source is located at the point (0,0) with Gaussian distribution. C. elegans starts at five different locations (\(-0.11\),\(-0.07\)), (\(-0.08\),0.08), (0,\(-0.14\)), (0.04,0.14), and (0.12,\(-0.06\)) with random initial angle. It moves towards the food source and finally settles down when it approaches the foodafter some right turns

5 Chemotaxis behavioral model for toxin avoidance

In this section, we explore the toxin avoidance behavior. The toxin avoidance is another kind of chemotaxis behaviorthat C. elegans will turn its direction to avoid the unpleasant chemical stimulus. Following the same procedure in Section 4, we first extract the wire diagram based on the biological neural connections. Second, SLFs for toxin avoidanceare constructed. At last, after the wire diagram is well trained, two different toxin scenarios are carried out to test the performance of the modeled C. elegans.

5.1 Wire diagram

For toxin avoidance behavior, the input neuron is ASH, which is responsible for nose touch, hyperosmolarity, and volatile repellent chemicals. The output neurons are DB for left-side and VB for right-side. Other interneurons areextracted following the same way in Section 4.1. The wire diagram for toxin avoidance is shown in Fig. 7. We obtain thewire diagram with the same interneurons compared to that for food attraction as shown in Fig. 3. However, theneuronal connections for food attraction and toxin avoidance wire diagrams are different. For example,ASH for toxin avoidance has the direct connections to command neurons AVD and AVA, but ASE for foodattraction does not. The neuron AIY functions as a memory neuron to record the previous toxin concentration \(C_{tx}(t-1)\). The toxin concentration information \(C_{tx}(t)\) is transferred to AIY from ASH by passing through ADF. Each neuron in this model is modeled by Eq. (7).

Fig. 7
figure 7

The wire diagram for toxin avoidance. The neuron ASH is the toxin sensory neuron. The neuron AIY functions as a memory neuron to record the previous toxin concentration \(C_{tx}(t-1)\). DB and VB are the left and right motor neurons. Others are hidden neurons

5.2 Switching logic functions for toxin avoidance

The SLFs for toxin avoidance should be opposite to the SLFs for food attraction. The SLFs for toxin avoidance are designed as:

$$\phi ({{C}_{tx}}(t)) ={{C}_{tx}}(t),$$
(17)
$$\begin{array}{rll}\sigma ({{C}_{tx}}(t),\Delta {{C}_{tx}}(t)) &=&{{C}_{tx}}(t)\\&&\cdot(-\tanh (\Delta {{C}_{tx}}(t)+1)-1),\end{array}$$
(18)

where \(C_{tx}(t)\) is the toxin concentration input at time t, and \(\Delta C_{tx}(t)\)= \(C_{tx}(t)-C_{tx}(t-1)\) is the temporal toxin concentration difference between two consecutive time steps. In Eq. (17),\(\phi ({{C}_{tx}}(t))\) controls the speed, and in Eq. (18) \(\sigma ({{C}_{tx}}(t),\Delta {{C}_{tx}}(t))\) controls the orientation. The plot of the SLF is shown in Fig. 8.

Fig. 8
figure 8

The SLFs for toxin avoidance. If \(C_{tx}(t) < C_{tx}(t-1)\), C. elegans moves in the correct direction and will move towards the same direction. When \(C_{tx}(t)\geq C_{tx}(t-1)\) (wrong direction), the output of \(V_{\text {right}}\) is smaller than the output of \(V_{\text {left}}\), so C. elegans turns right. When the input \(C_{tx}(t)\) is near zero, the outputs of both motor neurons approach to zero

For the speed regulation mechanism, as it is mentioned by Culotti and Russell (1978), C. elegans reversesand turns to change its direction of movement immediately when it encounters chemical repellents. For our toxin avoidance behavioral model, we assume that once C. elegans smells the toxin concentration, theavoidance behavior is activated. The stronger toxin concentration yields the faster speed and larger turningdegree of C. elegans. The avoidance behavior will last until there is no toxin concentration and then itreduces its speed to zero. In the SLFs for toxin avoidance, Eqs. (13), (14), (17), and (18), when the input\(C_{tx}(t)\) approaches to zero, the outputs \(V_{\text {left}}\) and \(V_{\text {right}}\) also approach to zero, so C. elegans reduces its speed down to zero. When \(C_{tx}(t)\) is large, \(V_{\text {left}}\) and \(V_{\text {right}}\) are also large, and therefore C. elegans maintains a high speed. For the orientation control, as shown in Fig. 9, when \(C_{tx}(t) \ge C_{tx}(t-1)\), C. elegans moves towards the wrong direction. In this case, \(\sigma ({{C}_{tx}}(t),\Delta {{C}_{tx}}(t))<0\), which yields \(V_{\text {right}}<V_{\text {left}}\), and C. elegans turnsright. When \(C_{tx}(t) < C_{tx}(t-1)\), C. elegans is in thecorrect direction. In this case \(\sigma ({{C}_{tx}}(t),\Delta {{C}_{tx}}(t))=0\) yields \(V_{\text {right}}=V_{\text {left}}\) and C. elegans goes straightly. As shown in Fig. 8, a large positive temporal concentration variation yields a large difference between left and right output neurons, which can generate the abrupt turn (\(\Omega \) turn), whereas a small positive temporal concentration variation yields a small difference between left and right output neurons, which produces the slight turn.

Fig. 9
figure 9

Movement demonstration for toxin avoidance. If \(C_{tx}(t) < C_{tx}(t-1)\), C. elegans is in the correct direction, so \(V_{\text {left}}=V_{\text {right}}\) and it goes straightly. If \(C_{tx}(t) \ge C_{tx}(t-1)\) (wrong direction), the output of \(V_{\text {right}}\) is smaller than \(V_{\text {left}}\), which makes C. elegans turn right

From the Eqs. (15) and (17), we can observe that SLFs of speed for food attraction and toxin avoidance are in anopposite manner due to the nature of tasks. For food attraction, the gradient of Eq. (15) is

$$\frac{\partial \phi ({{C}_{f}}(t))}{\partial {{C}_{f}}(t)}=-1,$$
(19)

which is negative. For toxin avoidance, the gradient of (17) is

$$\frac{\partial \phi ({{C}_{tx}}(t))}{\partial {{C}_{tx}}(t)}=1,$$
(20)

which is positive. In such circumstances, when concentration is higher, C. elegans is going to stop before food or move quickly from toxin. By comparing with Eqs. (16) and (18), SLFs of orientation have the opposite logics for foodattraction and for toxin avoidance. When concentration at time t is higher than that at the previous time \(t-1\), C. elegans should go straightly for food attraction, or turn for toxin avoidance.

5.3 Testing results

The wire diagram of toxin avoidance, as shown in Fig. 7, is trained to remember the input-output mapping for toxin avoidance (Fig. 8).

For the training data, the input data include two terms, \(C_{tx}(t)\) and \(C_{tx}(t-1)\), which range from 0 to 2 with interval 0.1. To train this model, ASH functions as the input neuron to receive the training data \(C_{tx}(t)\), and AIY is assigned to be the memory neuron to receive the training data \(C_{tx}(t-1)\). Target data for thetwo output neurons, \(V_{\text {left}}\) for DB and \(V_{\text {right}}\) for VB, are calculated by Eqs. (13), (14), (17), and (18).

After being trained by RTRL, C. elegans are tested in two different scenarios. In the first scenario, as shown in Fig. 10, four toxin resources are located at (\(-0.2\),0), (\(-0.1\),\(-0.15\)), (0,0.2), and (0.1,\(-0.1\)). C. elegans starts at three different positions (\(-0.13\),\(-0.11\)), (0.07,\(-0.1\)), (0,0.18) with head angle randomly generated. C. elegans successfully finds the zero toxin concentration places after several turns and finally stops.

Fig. 10
figure 10

Testing results for toxin avoidance. Four toxin resources are located at (\(-0.2\),0), (\(-0.1\),\(-0.15\)), (0,0.2), and (0.1,\(-0.1\)). C. elegans starts at three different positions (\(-0.13\),\(-0.11\)), (0.07,\(-0.1\)), (0,0.18) with head angle randomly. It successfully finds the zero toxin concentration places to settle down

In the second scenario, as shown in Fig. 11, twenty-five toxin sources are distributed as a \(5 \times 5\) grid. In the figure, each dot indicates a toxin source and each circle line indicates theboundary of its corresponding toxin distribution. C. elegans starts at four different positions (\(-0.04\),0.06), (0,0),(0.03,\(-0.02\)), and (0.05,0.05) with random initial head angle. It escapes the toxin successfully by a series of turns and finally stops at places without toxin concentration. From the tracks in Fig. 11, it is obvious that C. elegans escapes by passing the toxinboundary areas where the toxin gradient and magnitude are relative low. Interestingly, it seems that C. elegans has the “intelligence” to guide itself to follow the optimal route to escape.

Fig. 11
figure 11

Testing results for toxin avoidance. Twenty-five toxin resources are distributed as a \(5 \times 5\) grid. C. elegans starts at four different positions (0,0), (0.05,0.05), (0.03,\(-0.02\)), (\(-0.04\),0.06) with random initial head angle. It successfully finds the zero toxin concentration places to settle down. From thetracks it is obvious that C. elegans escapes by passing the toxin boundary areas where the toxin gradient andmagnitude are relative low

6 Integrated chemotaxis behavioral model

In previous sections we explore the chemotaxis behaviors of food attraction and toxin avoidance separately. However, in nature C. elegans produces all the chemotaxis behaviors with only one wire diagram. Thus, in this section wecombine the wire diagrams for food attraction and toxin avoidance into an integrated model. SLFs areredesigned and learned by the integrated chemotaxis behavioral model. We test C. elegans in three different scenarios and it shows good performance on finding food and avoiding toxin simultaneously with speed regulation.

6.1 Wire diagram

The wire diagram of the integrated chemotaxis behavioral model, as shown in Fig. 12, is the combination of two wire diagrams shown in Figs. 3 and 7 respectively. ASE and ASH are sensory neuronsfor food and toxin concentration respectively. DB and VB are left-side and right-side motor neurons, and the rest are hidden neurons. AIY functions as the memory neuron to record the concentration \(C_{f}(t-1)\) and \(C_{tx}(t-1)\).

Fig. 12
figure 12

The wire diagram for integrated chemotaxis behavioral model. This wire diagram is the combination of wire diagrams for food attraction and toxin avoidance. ASE is the sensory neuron for foodand ASH is the sensory neuron for toxin. DB and VB are left-side and right-side motor neurons, and the rest are hidden neurons. AIY functions as a memory neuron to record the concentration \(C_{f}(t-1)\) and \(C_{tx}(t-1)\)

It should be mentioned that all the wire diagrams obtained are simplified chemotaxis behavioral models. In other works (Gray et al. 2005; Karbowski et al. 2008) head swing neurons such as RMD, SMB, SMD, RIA, and RIB are involved. Inthis work, we focus on the relationship between the chemotaxis concentration and the outputs of motor neurons, VB andDB. The locomotion model of C. elegans is simplified into a point mass. However, in our next work that focuses on theundulatory movement of C. elegans, the neck motor neurons RMD, SMB, and SMD are involved in the neural model.

6.2 Switching logic function

For the integrated behavior model, we combine the behaviors for food attraction and toxin avoidance together and SLFs are designed as:

$${{V}_{\text{left}}(t)}=\underbrace{{{\phi }_{1}}({{C}_{f}}(t))+{{\phi }_{2}}({{C}_{tx}}(t))}_{\text{speed}},$$
(21)
$$\begin{array}{rll} {{V}_{\text{right}}(t)}&=&\underbrace{{{\phi }_{1}}({{C}_{f}}(t))+{{\phi }_{2}}({{C}_{tx}}(t))}_{\text{speed}} \\ &&+\underbrace{[{{\phi }_{1}}({{C}_{f}}(t))+{{\phi }_{2}}({{C}_{tx}}(t))]\cdot\sigma (\Delta C_{ft}(t))}_{\text{orientation}}\end{array}$$
(22)

where

$${{\phi }_{1}}({{C}_{f}}(t))=-0.5{{C}_{f}}(t)+1,$$
(23)
$${{\phi }_{2}}({{C}_{tx}}(t))=0.5{{C}_{tx}}(t),$$
(24)
$$\sigma (\Delta C_{ft}(t))=\rm{tanh} (\Delta C_{ft}(t)+1)-1,$$
(25)
$$\Delta C_{ft}(t)={{C}_{f}}(t)-{{C}_{f}}(t-1)-{{C}_{tx}}(t)+{{C}_{tx}}(t-1).$$
(26)

For the speed regulation mechanism, the speed of C. elegans is determined by both food and toxin concentrations. Theeffect of the food concentration makes C. elegans stop only when it arrives at the food source, otherwise it will cruise continually. It is in accord with the statement of reference Rankin (2005) that C. elegans spends nearly all of itstime grazing on bacterial lawns, and if there is no bacteria, it moves around the plate to search for food.The effect of the toxin concentration makes C. elegans continue moving and changing its direction as longas toxin concentration is smelled. The SLFs of the speed are shown in Fig. 13(a). In Eqs. (21) and (22), \({{\phi }_{1}}({{{C}}_{f}}(t))\) and \({{\phi }_{2}}({{{C}}_{tx}}(t))\) determine the speed. When C. elegans approaches the food source, the high input value of \({C}_{f}(t)\) yields a low output value of \({\phi }_{1}({{{{C}}}_{f}}(t))\); and when C. elegans is faraway from the toxin, the low input value of \({C}_{tx}(t)\) yields a low output value of \({\phi }_{2}({{{{C}}}_{tx}}(t))\). In this case, both the \(V_{\text {right}}(t)\) and \(V_{\text {left}}(t)\) are near zero, and the worm comes to stop. Otherwise, C. elegans will keep moving.

Fig. 13
figure 13

Plot of switching logic function for the integrated chemotaxis behavioral model. In (a), \(C_{f}(t)\) and \(C_{tx}(t)\) determine the outputs of motor neurons for speed regulation. When \(C_{f}(t)\) reaches the highest value, and \(C_{tx}(t)\) goes down to zero, both the right and left output neurons are zero, hence the worm stops. Otherwise, C. elegans will keep moving. In (b), \(\Delta C_{ft}(t)\) controls the orientation. If \(\Delta {{C}_{ft}}(t)\geq 0\), the food concentration is bigger than that at the previous time, or the toxin concentration is smaller than that at the previous time. Thus for Eq. (25), \(\sigma (\Delta C_{ft}(t))\) is near zero and C. elegans does not turn. If \(\Delta {{C}_{ft}}(t)<0\), C. elegans goes wrongly, \(\sigma (\Delta {{C}_{ft}}(t))<0\), and \(V_{\text {left}}>V_{\text {right}}\). Thus the worm turns right

For the orientation control, based on the assumption that C. elegans can only turn right or go straightly, it is adequate to add the term \(\sigma (\Delta C_{ft}(t))\) to \(V_{\text {right}}(t)\) only. In Fig. 13(b), \(\Delta {{C}_{ft}}(t)\geq 0\) means the food concentration is higher than that at the previous time, or the toxin concentration is lower than that at the previous time. In this case, for Eq. (25), \(\sigma (\Delta {{C}_{ft}}(t))\) is near zero and C. elegans does not turn. If \(\Delta {{C}_{ft}}(t)<0\), C. elegans goes wrongly, and \(\sigma (\Delta {{C}_{ft}}(t))<0\), yielding \(V_{\text {left}}>V_{\text {right}}\). Thus the worm turns right.

6.3 Testing results

The integrated chemotaxis behavioral model, as shown in Fig. 12, is trained to remember the input-output mapping (Fig. 13). The inputsof training data include \(C_f(t)\) for ASE, \(C_{tx}(t)\) for ASH, and \(C_f(t-1)-C_{tx}(t-1)\) for AIY. The range of input data is from 0 to 2 with interval 0.1. Target data for the two motor neurons, \(V_{\text {left}}\) for DB and \(V_{\text {right}}\) for VB, are calculated by Eqs. (21) and (22), respectively.

The tests are carried out in three different scenarios. In the first scenario, as shown in Fig. 14, one food is located at point (\(-0.11\),0) and one toxin is located at point (0.11,0) with slightly overlapped concentration. C. elegans starts at (0.09,0.03) where it isnear the toxin without food concentration. It escapes from toxin first, and when C. elegans detects the food concentration it moves towards to the food and finally stops.

Fig. 14
figure 14

Testing results for the integrated chemotaxis behavioral model in the first scenario. One food is located at point (\(-0.11\),0) and one toxin is located at point (0.11,0) with slightly overlapped concentration. C. elegans starts at (0.09,0.03) where it is near the toxin without food concentration. It escapes toxin firstly, and when C. elegans detects the food concentration it moves towards to the food and finally stops near it

In the second scenario, as shown in Fig. 15, one food source is located at (\(-0.03\),0) and one toxin source is located at (0.03,0) with concentrations largely overlapped. The 2D concentration distribution along x-axis is shown in Fig. 16(a). Here we assume that the direction of x-axis is the positive direction. Accordingly, the gradients of food and toxin concentrations along the positive direction are shown in Fig. 16(b). There are two points where the gradients of food and toxin concentrations are identical: \(x=-0.07\) and \(x=0.07\).The direction of C. elegans is determined by Eq. (26), which can be written as \(\Delta {{C}_{ft}}(t)=\Delta {{C}_{f}}(t)-\Delta {{C}_{tx}}(t)\), where \(\Delta {C}_{f}(t)={C}_{f}(t)-C_f(t-1)\) and \(\Delta C_{tx}(t)={C}_{tx}(t)-{{C}_{tx}}(t-1)\). As shown in Fig. 13(b), if \(\Delta C_{ft}(t)>0\) (\(\Delta C_{f}(t)>\Delta C_{tx}(t)\)), C. elegans goes straightly. Otherwise, it will turn. As shown in Fig. 16(b), along the positive direction, when \(x<-0.07\), i.e., on the left of the point P, \(\Delta C_{f}(t)>\Delta C_{tx}(t)\), resulting \(\Delta C_{ft}(t)>0\), so C. elegans will move towards the positive direction until it reaches the point P, namely, the stable equilibrium. When \(-0.07<x<0.07\), i.e., in between the points P and Q, \(\Delta C_{f}(t)<\Delta C_{tx}(t)\), resulting \(\Delta C_{ft}(t)<0\), so C. elegans will turn its direction and move towards the negative direction until it arrives at \(x=-0.07\), namely, the stable equilibrium P. When \(x>0.07\), i.e.,on the right of the point Q, \(\Delta C_{f}(t)>\Delta C_{tx}(t)\), resulting \(\Delta C_{ft}(t)>0\). C. elegans will move towards the positive direction until the toxin concentration disappears, namely,away from the unstable equilibrium Q. In conclusion, the target places of this case are the point (\(-0.07\),0) and where no toxin concentration exists on the toxin side.

Fig. 15
figure 15

Testing results for the integrated chemotaxis behavioral model in the second scenario. One food source islocated at (\(-0.03\),0) and one toxin source is located at (0.03,0) with largely overlapped concentration. When C. elegans starts from (0.08,0) with initial angle 180° (facing the toxin, shown as track A), it avoids the toxin by a series of right turnsand settles down at the place without toxin concentration. When starting from the point (0.06,\(-0.02\)) with initial angle 135° (facing the toxin, shown as track B) where the toxin and food concentration are overlapping, C. elegans by passes the toxin source and navigates itself towards the food source, and finally it settles down around the point (\(-0.07\),0). When starting from the point (\(-0.15\), \(-0.05\)) with initial angle 180° (shown as track C), C. elegans moves towards to the food and finally settles down around the point (\(-0.07\),0)

Fig. 16
figure 16

(a) 2D concentration distributions of food and toxin along x-axis. (b) The gradientsof food and toxin concentrations along the positive direction (direction of x-axis). When \(x<-0.07\), \(\Delta C_{f}(t)>\Delta C_{tx}(t)\), so \(\Delta C_{ft}(t)>0\), and C. elegans will move towards the positive direction. When \(-0.07<x<0.07\), \(\Delta C_{f}(t)<\Delta C_{tx}(t)\), so \(\Delta C_{ft}(t)<0\), and C. elegans will turn its direction and move towards the negative direction until it arrives at \(x=-0.07\). When \(x>0.07\), \(\Delta C_{f}(t)>\Delta C_{tx}(t)\), so \(\Delta C_{ft}(t)>0\), and C. elegans will move towards the positive direction. Point P is a stable equilibrium, and point Q is an unstable equilibrium

The testing results are shown in Fig. 15. When C. elegans starts from (0.08,0), i.e., on the right side of the unstable equilibrium Q, and with initial angle 180° (facing the toxin, shown as track A), where both food and toxin concentrations are present at the same time, the worm avoids the toxin by a right turn and leaves faraway from the toxin source. Finally it settles down at the place without toxin concentration. When starting from the point (0.06,\(-0.02\)), i.e., in between points Pand Q, and with initial angle 135° (facing the toxin, shown as track B) where both toxin and food concentrations exist simultaneously, C. elegans bypassesthe toxin source and navigates itself towards the food source, and finally it settles down around the stable equilibrium P at (\(-0.07\),0). When starting from the point (\(-0.15\), \(-0.05\)),i.e., on the left side of the stable equilibrium P, and with initial angle 180° (facing against the food, shown as track C), C. elegans moves towards to the food and finally settles down around the the stable equilibrium Pat (\(-0.07\),0). It can be seen that when food concentration and toxin concentration are largely overlapping, the testing results are consistent with the gradient-based analysis, namely, C. elegans is attracted towards the stable equilibrium, point P, and repelled from the unstable equilibrium, point Q.

In the last scenario, twenty-five toxin sources are distributed as a \(5\times 5\) grid. As shown in Fig. 17, black dots depict the toxin sources and circle lines are the boundaries of toxinconcentration. One food source is located at (0,0.45). C. elegans starts at three different locations, (\(-0.02\),\(-0.01\)), (0,0.02), and (0.02,\(-0.02\)) respectively, with random initial angles. All the three starting points are very near the central toxin source. From thetracks, it is obvious that C. elegans escapes from the toxin by passing the boundary areas where the toxin gradientand magnitude are relatively low. C. elegans successfully escapes from the toxin and settles down at theplaces where no toxin concentration exists (see the left and bottom tracks). Furthermore, if C. elegans smells the food concentration (see the top track), it navigates itself towards the food source and finally stops.

Fig. 17
figure 17

Testing results for the integrated behavioral model in the third scenario. Twenty-five toxin resources are distributed as a \(5 \times 5\) grid. One food source is located at (0,0.45). C. elegans starts at three different locations, (\(-0.02\),\(-0.01\)), (0,0.02), and (0.02,\(-0.02\)) respectively, with random initial angles. C. elegans successfully escapes from the toxin and settles down at theplaces where no toxin concentration exists (see the left and bottom tracks). Furthermore, if C. elegans smells thefood concentration (see the top track), it navigates itself towards the food source and finally stops. It is obviousthat C. elegans escape from the toxin by passing the boundary areas where the toxin gradient and magnitude are relatively low

From the test results, we can conclude that the integrated chemotaxis behavioral model can well performs the chemotaxis behaviors on finding food and avoiding toxin simultaneously with speed regulation. Furthermore,it also verifies that when SLFs are learned, C. elegans can perform the chemotaxis behaviors in different environments.

7 Analysis of the resultant wire diagrams

7.1 Wire diagram analysis

In our work, we obtain thirty wire diagrams for each chemotaxis behavioral model after providing random initial weights and training. The successful training rates are about 60 % for both food attraction and for toxin avoidancebehavioral models, and about 47 % for the integrated chemotaxis behavioral model. When the learned behaviors becomemore sophisticated, the training would be more difficult. Furthermore, we also optimized the wire diagrams by Genetic Algorithm and obtained the same results.

For the network similarity, we first cluster the thirty wire diagrams in each behavioral model by using k-means algorithm, and then verify the clustering results by Analysis of Variance (ANOVA). For each kind ofbehavioral model, we calculate the summation of absolute weight values of every wire diagram, denoted as \(Q_{i}\), \(i=1,...,N_{m}\) (\(N_{m}=30\)), and then apply k-means algorithm to cluster these wire diagrams according to the value of \(Q_i\). The results are shown in Fig. 18. As shown in Fig. 18(a), each dot represents its corresponding wire diagram for food attractionbehavioral model, and the value in x-axis denotes the summation of the absolute weight values of its corresponding wirediagram. The asterisks represent the clustering centers. These dots are clustered into three groups by k-means algorithm.The inter-group mean squared error (MSE) is 1.60 for Groups 1, 2, and 3. The intra-group MSEs are 0.23 for Group 1,0.32 for Group 2, and 0.19 for Group 3. The clustering result is analyzed by ANOVA. By setting the significance level \(\alpha =0.05\) in ANOVA analysis, weobtain the observed value \(F=559.71\) and the critical value \(F_{\text {Critical}}=3.35\). \(F>F_{\text {Critical}}\) denotes the three groups are significantly different, which means the clustering is effective. As shown in Fig. 18(b), the dots denote the wire diagrams for toxin avoidance behavioral model. These dots can be clustered into threegroups and the asterisks represent the clustering centers. The inter-group MSE is 1.61 for Groups 1, 2,and 3. The intra-group MSEs are 0.17 for Group 1, 0.16 for Group 2, and 0.10 for Group 3. By setting \(\alpha =0.05\), we obtain \(F=1450.76\) and \(F_{\text {Critical}}=3.35\). \(F>F_{\text {Critical}}\) denotes the effectiveness of this clustering. As shown in Fig. 18(c), the dots denote the wire diagrams for integrated behavioral model. These dots are difficult to be clustered by k-means algorithm, so we cluster them to be one group.Within the group, the intra-group MSE is 0.13. From these results we can conclude that the solution is notunique for each behavioral model. The wire diagrams in the same group have small MSE, which are lessthan 0.32, and the wire diagrams in different groups have relatively larger MSE, which are greater than 1.60.

Fig. 18
figure 18

The similarity analysis of the resultant wire diagrams. Every dot denotes a wire diagram and the valuein x-axis denotes the summation of the absolute weight values of its corresponding wire diagram. The asterisks represent the clustering centers. (a) Thirty wire diagrams for the food attraction behavioral model are clusteredinto three groups by k-means algorithm. (b) Thirty wire diagrams for the toxin avoidance behavioral model are clustered into three groups by k-means algorithm. (c) Thirty wire diagrams for the integrated behavioral model are clustered into the same group

Furthermore, following the method of Dunn (2006), we first find out the “all-off” neurons that are inactive and the“all-on” neurons that are saturated active. Next, we remove these “all-off” neurons from the wire diagrams and move these“all-on” neurons to their downstream neurons as bias. In this way, the wire diagrams are simplified and the relevantnetworks are obtained. For the food attraction behavioral model, the “all-off” neurons are PVP, ADF, RIF, and AVD,because all weights of these neurons are small and near to zero. The wire diagrams without these neurons can still performthe behavior for food attraction well. The “all-on” neurons for the food attraction behavioral model are DVA and AVB. After we move these neurons to their downstream neurons, the resultant wire diagram is shown in Fig. 19(a). As shown in Fig. 19(a), there are six interneurons instead of twelve interneurons after simplifying. By following the same way, the resultant wire diagram for toxin avoidance behavioral model is shown in Fig. 19(b).The “all-off” neurons are PVP and RIF that are removed from wire diagram. The “all-on” neurons areDVA, AVD, and AVB. After simplification, we can see that there are seven interneurons instead of thirteeninterneurons. By comparing Fig. 19(a) and (b), one additional neuron ADF exists in the wire diagram of toxinavoidance behavior model. This is because there is no direct connection from sensory neuron ASH to memoryneuron AIY biologically, and the function of ADF here is to transmit the signal from ASH to AIY. For theintegrated behavioral model, the “all-off” neuron is PVP that can be removed from the wire diagram. However, we haven’t found any neurons that can serve as the “all-on” neurons since all neurons are not saturated activated.

Fig. 19
figure 19

(a) Resultant wire diagram for food attraction behavioral model. After the “all-off” neurons are removedand the “all-on” neurons are moved to downstream neurons, the simplified network contains six interneuronsinstead of twelve. (b) Resultant wire diagram for toxin avoidance behavioral model. After the “all-off” neuronsare removed and the “all-on” neurons are moved to downstream neurons, the simplified network contains seven interneurons instead of thirteen

By comparing with another similar work (Ferrée and Lockery 1999) that provides a model for food attraction, ourmodel contains three more interneurons. This is because we not only consider the turning mechanism, as Ferrée and Lockery (1999) did, but also incorporate the speed regulation mechanism. Moreover, the integrated behavioral model needseleven interneurons (after PVP is removed). If we remove one or more interneurons, till now we have notobtained any satisfactory wire diagrams after training. The reason that more interneurons are needed in our models is aroused by the complexity of our learning task: finding food, avoiding toxin, and regulating speed synchronously.

7.2 Behaviors analysis

In this subsection we provide the quantitative analysis of the trajectories of our models by comparing with experiment results. To the best of our knowledge, the references about the quantitative analysis of the trajectories fortoxin avoidance behaviors and integrated behaviors (for both food and toxin) are limited. Thus in thissubsection we only provide the analysis of the food attraction behavioral model by comparing with th eexperiment results of wild type C. elegans provided by Pierce-Shimomura et al. (1999) and Iino and Yoshida (2009).

We analyze the relationships between (1) speed and concentration, (2) turning rate and concentration, (3) turning rate and change of concentration (\(dC(t)/dt\)), and (4) probability of turning and \(dC(t)/dt\) by following the methods in Pierce-Shimomura et al. (1999) and Iino and Yoshida (2009). The simulation time is 1500 s,and we record the location, concentration, and direction per second. Hence, for each relationship analysis, there are 1500tracking data, and these data are classified into 15 groups. Every group contains 100 data and is represented as a dot in Fig. 20. The values of each dot in x-axis and y-axis are calculated by taking the average of the 100 data inthe same group. The error bar for each dot indicates the standard deviation of the data within the samegroup. The solid lines in each sub-figure are the best-fitting quadratic functions of their corresponding dots.The dotted lines represent the experiment results of Pierce-Shimomura et al. (1999) and Iino and Yoshida (2009).

In this work, Least Square Method is adopted to fit these dots, as shown in Fig. 20. The quality of fitting is analyzed by using \({R}^2\) method Steel and Torrie (1960). \({R}^2\) is defined as \({R}^2=1-S{{S}_{\text {err}}}/S{{S}_{\text {tot}}}\), where \(S{{S}_{\text {tot}}}=\sum \nolimits _{i=1}^{N}{{{({{y}_{i}}-\overline {y})}^{2}}}\) and \(S{{S}_{\text {err}}}=\sum \nolimits _{i=1}^{N}{{{({{y}_{i}}-{{f}_{i}})}^{2}}}\). \(y_{i}\) (\(i=1, \ldots , N\)) are the testing results that should be fitted, and each testing result has an associated experiment result \(f_{i}\) (\(i=1, \ldots , N\)). N is the number ofthe testing results, and \(\overline {y}\) is the average value of \(y_{i}\) (\(i=1, \ldots , N\)). The value of \({R}^2\) is equal to or less than 1, which is used to describe how well a regression curve fits the testing results. An \({R}^2\) near 1 indicates that the regression curve fits the testing results well, while the more negative value of \({R}^2\) indicates the worse of fitting. In this work, we analyze (1) the degree of the curves to fit the dots (testing results), measured by \({R}_{\text {dot}}^{2}\), and (2) the degree of the curves to fit the experiment results, measured by \({R}_{\text {ep}}^{2}\).

Fig. 20
figure 20

Statistical analysis of trajectories for food attraction behavior model. (a) The relationship between speed and concentration. The speed is inverse proportion to the concentration for our model (solid line). (b) The relationship between turning rate and concentration. There is no obvious relationshipbetween the turning rate and the the food concentration. (c) The relationship between turning rate and \(dC(t)/dt\). The turning rate is inverse proportion to \(dC(t)/dt\), and once \(dC(t)/dt\) is greater than zero, the turning rate approaches zero. (d) The relationship between probability of turning and \(dC(t)/dt\). This relation can be approximated by formula (solid line) \(y=0.023/(a+e^{bx+d})+c\) by following Iino and Yoshida (2009). The dotted line is the experiment result of Iino and Yoshida (2009). The probability of turning is higher when \(dC(t)/dt\) is more negative

In Fig. 20(a), the fitted polynomial equation (solid line) is \(y=-0.073x^2+0.0287x+0.224\) (\({R}_{\text {dot}}^{2}=1.00\), \({R}_{\text {ep}}^{2}=-0.92\)). We can observe that the speed is inversely proportional to the concentration. However, our result is different from the experiment data of Pierce-Shimomura et al. (1999) (dotted line), which concludes that the speed of C. elegans is weakly dependent onthe food concentration. The reason for this difference is that in this work we assume C. elegans will reduce its speed by following the increasing of food concentration.

Remark 2

It should be pointed out that till now there are two opposite point of views about the relationship between food concentration and speed of C. elegans. One opinion is that the speed of C. elegans is constant (Ferrée and Lockery 1999; Iino and Yoshida 2009), and the other one is that C. elegans will reduce its speed when encountering the food (Leung et al. 2008). In our previous work (Xu and Deng 2010), we have investigated the chemotaxis behaviorof C. elegans by assuming its speed to be a constant and obtained the similar results as Pierce-Shimomura et al. (1999). To the best of our knowledge, the actual causation of the speed reducing of C. elegans is still unknown. Thus in this work we assume its speed is related to the concentration.

As shown in Fig. 20(b), the fitted polynomial equation (solid line) is \(y=-0.5959x+15.7926\) (\({R}_{\text {dot}}^{2}=0.40\),\({R}_{\text {ep}}^{2}=-25.58\)). We can observe that the turning rate weakly depends on the food concentration, and it is similar to the experiment result of Pierce-Shimomura et al. (1999) (dotted line). The relationship between turning rate and \(dC(t)/dt\) is shown in Fig. 20 (c). The fitted polynomial equation (solid line) is \(y=27291x^3+1953x^2-236x+6\) (\({R}_{\text {dot}}^{2}=1.00\), \({R}_{\text {ep}}^{2}=-2.18\)). In this figure, the larger negative value of \(dC(t)/dt\) yields the larger magnitude of turning rate, and once \(dC(t)/dt\) is positive, the turning rate reduces to zero. This result is similar to the experiment data of Iino and Yoshida (2009) (dotted line). At last, we follow the same way of Iino and Yoshida (2009) to analyze the relationship between probability of turning and \(dC(t)/dt\). As shown in Fig. 20(d), these dotscan be approximated by formula \(y=0.023/(a+e^{bx+d})+c\), where y is the probability of turning, and x is the change of concentration \(dC(t)/dt\), and a, b, c, d are constants. For our case, the values of these parameters are \(a=0.3448\), \(b=300\),\(c=0\), and \(d=-0.8\). The fitted formula is plotted asthe solid line in Fig. 20(d), with \({R}_{\text {dot}}^{2}=0.99\) and \({R}_{\text {ep}}^{2}=0.67\). The experiment data of Iino and Yoshida (2009) is plotted as the dotted line in Fig. 20(d). The parameters obtained by Iino and Yoshida (2009) are \(a=0.40\), \(b=140\), \(c=0.0033\), and \(d=0\). From both our result and the experiment result, we can observe that they share the same shape and the probability of turning is higher when \(dC(t)/dt\) is more negative.

Above all, except for the first relationship (speed and concentration), other three relationships are in accord with the experiment results. Furthermore, we can explain the abrupt turn and continue turn of our models through Fig. 20(c) and (d). More negative values in \(dC(t)/dt\) yield larger magnitudes of the turning rate and higher probability of turning, which lead to the abrupt turn. In contrast, small negative values of \(dC(t)/dt\) only yield small magnitudes of the turning rate and low probability of turning, which lead to the slight and continual turn. Additionally, if \(dC(t)/dt\) is positive, the turning rate and the probability of turning will approach zero, which make C. elegans move straightly.

7.3 Performance with noises

This subsection discusses the robustness of the DNN-based behavioral models in the presence of noises. We test the performance of our behavioral models by adding the external noise and internal noise. For the external noise, we add the randomly generated noise with the range [0, 0.02] and [0, 0.2] (1 and 10 % of the largest magnitude of input concentration) to concentration signals. Due to the page limitation, we only present the results for food attraction. The result is shown in Fig. 21. It can be seen that, with the external noise, there are more turns appearing and the tracks areless smooth than that without the external noise. However, the worm can still reach the final destination correctly.

Fig. 21
figure 21

Testing results by adding the external noise. The test is based on the wire diagram for food attraction. With the external noise, there are more turns produced and the locomotion is less smooth as the scenario withoutthe external noise. However, the worm can still reach the final destination correctly

Next we add the internal noise to the wire diagram for food attraction. By following the method in Jim et al. (1996), we add the synaptic noise (one kind of the internal noise) tothe wire diagram. The testing result is shown in Fig. 22. The internal noise range is between \(-0.003\) and 0.003 (about 1 % of the average weight value), and between \(-0.03\) and 0.03 (about 10 % of the average weight value). As shown in Fig. 22, C. elegans without the internal noise can guide itself towards the food source. When the noise range is between \(-0.003\) and 0.003, C. elegans can still move towards the food source. When the noise range is between \(-0.03\) and 0.03, C. elegans circles around the starting place. In comparison, DNN-based models are more robust for the external noise.

Fig. 22
figure 22

Testing results by adding the internal noise. Without the internal noise C. elegans can guide itself towards the food source. When the noise is between \(-0.003\) and 0.003, C. elegans can still move towards the food source. When the noise is between \(-0.03\) and 0.03, C. elegans circles around the starting place

Furthermore, we quantitatively analyze the trajectories that are affected by the external and internal noises. By following the methods in Pierce-Shimomura et al. (1999) and Iino and Yoshida (2009), we analyze the relationship between (1) turning rate and concentration, and (2) probability of turning and \(dC(t)/dt\) as what we have done in Section 7.2.

The relationship between turning rate and concentration are shown in Fig. 23(a). The results with the external noise (solidline: \(y=-0.5959x+15.7926\), \({R}_{\text {dot}}^{2}=0.40\), \({R}_{\text {ep}}^{2}=-25.58\)) and with the internal noise (dashed line: \(y=-0.3657x+1.0066\), \({R}_{\text {dot}}^{2}=0.24\), \({R}_{\text {ep}}^{2}=-4278.3\)) indicate that the turning rate weakly depends on the concentration, which are the same as the conclusion of Pierce-Shimomura et al. (1999). As shown in Fig. 23(a), we can observe that the fitting result for experimental data with the internal noise (dashed line, \({R}_{\text {ep}}^{2}=-4278.3\)) is much worse than that with the external noise (solid line, \({R}_{\text {ep}}^{2}=-25.58\)). This poor fitting is due to the internal noise that greatly affects the locomotion behaviors of our models.

Fig. 23
figure 23

Statistical analysis for food attraction behavior with noises. (a) The relationship between turning rateand concentration with the external and internal noises. (b) The relationship between probability of turning and \(dC(t)/dt\) with the external and internal noises. From two subfigures, we can observe that the fitting results for experimentaldata with the internal noise (dashed lines) are much worse than that with the external noise (solid lines). Thepoor fitting is due to the internal noise that greatly affects the locomotion behaviors of our models

The relationship between probability of turning and \(dC(t)/dt\) is shown in Fig. 23(b). The result with the external noise can be approximated by formula \(y=0.023/(a+e^{bx+d})+c\), where \(a=0.3448\), \(b=200\), \(c=0\), and \(d=-0.3\), shown as the solid line. \({R}_{\text {dot}}^{2}=0.99\) and \({R}_{\text {ep}}^{2}=0.89\) for this fitting. However, for the result with the internal noise (asterisks), the relationship between probability of turning and \(dC(t)/dt\) is not apparent, and it cannot be approximated by the formula \(y=0.023/(a+e^{bx+d})+c\). Instead, we approximate these data by \(y=0.1149x+0.0598\), but the fitting is poor, since \({R}_{\text {dot}}^{2}=0.05\) and \({R}_{\text {ep}}^{2}=-782.83\). The poor fitting is also due to the internal noise that greatly affects the locomotion behaviors of our models. Additionally, it is interesting to note that the result with the internal noise is similar to the results shown as Fig. 7(E) and (I) in Iino and Yoshida (2009), which are the experiment results of C. elegans with neurons ablation.

From the analysis results, the behavior of our model with the external noise is similar to the behavior of wild-type C. elegans, whereas the behavior of the model with the internal noise is similar to the behavior of C. elegans with neuron ablation.

8 Conclusion

In this paper, the chemotaxis behaviors of C. elegans for food attraction and toxin avoidance are investigated. First, three chemotaxis behavioral models are constructed from chemosensory neurons to motor neurons by extracting directlyfrom the biological wire diagram. These chemotaxis behavioral models are approximated by DNN, and each neuron isdescribed as a non-linear active function. Second, we design the kinematic model to describe C. elegans locomotionbehaviors, that is, turning and speed regulation. Third, a set of switching logic functions are constructed to represent thechemotaxis behaviors of food attraction, toxin avoidance, integrated behaviors, as well as speed regulation. All these switching logic functions can be learned by DNN models with RTRL. The testing results verify that these chemotaxis behavioral models can well perform the complex chemotaxis behaviors in different circumstances, and their behaviors are similar to the real C. elegans by comparing with the experimental data.