Collective gradient sensing in fish schools

Throughout the animal kingdom, animals frequently benefit from living in groups. Models of collective behaviour show that simple local interactions are sufficient to generate group morphologies found in nature (swarms, flocks and mills). However, individuals also interact with the complex noisy environment in which they live. In this work, we experimentally investigate the group performance in navigating a noisy light gradient of two unrelated freshwater species: golden shiners (Notemigonuscrysoleucas) and rummy nose tetra (Hemigrammus bleheri). We find that tetras outperform shiners due to their innate individual ability to sense the environmental gradient. Using numerical simulations, we examine how group performance depends on the relative weight of social and environmental information. Our results highlight the importance of balancing of social and environmental information to promote optimal group morphologies and performance.

Collective animal behaviour arises from self-organising social interactions among individuals 1,2 . While the functional form of these interactions is not trivial to determine from experiments 3 , models have shown that simple local social interactions consisting of rules such as repulsion, alignment, and attraction are sufficient to generate observed group morphologies, such as swarms, flocks, and mills [4][5][6][7][8][9] . However, in nature, individuals must balance social information with individually acquired environmental information [10][11][12] .
Social interactions benefit group members in diverse ways. Living in groups has been shown to increase foraging ability 13,14 and reduce predation risk 15 through collective vigilance 16 or escape waves 17 . Individuals can also use social information to help navigate noisy environmental gradients [18][19][20] . In this case where individuals may benefit from pooling information to overcome inaccurate estimates, which is often called 'wisdom of the crowd' 21 or the 'many wrongs' principle [22][23][24] . For each of these benefits, individuals combine social and environmental information which enhances information processing 11 , possibly leading to emergent collective intelligence 20,25,26 .
However, social benefits are weighed against possible downsides 27,28 , such as de-valued individual information 27 and decreased sensitivity to changing environments 29 . Individuals must weigh environmental information gathered from their senses along with social information 30 or become isolated and face a greater risk of predation 9,31,32 .
Despite the large number of studies on collective behaviour, how individuals integrate social and environmental information across ecological contexts remains an open question. Previous work using mixed societies of artificial and natural agents has shown group decisions arise from nonlinear feedback between local interactions between individuals 33 . Using multi-robotic-fish systems 34 and simulations 35 , studies have explored the evolutionary mechanisms through which individuals use social information to better interpret noisy environmental information.
In a recent study, Berdahl et al. examined how a school of golden shiners (Notemigonus crysoleucas) collectively navigated a noisy environment (a dynamic light field) 20 . While individual golden shiners could not detect the environmental gradient, the school was able to collectively swim toward darker waters. The emergent sensing arose from social interactions governed by a simple rule: golden shiners swim faster in bright regions and slower in dark regions. However, many animals, even those of microscopic scales such as bacteria 36 , are able to sense environmental gradients.
In this work, we investigate the interplay of social and environmental information and how it impacts group performance. Building on recent work by Berdahl et al. 20 , our study combines empirical data with numerical simulations to examine the performance of schools of fish in navigating dynamic light fields. We experimentally examined group gradient sensing ability in two different species of freshwater fish: golden shiners (Notemigonus crysoleucas) and rummy nose tetra (Hemigrammus bleheri). While we find golden shiners are not able to sense the environmental gradient but are able to collectively find darker regions using an emergent sensing as in agreement with previous work 20 , the tetras out-performed the shiners for all group sizes, which can be attributed to tetra's ability to sense the light gradient individually. We propose a model based on the light intensity dependent speed-modulation proposed in the Berdahl-Couzin model 20 . Our model includes an additional gradient sensing term that can be tuned to investigate the interplay of environmental and social information and its effect on group performance.
Our results show that while an individual's ability to sense gradients generally improves the group's performance, there are downsides. With greater weight given to environmental information, individuals rely less on social information leading to larger nearest neighbour distance, eventually fragmenting the school. However, by balancing social and environmental information, the nearest neighbour distance can be minimised, decreasing predation risk 9,37,38 while keeping group performance near optimal. The relative gradient sensing weight that minimises nearest neighbour distance avoids relying too much on one source of information and produces simulations that agree with our experimental data for rummy nose tetras.

