comparison src/DLD-FUNCTIONS/rand.cc @ 10840:89f4d7e294cc

Grammarcheck .cc files
author Rik <octave@nomad.inbox5.com>
date Sat, 31 Jul 2010 11:18:11 -0700
parents 3140cb7a05a1
children a4f482e66b65
comparison
equal deleted inserted replaced
10839:65bc065bec95 10840:89f4d7e294cc
352 rand (\"state\", v)\n\ 352 rand (\"state\", v)\n\
353 @end example\n\ 353 @end example\n\
354 \n\ 354 \n\
355 @noindent\n\ 355 @noindent\n\
356 You may also initialize the state vector from an arbitrary vector of\n\ 356 You may also initialize the state vector from an arbitrary vector of\n\
357 length <= 625 for @var{v}. This new state will be a hash based on the\n\ 357 length @leq{} 625 for @var{v}. This new state will be a hash based on the\n\
358 value of @var{v}, not @var{v} itself.\n\ 358 value of @var{v}, not @var{v} itself.\n\
359 \n\ 359 \n\
360 By default, the generator is initialized from @code{/dev/urandom} if it is\n\ 360 By default, the generator is initialized from @code{/dev/urandom} if it is\n\
361 available, otherwise from CPU time, wall clock time and the current\n\ 361 available, otherwise from CPU time, wall clock time and the current\n\
362 fraction of a second.\n\ 362 fraction of a second.\n\
632 \n\ 632 \n\
633 This can be used to generate many distributions:\n\ 633 This can be used to generate many distributions:\n\
634 \n\ 634 \n\
635 @table @asis\n\ 635 @table @asis\n\
636 @item @code{gamma (a, b)} for @code{a > -1}, @code{b > 0}\n\ 636 @item @code{gamma (a, b)} for @code{a > -1}, @code{b > 0}\n\
637 \n\
637 @example\n\ 638 @example\n\
638 r = b * randg (a)\n\ 639 r = b * randg (a)\n\
639 @end example\n\ 640 @end example\n\
641 \n\
640 @item @code{beta (a, b)} for @code{a > -1}, @code{b > -1}\n\ 642 @item @code{beta (a, b)} for @code{a > -1}, @code{b > -1}\n\
643 \n\
641 @example\n\ 644 @example\n\
642 @group\n\ 645 @group\n\
643 r1 = randg (a, 1)\n\ 646 r1 = randg (a, 1)\n\
644 r = r1 / (r1 + randg (b, 1))\n\ 647 r = r1 / (r1 + randg (b, 1))\n\
645 @end group\n\ 648 @end group\n\
646 @end example\n\ 649 @end example\n\
650 \n\
647 @item @code{Erlang (a, n)}\n\ 651 @item @code{Erlang (a, n)}\n\
652 \n\
648 @example\n\ 653 @example\n\
649 r = a * randg (n)\n\ 654 r = a * randg (n)\n\
650 @end example\n\ 655 @end example\n\
656 \n\
651 @item @code{chisq (df)} for @code{df > 0}\n\ 657 @item @code{chisq (df)} for @code{df > 0}\n\
658 \n\
652 @example\n\ 659 @example\n\
653 r = 2 * randg (df / 2)\n\ 660 r = 2 * randg (df / 2)\n\
654 @end example\n\ 661 @end example\n\
662 \n\
655 @item @code{t(df)} for @code{0 < df < inf} (use randn if df is infinite)\n\ 663 @item @code{t(df)} for @code{0 < df < inf} (use randn if df is infinite)\n\
664 \n\
656 @example\n\ 665 @example\n\
657 r = randn () / sqrt (2 * randg (df / 2) / df)\n\ 666 r = randn () / sqrt (2 * randg (df / 2) / df)\n\
658 @end example\n\ 667 @end example\n\
668 \n\
659 @item @code{F (n1, n2)} for @code{0 < n1}, @code{0 < n2}\n\ 669 @item @code{F (n1, n2)} for @code{0 < n1}, @code{0 < n2}\n\
670 \n\
660 @example\n\ 671 @example\n\
661 @group\n\ 672 @group\n\
662 ## r1 equals 1 if n1 is infinite\n\ 673 ## r1 equals 1 if n1 is infinite\n\
663 r1 = 2 * randg (n1 / 2) / n1\n\ 674 r1 = 2 * randg (n1 / 2) / n1\n\
664 ## r2 equals 1 if n2 is infinite\n\ 675 ## r2 equals 1 if n2 is infinite\n\
665 r2 = 2 * randg (n2 / 2) / n2\n\ 676 r2 = 2 * randg (n2 / 2) / n2\n\
666 r = r1 / r2\n\n\ 677 r = r1 / r2\n\n\
667 @end group\n\ 678 @end group\n\
668 @end example\n\ 679 @end example\n\
680 \n\
669 @item negative @code{binomial (n, p)} for @code{n > 0}, @code{0 < p <= 1}\n\ 681 @item negative @code{binomial (n, p)} for @code{n > 0}, @code{0 < p <= 1}\n\
682 \n\
670 @example\n\ 683 @example\n\
671 r = randp ((1 - p) / p * randg (n))\n\ 684 r = randp ((1 - p) / p * randg (n))\n\
672 @end example\n\ 685 @end example\n\
686 \n\
673 @item non-central @code{chisq (df, L)}, for @code{df >= 0} and @code{L > 0}\n\ 687 @item non-central @code{chisq (df, L)}, for @code{df >= 0} and @code{L > 0}\n\
674 (use chisq if @code{L = 0})\n\ 688 (use chisq if @code{L = 0})\n\
689 \n\
675 @example\n\ 690 @example\n\
676 @group\n\ 691 @group\n\
677 r = randp (L / 2)\n\ 692 r = randp (L / 2)\n\
678 r(r > 0) = 2 * randg (r(r > 0))\n\ 693 r(r > 0) = 2 * randg (r(r > 0))\n\
679 r(df > 0) += 2 * randg (df(df > 0)/2)\n\ 694 r(df > 0) += 2 * randg (df(df > 0)/2)\n\
680 @end group\n\ 695 @end group\n\
681 @end example\n\ 696 @end example\n\
697 \n\
682 @item @code{Dirichlet (a1, @dots{} ak)}\n\ 698 @item @code{Dirichlet (a1, @dots{} ak)}\n\
699 \n\
683 @example\n\ 700 @example\n\
684 @group\n\ 701 @group\n\
685 r = (randg (a1), @dots{}, randg (ak))\n\ 702 r = (randg (a1), @dots{}, randg (ak))\n\
686 r = r / sum (r)\n\ 703 r = r / sum (r)\n\
687 @end group\n\ 704 @end group\n\
688 @end example\n\ 705 @end example\n\
706 \n\
689 @end table\n\ 707 @end table\n\
690 @seealso{rand, randn, rande, randp}\n\ 708 @seealso{rand, randn, rande, randp}\n\
691 @end deftypefn") 709 @end deftypefn")
692 { 710 {
693 octave_value retval; 711 octave_value retval;
869 \n\ 887 \n\
870 Five different algorithms are used depending on the range of @var{l}\n\ 888 Five different algorithms are used depending on the range of @var{l}\n\
871 and whether or not @var{l} is a scalar or a matrix.\n\ 889 and whether or not @var{l} is a scalar or a matrix.\n\
872 \n\ 890 \n\
873 @table @asis\n\ 891 @table @asis\n\
874 @item For scalar @var{l} <= 12, use direct method.\n\ 892 @item For scalar @var{l} @leq{} 12, use direct method.\n\
875 W.H. Press, et al., @cite{Numerical Recipes in C}, Cambridge University Press, 1992.\n\ 893 W.H. Press, et al., @cite{Numerical Recipes in C},\n\
894 Cambridge University Press, 1992.\n\
895 \n\
876 @item For scalar @var{l} > 12, use rejection method.[1]\n\ 896 @item For scalar @var{l} > 12, use rejection method.[1]\n\
877 W.H. Press, et al., @cite{Numerical Recipes in C}, Cambridge University Press, 1992.\n\ 897 W.H. Press, et al., @cite{Numerical Recipes in C},\n\
878 @item For matrix @var{l} <= 10, use inversion method.[2]\n\ 898 Cambridge University Press, 1992.\n\
899 \n\
900 @item For matrix @var{l} @leq{} 10, use inversion method.[2]\n\
879 E. Stadlober, et al., WinRand source code, available via FTP.\n\ 901 E. Stadlober, et al., WinRand source code, available via FTP.\n\
902 \n\
880 @item For matrix @var{l} > 10, use patchwork rejection method.\n\ 903 @item For matrix @var{l} > 10, use patchwork rejection method.\n\
881 E. Stadlober, et al., WinRand source code, available via FTP, or\n\ 904 E. Stadlober, et al., WinRand source code, available via FTP, or\n\
882 H. Zechner, @cite{Efficient sampling from continuous and discrete\n\ 905 H. Zechner, @cite{Efficient sampling from continuous and discrete\n\
883 unimodal distributions}, Doctoral Dissertation, 156pp., Technical\n\ 906 unimodal distributions}, Doctoral Dissertation, 156pp., Technical\n\
884 University Graz, Austria, 1994.\n\ 907 University Graz, Austria, 1994.\n\
908 \n\
885 @item For @var{l} > 1e8, use normal approximation.\n\ 909 @item For @var{l} > 1e8, use normal approximation.\n\
886 L. Montanet, et al., @cite{Review of Particle Properties}, Physical Review\n\ 910 L. Montanet, et al., @cite{Review of Particle Properties}, Physical Review\n\
887 D 50 p1284, 1994.\n\ 911 D 50 p1284, 1994.\n\
888 @end table\n\ 912 @end table\n\
889 @seealso{rand, randn, rande, randg}\n\ 913 @seealso{rand, randn, rande, randg}\n\