Vision-based route following by an embodied insect-inspired sparse
  neural network
We compared the efficiency of the FlyHash model, an insect-inspired sparse
neural network (Dasgupta et al., 2017), to similar but non-sparse models in an
embodied navigation task. This requires a model to control steering by
comparing current visual inputs to memories stored along a training route. We
concluded the FlyHash model is more efficient than others, especially in terms
of data encoding.
Lu Yihe, Rana Alkhoury Maroun, Barbara Webb
# Vision-based route following by an embodied insect-inspired sparse neural network

###### Abstract

We compared the efficiency of the FlyHash model, an insect-inspired sparse neural network (Dasgupta et al., 2017), to similar but non-sparse models in an embodied navigation task. This requires a model to control steering by comparing current visual inputs to memories stored along a training route. We concluded the FlyHash model is more efficient than others, especially in terms of data encoding.

## 1 Introduction

The ability of animals to follow a familiar route is one of their critical navigation skills, which enables them to forage, to escape, to home, or to migrate, without exploring unknown, potentially dangerous, territories. Despite their tiny brains, desert ants are capable of vision-based route following. Based on a brain structure, called mushroom body (MB), which is common across many insect species, Ardin et al. (2016) developed a computational model, which can learn a training route in a one-shot manner, and subsequently follow the route reliably. This MB-based model is fundamentally a sparse, shallow neural network performing unsupervised learning of retinotopic images. After training, it succeeds in route following by selecting the direction associated with the most familiar visual input (Figure 1A).

Inspired by the same insect MB structure, Dasgupta et al. (2017) proposes the FlyHash model, which performs locality-sensitive hashing (LSH). In contrast to classical hashing which aims to minimise encoding duplication amongst inputs (even if two inputs are similar), LSH algorithms assign similar hashes to similar inputs to support efficient similarity search in large databases by approximating nearest neighbour search (Andoni & Indyk, 2008). Since typical LSH hashes have smaller dimensionality than their inputs, LSH can be considered as a dimensionality reduction technique. Unlike other techniques that exploit data extensively, e.g., to train an autoencoder, to compute orthonormal basis in principle component analysis, before they can be used for dimensionality reduction, LSH algorithms take advantage of randomly initialised functions to encode inputs as hashes. Typically, such encoding functions stay unchanged and data-independent after initialisation.

The FlyHash model effectively formalises the visual encoding process previously used in the MB-based route following model, as the same neural network is considered (Figure 1B). A sensory signal received by the input layer, composed of projection neurons (PNs), is encoded as a hash, represented by binarised activation of Kenyon cells (KCs). Two features of this MB-inspired neural network make the FlyHash model distinct from conventional LSH algorithms. Firstly, an input is encoded as a higher-dimensional sparse hash, Secondly, the PN-KC connectivity, defining the hash function, is sparse and binary.

Since it is beneficial for an intelligent agent, either biological or artificial, to encode and store memory efficiently and effectively for visual recognition of a familiar route, it might seem the smaller hash produced by a conventional LSH technique would be more appropriate for such tasks. Nevertheless, the FlyHash model suggests an alternative, seemingly counter-intuitive solution, which appears to be what is used by the real insect MB. Therefore, we deployed the FlyHash model on a virtual robot in a realistic simulation environment, along with two alternative encoding algorithms, in order to compare their model efficiency in a task-relevant manner.
## 2 Methods

### Embodied models

In this manuscript the embodied models are composed of 3 components, a data encoder, a memory storage, and a steering controller (Figure 1A). As we compare only the models for data encoding, while keeping the other 2 components identical, we use the same name for an embodied robot model and the model for date encoding deployed on the robot.

### Models for data encoding

We consider 3 single-layer neural network models (same or similar to Figure 1B) for data encoding, and their encoding functions can be formulated as,

\[\mathbf{y}=f_{\mathbf{W}}(\mathbf{x})=f(\mathbf{W}\cdot\mathbf{x}), \tag{1}\]