Results
Experimental results. We filmed schooling events of two freshwater species, golden shiners (Notemigonus crysoleucas) and rummy nose tetras (Hemigrammus bleheri), in a shallow tank (183 cm × 102 cm, 8 cm water depth). As shown in Fig. 1a, a projector located 226 cm over the experimental arena casts a dynamic light field at 30 Hz onto the bottom of the tank. An IR camera placed 180 cm over the tank records images at 30 Hz as shown in Fig. 1. A cropped sample image of the light is shown in Fig. 1b, with an overlay of the silhouettes of tetras for scale. Each noise image is the sum of a circular dark spot with gaussian decay (with length scale 38.1 cm) to white and a noisy greyscale light field that varies spatiotemporally 20,39 . The dark spot moves with a constant speed of 5.7 cm/s in random directions. The noise level η = 0.25 was held constant throughout the experiments. See the Supplementary Information and Berdahl et al. 20 for further details on the light field.
We investigated the gradient tracking performance of schools of N = 16, 32, 64, and 128 individuals. For each species and group size, we conducted five replicate experiments with different random seeds used to generate the light fields. Each experiment consisted of fish navigating the dynamic light field for 5 minutes. Individual fish were tracked following a similar technique to Rosenthal et al. 40 to obtain trajectories of individual's positions. Velocities and accelerations were computed by convolving the position time-series with the first and second derivatives of a Gaussian, respectively 41 . More details on our experimental methods and husbandry procedures are given in the Supplemental Information.
To quantify group gradient tracking performance, we calculate the mean gradient tracking performance as, ψ = 〈〈1−L〉 fish 〉 t , which averages the local light level first over all fish in each frame and then over all time 20 . This raw performance metric is then divided by the null performance, ψ null , which is defined similarly except by averaging over the level of darkness of fish trajectories if they instead experienced the temporal average of the light field. The un-biased gradient tracking performance is then, The theoretical maximum performance for a single individual is obtained by minimising Ψ null while remaining in the dark patch for the entire trial. Averaging over all five light fields generated with different random seeds, we calculate Ψ max = 2.32 ± 0.72. While Ψ max gives a hard upper limit on group performance, this inaccurately assumes that fish can minimise Ψ null (fish have no knowledge of the temporal average of the light fields) and more importantly that fish occupy no volume. In Fig. 2a, we show the number density ρ = A group /(N⋅BL 2 ) as a function of group size N for both shiners and tetras. In all our experimental statistical analysis, data was analysed with R version 3.4.3 using a generalised linear mixed model (GLMM) approach with gamma errors using the lmer4 package 42 , where light field random seed and home tank were included as random factors to test for any effects with light field and group identity, respectively. There was no significant effect of group size on the number density ρ for both shiners (χ 2 = 0.210, p = 0.647) and tetras (χ 2 = 1.768, p = 0.184). The number density was ρ = 0.69 for shiners and 1.28 for tetras, so the tetras are forming schools with roughly twice the number density as shiners.
In all our experiments, the radius of the circular dark spot is constant. Therefore, even if a school can perfectly track the spot, we expect that the group performance Ψ decreases for schools that are sufficiently large as some individuals will be beyond the radius of the dark spot. Note, however, that there are three factors which contribute to the area of the school: the number of fish N, the number density ρ and the size of fish BL. Firstly, the number density ρ for both shiners and tetras is intensive (does not depend on N) as shown in Fig. 2a, so increasing the number of fish N linearly increases the overall area occupied by the school. Secondly, schools with lower number density ρ occupy more area as the distance between each fish is larger. In Fig. 2a, we showed that a school of tetras has roughly twice the number of density ρ compared to shiners, therefore, tetras are forming denser, smaller schools than shiners. Finally, for a given N and ρ increasing the size of the fish increases the overall area of the school. The average body length of our shiners (5.3 ± 0.5 cm) is about 50% longer than the tetras (3.4 ± 0.5 cm). Shiners are larger fish that are forming less dense schools, therefore, we expect the optimal group performance for shiners to be less than tetras for large N.
For both shiners and tetras, the level of performance, Ψ is shown as a function of group size in Fig. 2b. To quantify how school size effects optimal performance for shiners and tetras, we calculate Ψ max,S and Ψ max,T for a circle of area N times the average area occupied by a shiner or tetra, respectively. In Fig. 2b, we show how Ψ max,S and Ψ max,T depend on N given the average area of a school for each respective species. For small schools, Ψ max is large as the area of the school is smaller than the area of the dark spot. However, as N grows, Ψ max decays with N, albeit decaying faster for shiners than tetras due to their larger area schools for a given N.
The group performance of shiners was found to be independent of group size (χ 2 = 1.833, p = 0.176), which did not agree with the result found by Berdahl et al. 20 . Since larger schools occupy greater area, larger group size decreases the optimal group performance of a given size school Ψ max,S . In Fig. 2b, note that the Ψ(N = 128) ≈ Ψ max,S (N = 128) showing that large schools of shiners are performing near optimally. The slightly larger size of our shiners compared to those used in Berdahl et al. (BL = 4.9 cm) 20 is likely responsible for the small decrease in performance for large schools of shiners. Therefore, with smaller shiners (or a larger central dark spot), we expect our results to agree with Berdahl et al.
Additionally, we found that group performance for tetras decreased with increasing group size (χ 2 = 4.620, p = 0.032). However, we note that the group performance for N = 128 is bounded by the decreasing optimal performance Ψ max,T which is due to the increasing area of the school but constant radius of the dark spot. While larger school area limits the group performance at large N, we found that tetras outperform shiners for small group sizes where the area of the school is small compared to the area of the central dark spot. We examine correlations between individual's acceleration to uncover the mechanism for the greater performance of tetras over shiners.
We investigated the mechanism for the increase in gradient tracking performance of tetras over shiners by examining the correlation between individual's acceleration and the social and environmental vectors. We estimate a social vector S which is calculated using neighbours within seven body lengths of the focal individual, The direction of the social vector indicates the direction of social attraction and its length is a proxy for the strength of the attraction. While Fig. 3 uses seven body lengths to find S, our results do not qualitatively change if the interaction range r s is between five and nine body lengths, as shown in Supplemental Figures S4 and S5.
We take the environmental vector G i to be the negative gradient of the light field L evaluated at the position x i of each fish, The environmental vector G i points in the direction of steepest descent toward darkness and its length is the rate of change of the light field in that direction. To calculate the response of an individual fish to its social and environmental vectors, we calculate the correlation between the direction of the corresponding vector and the direction of the fish's acceleration with the following, Using C social and C environmental , we determine whether the motion of individuals is more strongly correlated with social or environmental information.
In Fig. 3a, we show C social and C environmental for shiners as functions of the magnitude of the social vector S. Since, G is independent of S we use the C environmental as a baseline to check the significance of C social . For shiners, we find that C social ≈ C environmental when the magnitude of the social vector is less than 3, signifying that an individual's acceleration is poorly correlated with the social vector. Note that the social vector's magnitude is determined by the number of individuals in the range and their spatial distribution. The magnitude of the social vector |S| is small when either few neighbouring fish are located within the interaction range or neighboring fish are located uniformly around the focal fish. We do not expect shiners to respond strongly to the social vector in these situations. The magnitude of the social vector |S| is large when several neighbouring fish are located in a consistent direction. In Fig. 3a, when |S| > 3, we find that C social > C environmental and C social grows linearly with the magnitude of the social vector, signifying that the shiner's accelerations are correlated with the social vector.
In contrast, as shown in Fig. 3b, C environmental ≤ C social for all magnitudes of the environmental vector, suggesting that individual shiners may not be able sense the environmental gradient, in agreement with recently reported results 20 . When the magnitude of the environmental vector is very large, the uncertainty in C environmental and C social grows rapidly as the data is sparse and individual behavior is more variable. In contrast to the data reported for shiners, we find that the accelerations of tetras are not strongly correlated with the social vector as shown in Fig. 3c, as C social < C environmental . However, as shown in Fig. 3d, tetras respond strongly to the light gradient as C environmental > C social and C environmental increases with the magnitude of the environmental vector. Note that this does not imply that tetras do not respond to social forces, only that their accelerations are more strongly correlated with the environmental vector.
While our results for shiners show that individuals are more strongly influenced by social information, tetras appear to exhibit the opposite trend and are more strongly influenced by the environmental gradient, as shown by C environmental > C social shown in Fig. 3d. This result clarifies the findings in Fig. 2b, where tetras outperformed shiners in navigating the dynamic light field toward darker regions. This stark contrast in performance between tetras and shiners in solving the same problem is due to the different gradient sensing mechanisms. Shiners rely strongly on social cues which leads to an emergent group level gradient sensing 20 , but tetras can individually sense the environmental gradient.
Simulation model. As we have seen, different species of fish vary in the degree to which they base their movement on social and environmental information. To investigate this relationship, we explore how group performance depends on the relative weighing of environmental and social information via a tunable weight parameter, w.
We propose a new model, built on the recently proposed agent based Berdahl-Couzin model 6,20,43 , to which we augment with an environmental gradient sensing for each individual. Individuals interact socially via the canonical Couzin model where motion is determined via repulsive, aligning, and attractive interactions that depend on distance to neighbours. The direction given by social cues is  d social . Explicit details of the calculation of  d social are outlined in the Supplemental Information. We calculate the gradient of the noisy light field The updated direction of each individual is given by social environmental where w is the relative weight and  d social and  d environmenteal are unit vectors corresponding to the social and environmental vectors, respectively. To determine the velocity of each individual, we then normalise d and multiply by the speed s, To determine the speed of individuals, we follow the Berdahl-Couzin model using a light intensity dependent speed-modulation proposed by Berdahl et al. 20 , where individuals slow down in dark regions and speed up in bright regions. The speed grows linearly with the brightness, given by s = s min + L(s max − s min ). Note, the speed modulation is the basis for the shiner's emergent sensing. Further details and a flowchart for our model algorithm are given in the Supplementary Information.
In the limit that w → 0, social interactions entirely determine individual behaviour and our model reverts to the Berdahl-Couzin model 20 . In the opposing limit where w → ∞, individuals lose all social information and respond only to their local environmental gradient. We investigate the group performance as a function of group size N = [8, 16, 32, 64, 128, 256], the weight given to gradient information w is 32 log-spaced values between 10 −2 and 10 3 , and the noise level of the environment η = [0.10, 0.25, 0.40]. We performed 20 replicate simulations for each weight and noise level. Each simulation was run for 10 4 time steps and data was recorded every 100th time step. In all our simulations presented in the main text, the parameters used for the Couzin model 6 remained fixed throughout the simulations and were: zone of repulsion 0.5; zone of orientation 3.0; zone of attraction 5.5; field of perception 270 degrees; turning rate 100 degrees; social error 0.01 radians; time step increment 0.125. These values correspond to the parameters fit for golden shiners as previously reported by Berdahl et al. 20 .
Simulation results. In Fig. 4a, we show the group performance Ψ of our simulation as a function of the weight w with a noise level η = 0.25. The shape of Ψ(w) is sigmoidal. We find that increasing w (the gradient sensing weight) greatly increases Ψ of the group. In this limit, individuals follow the gradient eventually finding the moving dark region. However, inside the dark region d environmental = 0, since the gradient is zero, and the motion of individuals is determined by social interactions. Increasing group size N decreases the maximum Ψ, which is due to the increasing size of the school. Therefore, larger group sizes do not benefit from large gradient sensing weight as much as smaller groups. To quantify this effect, we calculate the max gain in group performance ΔΨ = max(Ψ) − Ψ(w = 0). In Fig. 4b, we show ΔΨ as a function of group size, N for three different noise levels η = 0.10,0.25, and 0.40. We find that ΔΨ decreases monotonically with increasing N and decreases with increasing η, showing that larger groups benefit less from an individual's ability to sense the gradient regardless of the noise level of the environment.
The group performance decreases with increasing noise level η at large w, as shown in Fig. 4c. In more noisy environments, individuals who strongly rely on gradient sensing benefit less, as they respond to local variations in light level instead of large scale features.
Another trend of increasing η is the shifting of the sigmoidal Ψ(w) toward smaller w. The sigmoid reaches half the max, Ψ = Ψ = + ΔΨ w ( 0) 1/2 1 2 , at w 0 as shown in Fig. 4c. In Fig. 4d, we show the shifting of the group performance Ψ toward smaller w by showing w 0 as a function of N and η. The weight at half-max, w 0 , decreases with increasing environmental noise level η. We also find a maximum of w 0 for groups of N = 32, demonstrating that small (and large) group benefit more from smaller weights w than intermediate group sizes.
Up to this point, our study did not account for the ubiquitous presence of error in individual environmental gradient sensing. To introduce this effect, we include a gaussian random error with standard deviation σ w which is added at each timestep to the local gradient direction. As shown in Fig. 5, for small w, the amount of error added to the gradient direction is nullified as individuals base their direction on social interactions. For large weights, w > 100, increasing the amount of error σ w destroys the individual ability to sense the gradient and turns the simulation into non-interacting random walkers.
While increasing w increases the group performance Ψ, large w destroys social information. To quantify this effect, we calculate the nearest neighbour distance d nn . For all group sizes N, nearest neighbour distance decreases with increasing w to a minimum d min( ) nn N . We find that d nn decreases for increasing group size N, corresponding to the increasing density of the group near the dark spot. Note that d nn < 0.5BL for N ≥ 128 which is due to overcrowding in the dark spot and low time resolution. With shorter Δt for the simulation, the repulsive social interaction would prohibit such overcrowding and should yield a minimum d nn ≥ 0.5BL. For large w, we find that d nn increases, as long range attractive social interactions weaken and individuals follow local transient gradients away from the school.  We propose that nature selects the weight w which balances individually acquired gradient information with social information such that nearest neighbour distance d nn is minimised for all group sizes. Smaller nearest neighbour distance reduces predation risk 9,37,38 . We find the weight which minimises the sum of the squared difference of d nn for group sizes N = 16, 32, 64 and 128 to be = . ∼ w 31 6 min , and is shown in Fig. 6a. Therefore, by weighing their individually acquired gradient information around thirty times stronger than social interaction, individuals can optimise both Ψ and d nn . However, we emphasise the granularity of w due to computational cost. Using = ∼ w w min , we show the group performance Ψ as a function of N in Fig. 6b. We find good agreement between our model and experimental data for the rummy nose tetras. In Fig. 6b, the shaded region represents the Ψ for the range of w that minimise d nn in simulations for each group size N, w = 14.7 to 68.1. Therefore, to further improve the model's ability to match the tetra's behaviour, one could optimise r o , r a and w to better replicate the behaviour of the tetra, however, given the large error bars on the simulated group performance and the good agreement with experimental data, parameterising the data for the tetras may be of limited value. We find that the weight which minimises d nn also minimises the root mean square error (RMSE) in group performance for experimental data of the tetras. For groups N = 128, the group performance for Ψ for the tetras falls below the range predicted by our simulation. attribute this disagreement largely to distraction of individual fish with the edge of the tank.
Note that the simulations are not parametrised to fit the schools of tetra. In all the numerical results, we fixed the repulsion, orientation and attraction zonal distances to match those reported for golden shiners previously reported 20 . We use the simulations to display a generic behaviour of self-propelled particle models which supports our experimental observations that tetras have some innate environmental gradient sensing ability. In the Supplemental Information Fig. S8, we show that the minimum of the RMSE between the tetras and the performance for our model using w = 0 (Berdahl-Couzin) gives a smaller interaction range (r o ,r a ), but the RMSE is several times larger than that reported for the shiners 20 . Furthermore, using this r o and r a , we conduct a parallel analysis as in the main text and find that the agreement with the experimental data was not as good as results reported in the main text in Fig. 6b. We refer the reader to the Supplemental Information for further discussion.

