Baboon Counting Algorithms

Human counting can be thought of as a kind of condition controlled logic where counters increment a sequence of labels “one, two, three four…” until some condition is met. (Cantlon et al. 2015) The diagram below illustrates some, but not all, of these conditions.

/Users/grahamshawcross/Documents/blog_drafts/shooting baboons/Sm

Cantlon et al. wanted to know if condition controlled logic, as exhibited by humans when counting, also played a part in the numerical capacity of other primates.

Sequential Experiment

Their main experiment consisted of placing 3 opaque cylinders in front of one of just 2 Olive Baboon monkeys, the cylinders being separated by at least a monkey’s arm length.

Screen Shot 2015-07-09 at 11.19.46

Watched by a monkey, one cylinder was filled with from 1 to 8 shelled peanuts. This was done one peanut at a time. Still watched by the monkey a second cylinder was then filled, one item at a time, with from 1 to 8 shelled peanuts. The peanuts were shown to the monkeys for 2 seconds before being put into the cylinders and there was a 2 second gap between the presentation of each peanut. The third cylinder remained unfilled and the positions of the 3 cylinders in the row was randomly determined for each trial.

Once the second cylinder had been filled, the subject baboon was allowed to choose the cylinder she preferred by pointing to it with her finger. The baboon was then allowed to eat the peanuts from the cylinder she had chosen and shown the peanuts in the other cylinder before they were removed.

Simultaneous Procedure

Randomly interspersed with the sequential procedure described above, were an equal number of experiments where the peanuts were just presented simultaneously from the left and right hands.


On average, in 68% of all the trials the baboons chose the cylinder containing the most peanuts . However the monkeys’ numerical discrimination was effected by the ratio between the numbers of peanuts in each cylinder as indicated below.


That is, the results obey Weber’s Law, so that as the ratio between the quantities increases the monkeys’ accuracy in choosing the larger quantity decreases.

Their average sensitivity to differences between numerical values was 0.86 (their Weber fraction). This means that the monkeys required nearly a 2:1 ratio between the two quantities to reliably identify the larger one.

Switching Position

During the sequential procedure, it was observed that when the second cylinder began to have more peanuts than the first cylinder the monkeys often, if they needed to, switched position to be nearer the second, fuller cylinder .


Previous investigations had assumed that numerical comparisons only took place at the end of incrementing the second set of peanuts. The shifting of position when the second cylinder began to hold more peanuts than the first shows that the baboons are actively counting the peanuts whilst retaining an understanding of the number of items in the first cylinder.


The average success rate of 68%, is lower than that reported in a number of other similar experiments. (Cantlon & Brannon, 2006) (Nieder & Miller, 2003)

It is suggested that this is because the two baboons used in this experiment had not been trained and had not participated in any previous experiments. Also they were always rewarded with food, even if they did not pick the beaker with the most peanuts.

Two control conditions were introduced to in an attempt to exclude the possibility that the choice or shifting were influenced by experimenter cuing or the length of stimulus presentation.

In an attempt to avoid cueing, two experimenters were used, sitting back-to-back. The first experimenter filled the first cylinder with the number of peanuts specified by a trial list for that cylinder only. The second experimenter filled the second cylinder from another separate trial list.

Similar results were obtained with this procedure, so it was assumed that the choices and shifting were not influenced by cuing from the experimenter in either series of experiments.

This seems to present at least two difficulties. Dropping the peanuts into the first cylinder probably made a noise that could be heard by the second experimenter. The standard 2-second interval between peanuts also meant that the duration of the first experimenter’s activity was a measure of the number of peanuts in the first cylinder. In both cases the second experimenter, at least to some degree, ‘knows’ the number of peanuts in the first cylinder and may unconsciously communicate this to the subject or indicate when the monkey should pay more attention to the second cylinder and maybe switch over to it.

The simultaneous presentation procedure seemed to indicate that timing was unlikely to be being used to estimate numerosity. To avoid the possibility that the monkeys were judging the number of peanuts from the total duration of the presentation another series of trials was carried out. In half these trials the total baiting duration for the first cylinder was 30 seconds and the baiting duration for the second cylinder was 20 seconds. In the other half the duration times were reversed. There was no significant difference between the standard trials and these trials.

Bayesian Analysis of Switching

The idea of a Bayesian analysis is to propose a parameterised model and use data to infer a probability distribution for the value of each parameter.

The model assumes that the monkeys represent the quantity of peanuts in Set 1 as an approximate value with scalar variability and that as each peanut is added to Set 2 they noisily increment an approximate mental counter and compare it to the value of Set 1. It also assumes that there is a tendency to switch position if the value of Set 2 is greater than the value of Set 1.