where \(\mathbf{x}\) denotes an input vector of length \(N_{\text{PN}}\), and \(\mathbf{y}\) the encoded output of dimension \(N_{\text{KC}}\). Note that the activation function \(f\), the connection matrix \(\mathbf{W}\) and the encoding matrix \(f_{\mathbf{W}}(\mathbf{x})\) are model specific, but not plastic.

**The FlyHash model** is characterised by its sparse and binary \(\mathbf{W}\) forming an expansion structure, i.e., \(N_{\text{PN}}<N_{\text{KC}}\)(Dasgupta et al., 2017). \(\mathbf{W}\) is initialised by randomly generating its weights independently and identically from a Bernoulli distribution, \(W_{ij}\sim\mathcal{B}(\theta)\), where \(i\in\{1,2,\ldots,N_{\text{PN}}\},\ j\in\{1,2,\ldots,N_{\text{KC}}\}\), and \(\theta\in(0,1)\) controls the sparsity of \(\mathbf{W}\). \(f\) performs \(k\)-winners-take-all (\(k\)-WTA), which binarises \(\mathbf{W}\cdot\mathbf{x}\), and produces \(\mathbf{y}\) of sparsity, \(\kappa=k/N_{\text{KC}}\in(0,1)\).

**The conventional LSH model** typically uses dense and non-binary \(\mathbf{W}\)(Indyk and Motwani, 1998). It is initialised by randomly generating its weights independently and identically from a standard Gaussian distribution, \(W_{ij}\sim\mathcal{N}(0;1)\). \(f\) is essentially the Heaviside step function. Consequently, conventional LSH hashes are binary but not sparse (\(\kappa=0.5\) on average).

**The perfect memory model** does not encode inputs. Instead, vertical inputs are stored in training sessions, and evaluated in tests, i.e., \(\mathbf{y}=\mathbf{x}\). For consistency, we can still define an identity operator, \(f_{\mathbf{W}}=\mathbf{I}\), to be the model's encoding function. As in Ardin et al. (2016), the perfect memory model serves as a benchmark model in the route following task.

Figure 1: A: A diagram of an embodied model for vision-based route following. Visual memory is stored only in training sessions, and retrieved for novelty evaluation only in tests. **B**: An insect mushroom body (MB)-inspired neural network. The projection neurons (PNs) receive sensory inputs, and pass them onto the Kenyon cells (KC) for data encoding. In the real MB structure, and typically in the FlyHash model, the number of KCs is larger than the number of PNs, i.e., \(N_{\text{KC}}>N_{\text{PN}}\), and their connectivity is sparse, as is the proportion of KCs activated for encoding. Here, we also explore dense connectivity and non-sparse coding.
### Memory storage and novelty evaluation

While the perfect memory model simply stores visual inputs without any encoding, both the FlyHash model and the conventional LSH model store hashes only. Consequently, to evaluate visual novelty \(d\), the dissimilarity metric \(D\) is either the Hamming distance for binary hashes, or the Euclidean distance for images. Since there are multiple memory items stored from a training session, the visual novelty of an input is computed as

\[d(\mathbf{x})=\min_{\mathbf{y}\in\mathbb{M}}D\left(f_{\mathbf{W}}(\mathbf{x}),\mathbf{y}\right), \tag{2}\]

where \(\mathbb{M}\) is the set of all stored memory items. According to the theory of LSH, two sufficiently similar images should share the same hash, given the same \(f_{\mathbf{W}}\).

The same number of memory items is considered for the 3 models, so that differences in their behaviour and performance are determined mainly by the quality of memory encoding, and their model size only by the size of individual memory items.

### Insect-inspired model for autonomous robot steering

Using a well-established insect central complex model (Stone et al., 2017), which accounts for insect steering (and other navigation skills) by an anatomically realistic neural network, Wystrach et al. (2020) shows that insect locomotion can be robustly stabilised to follow straight trajectories. The key idea is that novelty evaluation (treated as an idealised function in Wystrach et al. (2020)) occurs in a pair of MB structures with their inputs lateralised to left and right respectively, thus their relative outputs inform the central complex model of the correct turning direction to bring the insect back in line with the route.