Discussion
This work presents experimental and numerical studies on group performance of fish schools navigating a spatiotemporally varying light field. First, we experimentally investigated the collective gradient tracking performance of two freshwater species: golden shiners (N. crysoleucas) and rummy nose tetras (H. bleheri). Our results agree with previous findings that the motion of shiners is based strongly on social interactions and is not correlated with the light gradient 20 . However, our results show that tetras outperform shiners at this task for all group sizes, which is due to the individual ability for tetras to sense the gradient of the light field. The emergent collective sensing (shiners) and collective enhanced individual sensing (tetras) are distinct gradient sensing mechanisms.
Second, we used these observations to propose an agent-based model based on the Berdahl-Couzin model 6,20 , where we included a gradient sensing ability which is weighted against social information for each individual. In our simulations, we find that group performance increases with increasing dependence (weight) on gradient sensing information, which is robust to group size N and noise scale η as shown in Fig. 4a,c. However, when individuals rely too much on their individual information, social information is lost, nearest neighbour distance increases and the school fragments.
To balance the benefits of social information and group living 9,31 with individually acquired environmental information, we proposed that individuals adjust the relative weight attributed to environmental (gradient) or social information to minimise the average nearest neighbour distance d nn . This adaptation is important, as decreasing nearest neighbour distance reduces risk of predation 9,37,38 . Using the gradient sensing weight which minimises the nearest neighbour distance, we found good agreement with our experimental data for tetras. Furthermore, we found that the minima in the d nn depends on N, which suggests that it may be advantageous for individuals to dynamically adjust the weight based on group size. A dynamic tuning based on the situation would allow individuals to optimise their performance based on the situation or quality of information. For example, a dynamic tuning would allow individuals to favour individually acquired environmental information, when the environment is less noisy or the magnitude of the environmental vector is large. By contrast, if the magnitude of the social vector is large or the environment is noisy 44 , individuals can benefit from decreasing the weight and relying more on social information.
Dynamic and adaptive behavioural rules have been experimentally investigated in groups of fish exposed to alarm or food cues. Under predatory cues, x-ray tetras slow down and increase in density 45 and bluegill sunfish form more highly polarised schools 46 . Fish swim faster and decrease in density when exposed to food 45,47,48 . While individual differences in physical ability and sensing can have large implications on decision making 49 and the fitness of the group 50 , social benefits may pressure individuals to ignore private information and conform 51 . In these situations, individuals adjust their social interactions via rapid feedback loops in order to conform to the group 50,52,53 .
For rummy nose tetras, we found group performance decreases with group size, which is due to geometrical constraints as size of the school exceeds the size of the dark spot. Our results show that tetras can maximise their benefit in smaller groups. In some contexts, larger groups may improve the group performance 20 and facilitate fast and accurate decisions where there are predatory cues 49 , though larger groups can increase confidence without increasing decision accuracy 54,55 and in some cases deteriorate obstacle avoidance capabilities 56 . As often seen in nature 2,31 , individuals may maximise their benefit in small to intermediate sized groups with increased decision accuracy from inherent noise and less detrimental feedback from correlated information (present in larger groups) 55 . In P. longicornis ants where the food is collectively transported, the collective response is maximised for intermediate group sizes where criticality facilitates the flow of new information 56 . In a similar experiment to the one in the text and Berdahl et al. 20 , however using humans, collective sensing was maximised in smaller groups, where collective sensing strategies were learned in minutes 57 .
In summary, our model shows the disadvantages of extreme behavioural rules, where either relying too strongly on either social information (w = 0) produces in poor group performance or relying too strongly on individually acquired environmental gradient information (w → ∞) destroys valuable social information and fragments groups. Our results show that individuals can balance their individually acquired environmental information with social information, which promotes group performance and strong cohesion. Our experimental results show two freshwater species using distinct gradient sensing mechanisms: emergent collective sensing (shiners) and collective enhanced individual sensing (tetras). These interaction rules evolved under distinct ecological and social conditions 35 . In new environments, individuals value social information more than their individually acquired environmental information (w < 1) which is due the need to conform 49 . Therefore, it is likely that individuals also adjust their weighing of social and environmental information w. An extension of this work would explore the extent to which individuals tune w to conform with the group or if w depends on the environmental noise level.

