All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Two Probability Distributions (Posted on 2021-06-21) Difficulty: 3 of 5
1. Devise an algorithm to generate uniformly distributed points on the surface of a sphere (i.e., so that no area has a higher expected concentration than any other of the same size). Positions can be referenced by latitude and longitude.

2. Say an event happens at 60 times per hour in a Poisson distribution (say customer arrivals in a store), so averaging also once per minute. Devise an algorithm to generate realistic arrival times for a one-hour period.

Note: Assume what's available is a uniformly distributed random real number generator on the interval (0,1).

  Submitted by Charlie    
Rating: 5.0000 (1 votes)
Solution: (Hide)
1. Choose a longitude distributed uniformly 0-360°. Then take the arcsine of a uniform distribution from -90-90°. The arcsine will exactly balance out the tendency to crowd the poles.

2. If r is a uniformly distributed random number 0 - 1, choose each successive arrival time by adding ln(1/r)/60.

Used in a sample run:

clc, clearvars
ct=0;
t=0; mct=zeros(1,60);
while t<1
   next=log(1/rand)/60;
   t=t+next;
   if t<1
       m=floor(t*60);
       s=(t-m/60)*3600;
       fprintf('%2d:%07.4f \n',m,s)
       ct=ct+1;
       mct(m+1)=mct(m+1)+1;
   end
end
disp(ct)
for i=0:5
   disp([i sum(mct==i)])
end

 m:ss.ssss

 0:46.7421
 0:48.9987
 1:25.2184
 2:04.3230
 3:32.0891
 4:15.0252
 4:43.3157
 5:06.5318
 6:02.1858
 7:02.2580
 7:02.9835
10:19.6074
10:26.9260
10:32.3684
10:46.0439
13:04.9766
14:25.3708
15:30.9244
15:54.0881
17:53.5506
18:13.1587
20:27.3879
20:52.8891
21:35.1811
21:50.1618
22:10.2871
22:16.3612
22:23.2910
23:29.0586
23:50.5667
25:27.7937
28:57.1149
29:14.8517
29:56.4379
30:40.4858
30:46.4934
31:16.1643
31:45.0727
31:54.1610
32:07.1393
32:40.1631
34:22.0846
35:47.7286
35:54.9563
39:28.0618
40:10.8749
41:57.9284
41:59.2214
42:19.5435
43:01.0758
43:46.2384
46:35.4253
46:58.3914
50:07.9837
52:46.3130
53:25.3585
55:45.5084
55:57.5511
56:09.6379
56:29.1452
58:23.0262
58:47.9930
59:27.3910
59:29.0348
59:54.9749
    65

where by chance 65 arrivals happened during the hour.

21 of the minutes had no arrivals
18 of the minutes had 1 arrival.
17 of the minutes had 2 arrivals.
3 of the minutes had 3 arrivals,
1 of the minutes had 4 arrivals.

Jer's method also works. Increment a cumulative p (probability) using the formula for number of arrivals (in the hour) until the random number 0-1 is exceeded, and use that number to divide in a uniform distribution over the hour. An implementation is here:

clc, clearvars
ct=0;
t=0; mct=zeros(1,60);
r=rand;
p=0; n=0;
while p < r
   p=p+60^n*exp(-60)/factorial(n);
   if p>r
       break
   end
   n=n+1;
end
n=n;
for i=1:n
   m=60*rand;
   t(i)=m;
end
t=sort(t);
for i=1:n

       m=floor(t(i));
       s=(t(i)-m)*60;
       fprintf('%2d:%07.4f \n',m,s)
       ct=ct+1;
       mct(m+1)=mct(m+1)+1;

end
disp(ct)
for i=0:5
   disp([i sum(mct==i)])
end

 0:04.1438
 0:24.1751
 2:08.7458
 4:04.7740
 5:26.9638
 9:09.7963
 9:13.1642
10:33.1479
11:30.2829
13:26.5441
14:26.5453
14:34.2586
15:17.2446
15:59.2974
16:51.6191
17:20.6325
19:20.8985
20:28.0486
20:40.0647
23:12.3763
25:24.4305
25:27.6565
26:24.3065
27:26.7277
27:39.2989
27:44.8170
28:16.8858
28:24.5496
31:04.9876
31:37.7139
36:07.8138
36:26.6012
36:39.4512
38:15.7528
40:04.1978
40:18.5094
40:31.1954
40:34.0403
41:42.5058
43:18.3289
44:18.3366
46:12.5750
46:43.6881
46:49.8707
47:05.0615
50:39.8118
52:31.3378
54:57.5685
56:37.0414
57:27.6982
    50

Counts of minutes containing n arrivals
     n   number of
         such minutes
     0    27
     1    21
     2     8
     3     3
     4     1
     5     0

Comments: ( You must be logged in to post comments.)
  Subject Author Date
This should work for part 2Jer2021-06-21 09:37:03
A note and solution to 1.Jer2021-06-21 09:19:58
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (18)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information