Here we use a functionally similar but structurally simpler motor controller for autonomous robot steering, which modulates the locomotion direction based on realistic lateralised visual inputs (see Section 3.1 for our implementation). Specifically, a data encoding model stores visual memory in training sessions, and at any moment of autonomous control it computes left and right visual novelty \(d_{\text{L}}\) and \(d_{\text{R}}\) of left and right visual inputs by Equation (2). The motor controller then determines the robot's angular speed \(\omega\) according to the novelty difference. Specifically,

\[\omega=\alpha\cdot\frac{d_{\text{L}}-d_{\text{R}}}{d_{\text{L}}+d_{\text{R}}}, \tag{3}\]

where \(\alpha>0\) is a predetermined constant. The normalisation term \(d_{\text{L}}+d_{\text{R}}\) is used to remove the effect of the number of learned views.

## 3 Experiment

### Simulation environment: iGibson

The simulated experiments were conducted in iGibson, an environment offering realistic visual rendering and physics simulation (Shen et al., 2021). Our models were deployed on the two wheeled Freight robot, which was running in the Rs_int scene (Figure 2A). While there is built-in noise in the simulated physics of iGibson, its default value caused negligible effects on our simulations.

Raw image were taken by the RGB-D camera on the robot was downsampled to the size of \(33\times 33\) pixels, transformed to greyscale by the standard colour converting method from the OpenCV library, and blurred by averaging pixels in every \(7\times 7\)-sized boxes. The depth information was discarded. We found empirically that such grey and small (but not too small) images were sufficient for our models to achieve good performance, while permitting faster and cheaper simulations. Such low resolution vision is also consistent with insect compound eye optics.

The image was cropped into left, middle and right visual fields (Figure 2B). The sizes of the 3 fields were identically \(22\times 33\) pixels. The middle field was used as the input to be stored in visual memory during training. The left and the right fields were used as inputs in test sessions for computing visual novelty, as described in Section 2.4.

The robot was controlled by commands in terms of linear speed \(v\) and angular speed \(\omega\) of its wheel joints. While \(v\) and \(\omega\) was manually specified in training sessions, \(\omega\) was determined by our models
autonomously using Equation (3) with \(\alpha=1\) in tests. For simplicity, \(v\) in the training and the test sessions were set to be constants, \(v_{\text{train}}=0.5\) and \(v_{\text{test}}=0.2\).1 Since the robot deviated more from the training route when it moved at higher speeds, we set \(v_{\text{test}}=0.2\) to ensure that the model performance depends only on the effectiveness of the data encoding.

Footnote 1: We note that the unit of the robot’s linear speed (omitted elsewhere for brevity) is \(2\pi\times 0.0613\approx 0.3852\) meter per second, as the robot’s wheel is \(0.0613\) meter in radius.

### Model specification

The number of PNs was the same as the number of pixels, i.e., \(N_{\text{PN}}=726\), and the values in an input vector \(\mathbf{x}\) were simply the greyscale values of the pixels. We varied the number of KCs, i.e., the hash length \(N_{\text{KC}}\), to compare models of different sizes (summarised in Table 1), because the overall model size is asymptotically dominated by \(N_{\text{KC}}\), as a model stores more memory items \(\mathbf{y}\),.

In the FlyHash model, the PN-KC connectivity matrix \(\mathbf{W}\) was sparse with \(\theta=10/N_{\text{PN}}\); on average a KC was connected to \(10\) PNs. We consider 3 sparsity levels for \(\mathbf{y}\), \(\kappa=0.05,0.1\) and \(0.5\). Note that the model is biologically realistic when \(\theta=10/N_{\text{PN}}\) and \(\kappa=0.05\) or \(0.1\)(Lin et al., 2014). When a hash \(\kappa=0.5\), \(\mathbf{y}\) was not sparse, but as dense as that in the conventional LSH model.

In \(\mathbf{W}\) and \(\mathbf{y}\), each binary element was assumed to occupy 1 bit, a greyscale value 8 bits, and a real number 64 bits.2