Methods
Husbandry. We studied the gradient sensing performance of schools of golden shiners (Notemigonus crysoleucas) and rummy nose tetras (Hemigrammus bleheri) in a laboratory. While both are freshwater fish that prefer to school in dark shallow water, shiners (a cyprinid found in cool waters of eastern North America) and tetras (a characin found in the tropical waters of Amazon Basin of Brazil and Peru) require different water chemistry.
The golden shiners N. crysoleucas were acquired from Anderson Minnows. We kept approximately 500 juvenile shiners in three 30 gallon home tanks (≈150 in each tank) using de-chlorinated, aerated, and filtered tap-water kept at 21 °C. Water changes of 30% were done twice weekly. Shiners were 5.3 ± 0.5 cm in length.
The rummy nose tetras, H. bleheri, were acquired from Cichlid Exchange. We kept approximately 200 tetras in two 40 gallon home tanks (100 in each) at a constant temperature of 27.0 ± 0.5 °C in a 1:3 de-chlorinated tap water to reverse osmosis water that was aerated and filtered. The RO water diluted the pH and gH of the tap water to 6.8 ± 0.2 and 100 ± 20 ppm, respectively. Water changes of 20% were done once a week. Tetras were 3.4 ± 0.5 cm in length.
The home tanks for both species were illuminated with 12 h of light and 12 h of darkness per day. Both were fed a mix of crushed TetraMin flakes, Hikari brine shrimp, micro pellets, and freeze-dried blood worms four times a day. Before each experimental trial, fish were gently netted from their home tanks an hour after their first feeding and transferred to the experimental tank. We ensured that fish were not used in experiments on consecutive days by using a rotating schedule to select which home tank to gather fish. Fish were appropriately acclimatised to the water in the experimental tank before experiments took place. Further husbandry details are outlined in the Supplementary information.

