probability and graphs
Richard Phipps

Just a quick question. Say we have a variable which we calculate by adding up two random numbers between 0-100 and then dividing the total by two.

If we then count the number of times each final number (0-100) comes up after a few thousands iterations and plot it on a graph, would the output be a triangle shape or a bell shaped curve?

:)

GullRaDriel

It depend of your random number generator algorythm.

Richard Phipps

Well, let's suppose for the sake of argument that it's a totally random output.

HoHo

see attachment.

I took 2x512 random numbers, added them up and took the average as you said. Sorted the resulting numbers and created a chart out of it. If the line would be linear it would be a linear distribution. From what I can rad out of it it really is a bell distribution.

Richard Phipps

Why thank you! I didn't expect someone to go to that much trouble. I just thought some of the math people here already knew the answer from their studies.

Cheers!
:)

Johan Halmén

Hm, let's throw two dice.

result     probability
1          0
2          1/36
3          2/36
4          3/36
5          4/36
6          5/36
7          6/36
8          5/36
9          4/36
10         3/36
11         2/36
12         1/36

Now wouldn't that be a triangle? You need more dice to get the bell. One die gives a line, two dice give a triangle, more dice twist the triangle towards the bell.

Richard Phipps

Johan: You are not dividing the result by 2 are you?

Evert
Quote:

would the output be a triangle shape or a bell shaped curve?

It will approach a bell shaped if the initial distribution is flat.
Sketch of proof: near the top of the distribution, the number of ways to create the maximum value remains the same (i.e. 1). The same holds for the minimum value you can generate.
However, near the middle of the distribution, there are more ways to generate the result (you can write down the number of permutations that yields the same result, but I can't be bothered). You can even go further and take the limit of N measurements (instead of 2) and show that the shape of the distribution tends to the normal distribution. You can test this easily with a couple of dice.

Punchline: if you sum two distributions, the result is a new and different distribution (a sum of flat distributions is no longer flat, nor is the a of normal distributions normal).

Johan Halmén

Why should I divide it? Dividing is just scaling linearly, right? Gosh, now I don't believe in myself anymore. Got to code that myself. Hate you if I was right. Hate you if I was wrong, too.

Richard Phipps

Now I'm confused too! :o

miran

Compile this:

1#include <allegro.h>
2 
3int main() {
4 allegro_init();
5 set_color_depth(32);
6 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
7 install_keyboard();
8 
9 int num[640];
10 for (int i=0; i<640; i++) {
11 num<i> = 0;
12 }
13 
14 srand(time(0));
15 int max = 0;
16 for (int i=0; i<1000000; i++) {
17 int x = rand()%640;
18 int y = rand()%640;
19 int z = (x + y)/2;
20 ++num[z];
21 if (num[z] > max) {
22 max = num[z];
23 }
24 }
25 
26 clear_to_color(screen, makecol(212,212,212));
27 int col2 = makecol(192,64,64);
28 for (int i=0; i<640; i++) {
29 int y1 = SCREEN_H - num<i>*SCREEN_H/max;
30 int y2 = SCREEN_H;
31 vline(screen, i, y1, y2, col2);
32 }
33 
34 readkey();
35}
36END_OF_MAIN()

It will draw a triangle.

Evert
Quote:

Why should I divide it? Dividing is just scaling linearly, right?

Yes. You should divide it if you want to keep the same normalisation.

Arthur Kalliokoski

To say it all a different way, let's throw the dice again.

To throw a 2 both dice have to fall on one's, no exceptions.

But to get a 7, you could have a "1+6", "2+5" "3+4" "4+3" "5+2" or "6+1".

Well, I suppose listing the result to get 2 would take "1+1" and "1+1" for symmetry.

Evert

To clarify what I said in my first post:
The sum of N flat distributions tends to a normal distribution as N tends to infinity.

X-G

Quote:

Yes. You should divide it if you want to keep the same normalisation.

But we're only interested in the distribution, which shouldn't change by scaling it.

Evert

True, but it's easier to compare the distributions if they're both normalised.

Richard Phipps

So how do you get a bell shaped curve with probabilites? ???

(None of this is really relevant I guess.. Just curious)

Matthew Leverton
X-G

Quote:

So how do you get a bell shaped curve with probabilites?

Box-Muller transform.

Richard Phipps

Thanks.

Johan Halmén
miran said:

It will draw a triangle.

Thanks, miran. Now I don't have to hate anyone.

[added]

Arthur said:

Well, I suppose listing the result to get 2 would take "1+1" and "1+1" for symmetry.

No. There's only one 1+1 case.

Thread #573044. Printed from Allegro.cc