\begin{table}
\begin{tabular}{c l l l l}  & & \multicolumn{2}{c}{**FlyHash**} & \multicolumn{2}{c}{**conventional LSH**} & \multicolumn{2}{c}{**perfect memory**} \\ \hline \multirow{2}{*}{\(\mathbf{W}\)} & data type & binary & real (float) & N/A \\  & dimension & \(N_{\text{PN}}\times N_{\text{KC}}\) (sparse) & \(N_{\text{PN}}\times N_{\text{KC}}\) (all-to-all) & N/A \\  & **size** (bit) & \(N_{\text{PN}}\times N_{\text{KC}}\) & \(64\times N_{\text{PN}}\times N_{\text{KC}}\) & \(0\) \\ \hline \multirow{2}{*}{\(\mathbf{y}\)} & data type & binary & binary & greyscale (uint8) \\  & dimension & \(N_{\text{KC}}\) (sparse) & \(N_{\text{KC}}\) (dense) & \(N_{\text{PN}}\) (dense) \\  & **size** (bit) & \(N_{\text{KC}}\) & \(N_{\text{KC}}\) & \(8\times N_{\text{PN}}\) \\ \hline \end{tabular}
\end{table}
Table 1: Model comparison in terms of data storage size

Figure 2: Snapshots of the Freight robot running in the Rs_int scene. **A**: A bird’s-eyed view. **B**: A raw image taken by the robot camera. Visual inputs from the middle field (bounded by the red, solid lines) were stored by the models, visual inputs from the left field (bound by the green, dotted lines) and the right field (bounded by the blue, dashed lines) were used for computing visual novelty.
### Task: route following

An experimental trial was composed of a training session and a test session, and all trials were independent from one another. The robot was trained under manual control along a predetermined route, which was designed arbitrarily by the authors with the only constraint that no collisions were to occur in training sessions. 25 images along the route were taken every 0.5 seconds (in simulation time), and stored by the model.

In the subsequent test session, the robot started from the same position, heading the same direction, as in the training session, but was now under full control of the model. The goal was to follow the training route as far as possible. Note that a collision event could and did occur under autonomous control in a trial as the result of poor memory encoding, and would be severely detrimental to the overall route following performance.

## 4 Results

### Model comparison: route following performance

We first checked the perfect memory model, which could reliably achieve one-shot vision-based route following. For instance, its sample trajectories from 10 trials overlay on one another in Figure 3A (labelled 'No KC').

It is clear in Figure 3A that the length of has  had a significant impact on the route following behaviour of the FlyHash model, To quantify such results, we measured the final distance between the final positions of the training and the test trajectories in individual trials, and considered a trial successful if the final distance was less than  meters. We consider this criterion a reasonable proxy measure for the overall route following performance, because the final positions either clustered near that of the training route when the route was followed, or distributed widely when the robot deviated too much and became lost (Figure 3B).

While the perfect memory model reached perfect performance effectively with 726 8-bit KCs (i.e., \(5808\) bits in total), the conventional LSH model and the FlyHash model with dense hashes (\(\kappa=0.5\)) required \(16000\) binary KCs, and the FlyHash models with biologically realistic, sparse hashes (\(\kappa=0.05\) and \(0.1\)) \(32000\) binary KCs, to achieve the same (Figure 4A). If \(10\%\) failure was acceptable,