Each step is parameterised with a variable whose value and probability is to be inferred from the data. In this case the parameters included

a. the variability of accumulators for Sets 1 and 2

b. a baseline rate of switching

c. a rate of switching when the Set 2 value is greater than the value of Set 1.

d. the probability of increasing the value of Set 2 when a peanut is added.

e. a baseline probability specifying how often an entire trial is ignored

Before examining any evidence (data), prior likelihoods were assigned to each parameter. The variability of the accumulators for Sets 1 and 2 were both given Gamma(2,1) priors. The rate of switching was assigned a Beta(1,9) prior, corresponding to a low expectation of switching. All the other parameters were given a Beta(1,1) prior, indicating no initial bias.

“Some settings of these parameters lead to viable alternative algorithms that do not count and compare, contrary to what we hypothesized. For instance, if the probability of incrementing Set 2 when each item is added is close to zero, this would mean that the representations of quantity are not updated with each item. If the baseline probability of switching is high, behavior is not dependent on the relative quantities of the two sets, and depends perhaps only on time. If Sets 1 and 2 are given very different noise (Weber ratio) values, it may be that the two sets are represented by qualitatively different systems. If quantities are precisely enumerated, the analysis will recover Weber ratios that approach zero. Exact counting therefore corresponds to a particular setting of the model parameters that could be supported by the data”.

A Markov-chain Monte Carlo procedure was run for 500,000 steps, drawing a sample every 200 steps. The quality of the model’s inference was tested by the standard method of running multiple chains from different starting positions. This yielded for each variable the posterior distributions shown below. These indicate the statistical probability of the various parameter values.


The posterior distributions shown above indicate that the most likely parameter values are consistent with the increment and compare algorithm. The monkeys had a high probability of incrementing their Set 2 accumulator with each additional peanut (distribution d). They also had low baseline probabilities of switching (distribution b) but a high probability of switching when they believed Set 2 contained more peanuts than Set 1 (distribution c).

The analysis also recovers Weber fractions (distributions at a) from the switch trials that are similar to the Weber fraction obtained with simple fits across all the trials, although the wide variability of these values is consistent with non-exact representations of the quantities in Sets 1 and 2.

The lack of attention demonstrated, particularly by the second monkey (distribution e) could also be a cause of behavioural noise in the analysis.


Human counting requires incrementing, iteration and condition controlled logic and the algorithm used by the monkeys exhibits all these logical elements.

The algorithm is incremental because, as each peanut is added to Set 2, it increments a mental counter. It is iterative because each time this happens a mental comparison is made with the quantity of peanuts in Set 1. It is condition controlled because each time a comparison is made the algorithm checks to see if Set 2 has approximately the same or a greater quantity of peanuts than Set 1. If it has the algorithm commits to choosing Set 2.

“non-human primates exhibit a cognitive ability that is algorithmically and logically similar to human counting”.

“the monkeys used an approximate counting algorithm for comparing quantities in sequence that is incremental, iterative, and condition controlled. This proto-counting algorithm is structurally similar to formal counting in humans and thus may have been an important evolutionary precursor to human counting”.


Barnard, A. M., Hughes, D.H., Gerhardt, R.R., DiVincenti, L., Bovee, J. M., and Cantlon J.F. (2013) Inherently Analog Quantity Representations in Olive Baboons (Papio anubis). Frontiers in Comparative Psychology, 2013 4:253

Cantlon, J. F., & Brannon, E. M. (2006). Shared system for ordering small and large numbers in monkeys and humans. Psychological Science, 17, 401–406.

Cantlon, J. F., Piantadosi, S. T.,Ferrigno, S., Hughes, K. D.,Barnard, A. M. (2015) The Origins of Counting Algorithms. Psychological Science 1-13

Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian data analysis (3rd ed.). Boca Raton, FL: CRC Press.

Kruschke, J. (2011) Doing Bayesian Data Analysis: A Tutorial with R and BUGS. Europe’s Journal of Psychology Vol. 7, Isssue 4, Pages 1-187

Nieder, A., & Miller, E. K. (2003). Coding of cognitive magnitude: Compressed scaling of numerical information in the primate prefrontal cortex. Neuron, 37, 149–157.


About Graham Shawcross

Architect PhD student at Edinburgh University Interested in order, rhythm and pattern in Architectural Design
This entry was posted in Architecture, Brain Physiology, Enumeration, Logic and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s