Ethics.
All experiments were conducted in accordance with federal and state regulations and were approved by the Gettysburg College Institutional Animal Care and Use Committee.
Experimental setup. We conducted experiments with golden shiners and rummy nose tetra in a quasi two-dimensional acrylic tank (183 × 102 cm, 8 cm water depth). Videos of schooling events were captured via a USB3 Point Grey camera mounted 180 cm above the tank which was back-lit by 850 nm infrared LEDs positioned beneath the tank. The videos were captured in 2048 × 1280 px at 30 frames per second by the camera which was hardware triggered to synchronise with the projected light field. The dynamic light field of 940 × 540 px were generated by a projector positioned 226 cm above the experimental tank at 30 frames per second. As shown in Supplemental Figure S2 and zoomed in Fig. 1, the projected field consisted of a single dark spot which moved randomly around the tank at a constant speed and was overlaid on a noisy background which varied both spatially and temporally, identical to the method detailed in a previous work 20 . Measured light levels at the surface of the tank ranged from 10 lux (approximately twilight) to 500 lux (sunrise on a clear day), corresponding to the natural environment of the fish in the morning or evening.
For each species (tetra and shiner) and group size N = 16, 32, 64 and 128, we recorded five replicate experiments for 5 minutes. We used four different seeds to generate each projected video at a medium level of environmental noise (η = 0.25), and added a 50 pixel white border to the light field to discourage fish from interacting with the sides of the arena. Each experimental run was followed by a 10 minute rest period under neutral lighting (0.5 lux, deep twilight). See Supplementary information for further experimental details. Fish Tracking. Our algorithm was implemented in Python using the OpenCV library, and followed a similar approach to SchoolTracker 40 . Individual fish are located using detected line-segments in background subtracted frames of video. We then track fish from frame to frame by linking their two-dimensional positions over time using a Kalman filter. Due to the large number of fish, occlusions are frequent and the detection/tracking algorithm can fail to locate and track a fish over multiple frames. The tracks are spliced together by linking tracks in a four-dimensional position-velocity space 58 . Our tracking algorithm recovers 90% of trajectories for N = 128 and 92% for N = 16. Since our focus in this paper does not rely on us maintaining identities for long periods of time, we have sufficient data to calculate velocities and accelerations.
Once the time-resolved trajectories are known, we compute velocities and accelerations by convolving the trajectories with a Gaussian smoothing and differentiating kernel 41,59 . Derivatives computed using this convolution method are less noisy than what would be obtained from a simple finite difference scheme. For the data presented here, the convolution kernel was chosen to have a standard deviation of 1.5 frames, and the position information from 11 frames was used to calculate each derivative.