Figure 3: Route following behaviour of the FlyHash model with hash sparsity, \(\kappa=0.1\). **A**: Sample trajectories of 10 trials for different (coloured). In the case of no KC, the perfect memory model was used instead. **B**: Final positions of 100 trials. All training routes (in black) started at the same position, \((x,y)=(-0.20,1.00)\), overlaid on one another due to negligible simulation noise, and ended at the same position, approximately \((x,y)=(-3.07,-0.72)\). The results of the conventional LSH model were qualitatively similar, and the plot is thus omitted. Note that it was impossible for the robot to take a shortcut between the start and the final positions due to obstacles. A video demo of the embodied perfect memory model can be found at [https://youtu.be/EdaQrmlruQQ](https://youtu.be/EdaQrmlruQQ).
the models with sparse hashes would require only \(8000\) KCs, and those with dense hashes \(4000\) KCs, which were more comparable to the perfect memory model in terms of the size of individual memory items.

The performance was reduced more as \(N_{\text{KC}}\) decreased, probably because a smaller \(N_{\text{KC}}\) was more likely to introduce hash collisions for dissimilar inputs (violating the principle of LSH), producing ill-computed visual novelty that disrupted the route following behaviour. The performance deterioration seemed relatively severe for the FlyHash model with the sparsest hashes (\(\kappa=0.05\)) for an intermediate number of KCs (\(2000\leq N_{\text{KC}}\leq 8000\)).

Interestingly, while the conventional LSH model was slightly more advantageous than the FlyHash model with \(\kappa=0.5\) for \(N_{\text{KC}}\geq 4000\), it was outperformed by the FlyHash model with a performance gap up to \(10\%\) when \(N_{\text{KC}}\) was smaller.

### Model comparison: model size and run-time cost

The above observation of the FlyHash model is particularly intriguing to us, because using dense hashes, rather than sparse encoding as in real insect MBs, yielded the best performance.

We note that it is possible to compress the sparse hashes, but not the dense ones, in a lossless manner by exploiting their sparsity. According to Shannon's source coding theorem, the lower bound of the code length for compression is determined by the entropy of the source code,

\[H(\text{y})=-\sum_{i}p_{i}\log p_{i}, \tag{4}\]

where each bit y in a sparse hash in the FlyHash model followed a Bernoulli distribution, \(\text{y}\sim\mathcal{B}(\kappa)\). Therefore, a sparse hash with \(\kappa=0.1\) or \(0.05\) could be compressed in lossless manner at most to approximately \(0.4690N_{\text{KC}}\) or \(0.2864N_{\text{KC}}\) bits, respectively, whereas the hashes in the FlyHash model with \(\kappa=0.5\) or the conventional LSH model could not be losslessly compressed. As a result, despite different \(\kappa\), the FlyHash model could achieve a performance level similar to the conventional LSH model with comparable memory sizes (Figure 4B). Considering additionally that its \(\mathbf{W}\) was also sparse and binary (see Table 1 for detailed comparison), the FlyHash model could be more efficient than the conventional LSH model in terms of overall model size.

The sparse and binary \(\mathbf{W}\) further implies that fewer run-time operations were required (Table 2). To compare the encoding costs of the FlyHash model and the conventional LSH model, it is straightforward to refer to the time complexity of the best sorting algorithm (for \(k\)-WTA) and matrix multiplication (between an \(m\times n\) matrix and an \(n\times p\) matrix), i.e., \(O(n\log n)\) versus \(O(mnp)\), where

Figure 4: Route following performance modualated by model size. **A**: The relation between task performance and \(N_{\text{KC}}\). **B**: The relation between the same task performance and the average entropy of a stored memory item.
\(m=N_{\text{PN}},n=N_{\text{KC}}\) and \(p=1\). Since \(\log N_{\text{KC}}\ll N_{\text{PN}}\) in all our models, the FlyHash model is guaranteed to be more efficient than the conventional LSH model in terms of run-time cost.

Although processing input images directly allowed the perfect memory model to avoid any encoding costs, the computation of visual novelty in terms of the Euclidean distance between an images was less efficient than finding the Hamming distance between hashes in the other 2 models.

## 5 Discussion

In this work in progress, we investigated the data encoding and storage efficiency of the FlyHash model, which uses an insect-inspired sparse neural network to encode data as sparse hashes, by deploying it on a virtual robot in a vision-based route following task. We compared it to the conventional LSH model, which shares many structural and functional similarities with the FlyHash model, except using a dense neural network and dense hashes. The route following performance of the models was positively correlated with their model sizes, and they could achieve perfect performance given sufficiently large memory.

While the conventional LSH model outperformed the FlyHash model given the same model size, the FlyHash model with biologically realistic hashes could be largely but losslessly compressible due to its sparsity, which was impossible for the conventional LSH model. After compression, the 2 models could indeed be comparable in model size at a similar route following performance level. In addition, the FlyHash model with biologically unrealistic dense hashes was more efficient in terms of run-time cost than the conventional LSH model, due to its sparse and binary PN-KC connectivity.

In summary. we considered the FlyHash model generally more efficient, mainly because it required a lower run-time costs.

### Limitations and future work

The main limitation of the current work is that our model compression analysis was based on theoretical low bound; an explicit, efficient method to achieve the low bounds might not be easily accessible. For instance, the compressed sparse row format would be a data structure naturally compatible with our implementation for both the sparse connectivity matrix and the sparse hashes. The format will require storing \(\kappa\times N_{\text{KC}}\) indices for every \(\mathbf{y}\), occupying \(0.8N_{\text{KC}}\) bits if uint16 is used for the \(\mathbf{y}\) indices in the FlyHash model with \(N_{\text{KC}}=32000\) and \(\kappa=0.05\), much more than the theoretical lower bound (\(0.2864N_{\text{KC}}\) bits).

An alternative solution would be to store implicitly visual information in plastic neural weights in learning, instead of storing memory items explicitly and computing visual novelty with respect to all the items. With an additional output layer of even one neuron connecting to all the KCs, it should be sufficient for our models to accomplish visual route following as in Arth et al. (2016), because both our approaches rely on visual novelty detection, despite the different steering models. We are planning to add this layer, and we expect the modified FlyHash model to remain the most efficient for 2 reasons. Firstly, its encoding matrix is sparse and binary (as discussed in this manuscript). Secondly, the modified model would effectively be able to store more images (implicitly), because

\begin{table}
\begin{tabular}{c l l l l}
**Phase** & **Operation** & **FlyHash** & **conventional LSH** & **perfect memory** \\ \hline \multirow{2}{*}{encoding} & multiplication & \(0\) & \(N_{\text{PN}}\times N_{\text{KC}}\) & \(0\) \\  & addition & \(9\times N_{\text{KC}}\) & \((N_{\text{PN}}-1)\times N_{\text{KC}}\) & \(0\) \\  & \(k\)-WTA & \(1\) & \(0\) & \(0\) \\ \hline \multirow{3}{*}{evaluating} & XOR & \(N_{\text{KC}}\) & \(N_{\text{KC}}\) & \(0\) \\  & multiplication (square) & \(0\) & \(0\) & \(N_{\text{PN}}+1\) \\ \cline{1-1}  & addition (subtraction) & \(\leq 2\kappa\times N_{\text{KC}}\) & \(\leq N_{\text{KC}}\) & \(2\times N_{\text{PN}}-1\) \\ \hline \end{tabular}
\end{table}
Table 2: Model comparison in terms of run-time operations
the memory capacity \(m\) would be approximately

\[m=\frac{\log\left(1-p_{\text{error}}^{1/N_{\text{ac}}}\right)-\log\kappa}{\log(1- \kappa)}, \tag{5}\]

where \(p_{\text{error}}\) denotes the probability for the model to confuse a novel visual input mistakenly as a familiar one (Ardin et al., 2016). Thus, with \(p_{\text{error}}=1\%\), the modified FlyHash model with \(\kappa=0.05\) would merely require \(330\) KCs to distinguish novel inputs from 25 training images. Most interestingly, \(m\) increases as \(\kappa\) becomes smaller, which can be explained by the formal proof that the expanded, sparse, and binary hashes can be more easily learned by an output neuron (Dasgupta and Tosh, 2020). The modified model also reflects better the real structure of the insect MB. It is also sensible in terms of metabolic efficiency and functional effectiveness, because if the KC activation were dense, the downstream synapses would have to adjust their weights rapidly and extensively.

In addition, we are interested in comparing the (modified) FlyHash model to other data encoding techniques on a virtual robot, especially in simulations with larger physical, visual, or neural noise. It will be even more interesting to compare them on an real embodied robot. Such endeavours will deepen our understanding of the efficiency of biological intelligence, and will hopefully help us build faster and less energy demanding artificial intelligence.
