Last change
on this file since 177 was
37,
checked in by (none), 15 years ago
|
Added original make3d
|
-
Property svn:executable set to
*
|
File size:
521 bytes
|
Rev | Line | |
---|
[37] | 1 | p = 0.13;
|
---|
| 2 | n = 123;
|
---|
| 3 | tim = [];
|
---|
| 4 |
|
---|
| 5 | nsamples = 1e4;
|
---|
| 6 | y = zeros(nsamples,1);
|
---|
| 7 | tic
|
---|
| 8 | for i = 1:nsamples
|
---|
| 9 | y(i) = randbinom(p,n);
|
---|
| 10 | end
|
---|
| 11 | tim(1) = toc;
|
---|
| 12 | g = int_hist(y+1,n+1)/nsamples;
|
---|
| 13 | tic
|
---|
| 14 | for i = 1:nsamples
|
---|
| 15 | y(i) = binornd(n,p);
|
---|
| 16 | end
|
---|
| 17 | tim(2) = toc;
|
---|
| 18 | fprintf('Time for binornd: %g\n', tim(2));
|
---|
| 19 | fprintf('Time for randbinom: %g (%g times faster)\n', tim(1), tim(2)/tim(1));
|
---|
| 20 |
|
---|
| 21 | if 0
|
---|
| 22 | % test validity of the sampler (use nsamples = 1e5)
|
---|
| 23 | x = 0:n;
|
---|
| 24 | f = binopdf(x,n,p);
|
---|
| 25 | plot(x,f,x,g)
|
---|
| 26 | legend('true','estimated')
|
---|
| 27 | end
|
---|
Note: See
TracBrowser
for help on using the repository browser.