# Numerosity task

**URL:** <https://discourse.psychopy.org/t/numerosity-task/11464>\
**Category:** Coding\
**Created:** [March 13, 2020, 8:13am UTC](https://discourse.psychopy.org/t/numerosity-task/11464 "2020-03-13T08:13:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thibault](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@thibault](https://discourse.psychopy.org/u/thibault)\
**Post date:** [March 13, 2020, 8:13am UTC](https://discourse.psychopy.org/t/numerosity-task/11464/1 "2020-03-13T08:13:07Z")

</div>

Hello,

i would like to run a numerosity task:

- 2 black circles side by side
- each circle containing a set of white dots (random position)  
where the number and size of dots in each circle can be adjusted.

Is there a simple way to code this task, or should i built it from scratch? If so, hints would be much welcome?

Thanks in advance  
best,  
thibault

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [March 15, 2020, 3:09am UTC](https://discourse.psychopy.org/t/numerosity-task/11464/2 "2020-03-15T03:09:29Z")

</div>

> [@thibault](#):
>
> random position

For any task, the meaning of “random” needs to be carefully defined. In this case, because the randomness is in two dimensions, with a circular boundary, the need for precision in the description is even higher.

---

<div class="post-metadata">

**Author:** ![thibault](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@thibault](https://discourse.psychopy.org/u/thibault)\
**Post date:** [March 15, 2020, 9:49am UTC](https://discourse.psychopy.org/t/numerosity-task/11464/3 "2020-03-15T09:49:30Z")

</div>

You are absolutely correct. What matters is that there is no obious pattern in the disposition of the dots, and that they are that there is no overlap. So i see two possible ways.

- to use two random numbers to define the position of one point (raduis and angle), and then to iterate until there is a minimal distance between each points.

- to first define an array of possible coordinates, and then to randomly assign each points to a position.

Best  
thibault

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [March 15, 2020, 7:26pm UTC](https://discourse.psychopy.org/t/numerosity-task/11464/4 "2020-03-15T19:26:18Z")

</div>

> [@thibault](#):
>
> - to use two random numbers to define the position of one point (raduis and angle), and then to iterate until there is a minimal distance between each points.

This is a possibility, but isn’t straight forward. One can sample from the angles as a uniform distribution, but then the points get spread further apart as they get further from the centre of the circle. If you want a uniform spatial distribution across the area of the circle, I _think_ the solution is something about sampling the radial value with the square root as the upper value, and then squaring the result?

But then avoiding collisions and overlaps is a a laborious task.

> [@](#):
>
> - to first define an array of possible coordinates, and then to randomly assign each points to a position.

This is far simpler to achieve, as it can de done in a deterministic way, without the iterations required to avoid overlaps. So you need to define the size and layout of the array.

---

<div class="post-metadata">

**Author:** ![Marco.Bertamini](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/marco.bertamini/32/1002_2.png) [@Marco.Bertamini](https://discourse.psychopy.org/u/Marco.Bertamini)\
**Post date:** [March 28, 2020, 8:56am UTC](https://discourse.psychopy.org/t/numerosity-task/11464/5 "2020-03-28T08:56:31Z")

</div>

With respect to placing dots within a circle and keeping the distribution uniform. It makes sense to use polar coordinates and therefore pick the radius r between 0 and the radius of the region, and then pick an angle between 0 and 360. However, this means the dor distribution is not uniform, there will be uniform dots within a band, but different densities near the centre and farther out. However this can be fixed. The radius r, should not be chosen from a uniform distribution, but one that goes as pdf\_r = (2/R^2)_r. That is you take the inverse of the cumulative distribution, so r = R_sqrt( rand()).  
More details here: [http://www.anderswallin.net/2009/05/uniform-random-points-in-a-circle-using-polar-coordinates/](http://www.anderswallin.net/2009/05/uniform-random-points-in-a-circle-using-polar-coordinates/)  
Of course you don’t have this problem if you pick x and y and then reject those locations that are outside the circular region.

Cheers, Marco

---

<div class="post-metadata">

**Author:** ![thibault](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@thibault](https://discourse.psychopy.org/u/thibault)\
**Post date:** [March 28, 2020, 11:32am UTC](https://discourse.psychopy.org/t/numerosity-task/11464/6 "2020-03-28T11:32:21Z")

</div>

Dear Marco,

thank you very much for the details!

best

thibault
