Mercurial > octave
comparison src/DLD-FUNCTIONS/rand.cc @ 6437:190dfe8b8f08
[project @ 2007-03-23 14:17:31 by dbateman]
author | dbateman |
---|---|
date | Fri, 23 Mar 2007 14:17:31 +0000 |
parents | 0b190c343471 |
children | 9dc77e3c9313 |
comparison
equal
deleted
inserted
replaced
6436:f1f2e0de340a | 6437:190dfe8b8f08 |
---|---|
38 #include "error.h" | 38 #include "error.h" |
39 #include "gripes.h" | 39 #include "gripes.h" |
40 #include "oct-obj.h" | 40 #include "oct-obj.h" |
41 #include "unwind-prot.h" | 41 #include "unwind-prot.h" |
42 #include "utils.h" | 42 #include "utils.h" |
43 | |
44 /* | |
45 %!shared __random_statistical_tests__ | |
46 %! % Flag whether the statistical tests should be run in "make check" or not | |
47 %! __random_statistical_tests__ = 0; | |
48 */ | |
43 | 49 |
44 static octave_value | 50 static octave_value |
45 do_rand (const octave_value_list& args, int nargin, const char *fcn, | 51 do_rand (const octave_value_list& args, int nargin, const char *fcn, |
46 bool additional_arg = false) | 52 bool additional_arg = false) |
47 { | 53 { |
414 %! assert(x,z); | 420 %! assert(x,z); |
415 */ | 421 */ |
416 | 422 |
417 /* | 423 /* |
418 %!test | 424 %!test |
419 %! % statistical tests may fail occasionally. | 425 %! % Test fixed state |
420 %! rand("state",12); | 426 %! rand("state",1); |
421 %! x = rand(100000,1); | 427 %! assert (rand(1,6), [0.1343642441124013 0.8474337369372327 0.763774618976614 0.2550690257394218 0.495435087091941 0.4494910647887382],1e-15); |
422 %! assert(max(x)<1.); %*** Please report this!!! *** | 428 %!test |
423 %! assert(min(x)>0.); %*** Please report this!!! *** | 429 %! % Test fixed state |
424 %! assert(mean(x),0.5,0.0024); | 430 %! rand("seed",1); |
425 %! assert(var(x),1/48,0.0632); | 431 %! assert (rand(1,6), [0.8668024251237512 0.9126510815694928 0.09366085007786751 0.1664607301354408 0.7408077004365623 0.7615650338120759],1e-15); |
426 %! assert(skewness(x),0,0.012); | 432 %!test |
427 %! assert(kurtosis(x),-6/5,0.0094); | 433 %! if (__random_statistical_tests__) |
428 %!test | 434 %! % statistical tests may fail occasionally. |
429 %! % statistical tests may fail occasionally. | 435 %! rand("state",12); |
430 %! rand("seed",12); | 436 %! x = rand(100000,1); |
431 %! x = rand(100000,1); | 437 %! assert(max(x)<1.); %*** Please report this!!! *** |
432 %! assert(max(x)<1.); %*** Please report this!!! *** | 438 %! assert(min(x)>0.); %*** Please report this!!! *** |
433 %! assert(min(x)>0.); %*** Please report this!!! *** | 439 %! assert(mean(x),0.5,0.0024); |
434 %! assert(mean(x),0.5,0.0024); | 440 %! assert(var(x),1/48,0.0632); |
435 %! assert(var(x),1/48,0.0632); | 441 %! assert(skewness(x),0,0.012); |
436 %! assert(skewness(x),0,0.012); | 442 %! assert(kurtosis(x),-6/5,0.0094); |
437 %! assert(kurtosis(x),-6/5,0.0094); | 443 %! endif |
444 %!test | |
445 %! if (__random_statistical_tests__) | |
446 %! % statistical tests may fail occasionally. | |
447 %! rand("seed",12); | |
448 %! x = rand(100000,1); | |
449 %! assert(max(x)<1.); %*** Please report this!!! *** | |
450 %! assert(min(x)>0.); %*** Please report this!!! *** | |
451 %! assert(mean(x),0.5,0.0024); | |
452 %! assert(var(x),1/48,0.0632); | |
453 %! assert(skewness(x),0,0.012); | |
454 %! assert(kurtosis(x),-6/5,0.0094); | |
455 %! endif | |
438 */ | 456 */ |
439 | 457 |
440 | 458 |
441 static std::string current_distribution = octave_rand::distribution (); | 459 static std::string current_distribution = octave_rand::distribution (); |
442 | 460 |
489 return retval; | 507 return retval; |
490 } | 508 } |
491 | 509 |
492 /* | 510 /* |
493 %!test | 511 %!test |
494 %! % statistical tests may fail occasionally. | 512 %! % Test fixed state |
495 %! rand("state",12); | 513 %! randn("state",1); |
496 %! x = randn(100000,1); | 514 %! assert (randn(1,6), [-2.666521678978671 -0.7381719971724564 1.507903992673601 0.6019427189162239 -0.450661261143348 -0.7054431351574116],1e-15); |
497 %! assert(mean(x),0,0.01); | 515 %!test |
498 %! assert(var(x),1,0.02); | 516 %! % Test fixed state |
499 %! assert(skewness(x),0,0.02); | 517 %! randn("seed",1); |
500 %! assert(kurtosis(x),0,0.04); | 518 %! assert (randn(1,6), [-1.039402365684509 -1.25938892364502 0.1968704611063004 0.3874166905879974 -0.5976632833480835 -0.6615074276924133],1e-15); |
501 %!test | 519 %!test |
502 %! % statistical tests may fail occasionally. | 520 %! if (__random_statistical_tests__) |
503 %! rand("seed",12); | 521 %! % statistical tests may fail occasionally. |
504 %! x = randn(100000,1); | 522 %! randn("state",12); |
505 %! assert(mean(x),0,0.01); | 523 %! x = randn(100000,1); |
506 %! assert(var(x),1,0.02); | 524 %! assert(mean(x),0,0.01); |
507 %! assert(skewness(x),0,0.02); | 525 %! assert(var(x),1,0.02); |
508 %! assert(kurtosis(x),0,0.04); | 526 %! assert(skewness(x),0,0.02); |
527 %! assert(kurtosis(x),0,0.04); | |
528 %! endif | |
529 %!test | |
530 %! if (__random_statistical_tests__) | |
531 %! % statistical tests may fail occasionally. | |
532 %! randn("seed",12); | |
533 %! x = randn(100000,1); | |
534 %! assert(mean(x),0,0.01); | |
535 %! assert(var(x),1,0.02); | |
536 %! assert(skewness(x),0,0.02); | |
537 %! assert(kurtosis(x),0,0.04); | |
538 %! endif | |
509 */ | 539 */ |
510 | 540 |
511 DEFUN_DLD (rande, args, , | 541 DEFUN_DLD (rande, args, , |
512 "-*- texinfo -*-\n\ | 542 "-*- texinfo -*-\n\ |
513 @deftypefn {Loadable Function} {} rande (@var{x})\n\ | 543 @deftypefn {Loadable Function} {} rande (@var{x})\n\ |
550 return retval; | 580 return retval; |
551 } | 581 } |
552 | 582 |
553 /* | 583 /* |
554 %!test | 584 %!test |
555 %! % statistical tests may fail occasionally | 585 %! % Test fixed state |
556 %! rand("state",12); | 586 %! rande("state",1); |
557 %! x = rande(100000,1); | 587 %! assert (rande(1,6), [3.602973885835625 0.1386190677555021 0.6743112889616958 0.4512830847258422 0.7255744741233175 0.3415969205292291],1e-15); |
558 %! assert(min(x)>0); % *** Please report this!!! *** | 588 %!test |
559 %! assert(mean(x),1,0.01); | 589 %! % Test fixed state |
560 %! assert(var(x),1,0.03); | 590 %! rande("seed",1); |
561 %! assert(skewness(x),2,0.06); | 591 %! assert (rande(1,6), [0.06492075175653866 1.717980206012726 0.4816154008731246 0.5231300676241517 0.103910739364359 1.668931916356087],1e-15); |
562 %! assert(kurtosis(x),6,0.7); | 592 %!test |
563 %!test | 593 %! if (__random_statistical_tests__) |
564 %! % statistical tests may fail occasionally | 594 %! % statistical tests may fail occasionally |
565 %! rand("seed",12); | 595 %! rande("state",1); |
566 %! x = rande(100000,1); | 596 %! x = rande(100000,1); |
567 %! assert(min(x)>0); % *** Please report this!!! *** | 597 %! assert(min(x)>0); % *** Please report this!!! *** |
568 %! assert(mean(x),1,0.01); | 598 %! assert(mean(x),1,0.01); |
569 %! assert(var(x),1,0.03); | 599 %! assert(var(x),1,0.03); |
570 %! assert(skewness(x),2,0.06); | 600 %! assert(skewness(x),2,0.06); |
571 %! assert(kurtosis(x),6,0.7); | 601 %! assert(kurtosis(x),6,0.7); |
602 %! endif | |
603 %!test | |
604 %! if (__random_statistical_tests__) | |
605 %! % statistical tests may fail occasionally | |
606 %! rande("seed",1); | |
607 %! x = rande(100000,1); | |
608 %! assert(min(x)>0); % *** Please report this!!! *** | |
609 %! assert(mean(x),1,0.01); | |
610 %! assert(var(x),1,0.03); | |
611 %! assert(skewness(x),2,0.06); | |
612 %! assert(kurtosis(x),6,0.7); | |
613 %! endif | |
572 */ | 614 */ |
573 | 615 |
574 DEFUN_DLD (randg, args, , | 616 DEFUN_DLD (randg, args, , |
575 "-*- texinfo -*-\n\ | 617 "-*- texinfo -*-\n\ |
576 @deftypefn {Loadable Function} {} randg (@var{a}, @var{x})\n\ | 618 @deftypefn {Loadable Function} {} randg (@var{a}, @var{x})\n\ |
661 return retval; | 703 return retval; |
662 } | 704 } |
663 | 705 |
664 /* | 706 /* |
665 %!test | 707 %!test |
666 %! rand("state",12) | 708 %! randg("state",12) |
667 %!assert(randg([-inf,-1,0,inf,nan]),[nan,nan,nan,nan,nan]) % *** Please report | 709 %!assert(randg([-inf,-1,0,inf,nan]),[nan,nan,nan,nan,nan]) % *** Please report |
668 %!test | 710 |
669 %! % statistical tests may fail occasionally. | 711 |
670 %! a=0.1; x = randg(a,100000,1); | 712 %!test |
671 %! assert(mean(x), a, 0.01); | 713 %! % Test fixed state |
672 %! assert(var(x), a, 0.01); | 714 %! randg("state",1); |
673 %! assert(skewness(x),2/sqrt(a), 1.); | 715 %! assert (randg(0.1,1,6), [0.0103951513331241 8.335671459898252e-05 0.00138691397249762 0.000587308416993855 0.495590518784736 2.3921917414795e-12],1e-15); |
674 %! assert(kurtosis(x),6/a, 50.); | 716 %!test |
675 %!test | 717 %! % Test fixed state |
676 %! % statistical tests may fail occasionally. | 718 %! randg("state",1); |
677 %! a=0.95; x = randg(a,100000,1); | 719 %! assert (randg(0.95,1,6), [3.099382433255327 0.3974529788871218 0.644367450750855 1.143261091802246 1.964111762696822 0.04011915547957939],1e-15); |
678 %! assert(mean(x), a, 0.01); | 720 %!test |
679 %! assert(var(x), a, 0.04); | 721 %! % Test fixed state |
680 %! assert(skewness(x),2/sqrt(a), 0.2); | 722 %! randg("state",1); |
681 %! assert(kurtosis(x),6/a, 2.); | 723 %! assert (randg(1,1,6), [0.2273389379645993 1.288822625058359 0.2406335209340746 1.218869553370733 1.024649860162554 0.09631230343599533],1e-15); |
682 %!test | 724 %!test |
683 %! % statistical tests may fail occasionally. | 725 %! % Test fixed state |
684 %! a=1; x = randg(a,100000,1); | 726 %! randg("state",1); |
685 %! assert(mean(x),a, 0.01); | 727 %! assert (randg(10,1,6), [3.520369644331133 15.15369864472106 8.332112081991205 8.406211067432674 11.81193475187611 10.88792728177059],1e-14); |
686 %! assert(var(x),a, 0.04); | 728 %!test |
687 %! assert(skewness(x),2/sqrt(a), 0.2); | 729 %! % Test fixed state |
688 %! assert(kurtosis(x),6/a, 2.); | 730 %! randg("state",1); |
689 %!test | 731 %! assert (randg(100,1,6), [75.34570255262264 115.4911985594699 95.23493031356388 95.48926019250911 106.2397448229803 103.4813150404118],1e-13); |
690 %! % statistical tests may fail occasionally. | 732 %!test |
691 %! a=10; x = randg(a,100000,1); | 733 %! % Test fixed seed |
692 %! assert(mean(x), a, 0.1); | 734 %! randg("seed",1); |
693 %! assert(var(x), a, 0.5); | 735 %! assert (randg(0.1,1,6), [0.07144210487604141 0.460641473531723 0.4749028384685516 0.06823389977216721 0.000293838675133884 1.802567535340305e-12],1e-15); |
694 %! assert(skewness(x),2/sqrt(a), 0.1); | 736 %!test |
695 %! assert(kurtosis(x),6/a, 0.5); | 737 %! % Test fixed seed |
696 %!test | 738 %! randg("seed",1); |
697 %! % statistical tests may fail occasionally. | 739 %! assert (randg(0.95,1,6), [1.664905071258545 1.879976987838745 1.905677795410156 0.9948706030845642 0.5606933236122131 0.0766092911362648],1e-15); |
698 %! a=100; x = randg(a,100000,1); | 740 %!test |
699 %! assert(mean(x), a, 0.2); | 741 %! % Test fixed seed |
700 %! assert(var(x), a, 2.); | 742 %! randg("seed",1); |
701 %! assert(skewness(x),2/sqrt(a), 0.05); | 743 %! assert (randg(1,1,6), [0.03512085229158401 0.6488978862762451 0.8114678859710693 0.1666885763406754 1.60791552066803 1.90356981754303],1e-15); |
702 %! assert(kurtosis(x),6/a, 0.2); | 744 %!test |
703 %!test | 745 %! % Test fixed seed |
704 %! rand("seed",12) | 746 %! randg("seed",1); |
747 %! assert (randg(10,1,6), [6.566435813903809 10.11648464202881 10.73162078857422 7.747178077697754 6.278522491455078 6.240195751190186],1e-14); | |
748 %!test | |
749 %! % Test fixed seed | |
750 %! randg("seed",1); | |
751 %! assert (randg(100,1,6), [89.40208435058594 101.4734725952148 103.4020004272461 93.62763214111328 88.33104705810547 88.1871337890625],1e-13); | |
752 %!test | |
753 %! if (__random_statistical_tests__) | |
754 %! % statistical tests may fail occasionally. | |
755 %! randg("state",12) | |
756 %! a=0.1; x = randg(a,100000,1); | |
757 %! assert(mean(x), a, 0.01); | |
758 %! assert(var(x), a, 0.01); | |
759 %! assert(skewness(x),2/sqrt(a), 1.); | |
760 %! assert(kurtosis(x),6/a, 50.); | |
761 %! endif | |
762 %!test | |
763 %! if (__random_statistical_tests__) | |
764 %! % statistical tests may fail occasionally. | |
765 %! randg("state",12) | |
766 %! a=0.95; x = randg(a,100000,1); | |
767 %! assert(mean(x), a, 0.01); | |
768 %! assert(var(x), a, 0.04); | |
769 %! assert(skewness(x),2/sqrt(a), 0.2); | |
770 %! assert(kurtosis(x),6/a, 2.); | |
771 %! endif | |
772 %!test | |
773 %! if (__random_statistical_tests__) | |
774 %! % statistical tests may fail occasionally. | |
775 %! randg("state",12) | |
776 %! a=1; x = randg(a,100000,1); | |
777 %! assert(mean(x),a, 0.01); | |
778 %! assert(var(x),a, 0.04); | |
779 %! assert(skewness(x),2/sqrt(a), 0.2); | |
780 %! assert(kurtosis(x),6/a, 2.); | |
781 %! endif | |
782 %!test | |
783 %! if (__random_statistical_tests__) | |
784 %! % statistical tests may fail occasionally. | |
785 %! randg("state",12) | |
786 %! a=10; x = randg(a,100000,1); | |
787 %! assert(mean(x), a, 0.1); | |
788 %! assert(var(x), a, 0.5); | |
789 %! assert(skewness(x),2/sqrt(a), 0.1); | |
790 %! assert(kurtosis(x),6/a, 0.5); | |
791 %! endif | |
792 %!test | |
793 %! if (__random_statistical_tests__) | |
794 %! % statistical tests may fail occasionally. | |
795 %! randg("state",12) | |
796 %! a=100; x = randg(a,100000,1); | |
797 %! assert(mean(x), a, 0.2); | |
798 %! assert(var(x), a, 2.); | |
799 %! assert(skewness(x),2/sqrt(a), 0.05); | |
800 %! assert(kurtosis(x),6/a, 0.2); | |
801 %! endif | |
802 %!test | |
803 %! randg("seed",12) | |
705 %!assert(randg([-inf,-1,0,inf,nan]),[nan,nan,nan,nan,nan]) % *** Please report | 804 %!assert(randg([-inf,-1,0,inf,nan]),[nan,nan,nan,nan,nan]) % *** Please report |
706 %!test | 805 %!test |
707 %! % statistical tests may fail occasionally. | 806 %! if (__random_statistical_tests__) |
708 %! a=0.1; x = randg(a,100000,1); | 807 %! % statistical tests may fail occasionally. |
709 %! assert(mean(x), a, 0.01); | 808 %! randg("seed",12) |
710 %! assert(var(x), a, 0.01); | 809 %! a=0.1; x = randg(a,100000,1); |
711 %! assert(skewness(x),2/sqrt(a), 1.); | 810 %! assert(mean(x), a, 0.01); |
712 %! assert(kurtosis(x),6/a, 50.); | 811 %! assert(var(x), a, 0.01); |
713 %!test | 812 %! assert(skewness(x),2/sqrt(a), 1.); |
714 %! % statistical tests may fail occasionally. | 813 %! assert(kurtosis(x),6/a, 50.); |
715 %! a=0.95; x = randg(a,100000,1); | 814 %! endif |
716 %! assert(mean(x), a, 0.01); | 815 %!test |
717 %! assert(var(x), a, 0.04); | 816 %! if (__random_statistical_tests__) |
718 %! assert(skewness(x),2/sqrt(a), 0.2); | 817 %! % statistical tests may fail occasionally. |
719 %! assert(kurtosis(x),6/a, 2.); | 818 %! randg("seed",12) |
720 %!test | 819 %! a=0.95; x = randg(a,100000,1); |
721 %! % statistical tests may fail occasionally. | 820 %! assert(mean(x), a, 0.01); |
722 %! a=1; x = randg(a,100000,1); | 821 %! assert(var(x), a, 0.04); |
723 %! assert(mean(x),a, 0.01); | 822 %! assert(skewness(x),2/sqrt(a), 0.2); |
724 %! assert(var(x),a, 0.04); | 823 %! assert(kurtosis(x),6/a, 2.); |
725 %! assert(skewness(x),2/sqrt(a), 0.2); | 824 %! endif |
726 %! assert(kurtosis(x),6/a, 2.); | 825 %!test |
727 %!test | 826 %! if (__random_statistical_tests__) |
728 %! % statistical tests may fail occasionally. | 827 %! % statistical tests may fail occasionally. |
729 %! a=10; x = randg(a,100000,1); | 828 %! randg("seed",12) |
730 %! assert(mean(x), a, 0.1); | 829 %! a=1; x = randg(a,100000,1); |
731 %! assert(var(x), a, 0.5); | 830 %! assert(mean(x),a, 0.01); |
732 %! assert(skewness(x),2/sqrt(a), 0.1); | 831 %! assert(var(x),a, 0.04); |
733 %! assert(kurtosis(x),6/a, 0.5); | 832 %! assert(skewness(x),2/sqrt(a), 0.2); |
734 %!test | 833 %! assert(kurtosis(x),6/a, 2.); |
735 %! % statistical tests may fail occasionally. | 834 %! endif |
736 %! a=100; x = randg(a,100000,1); | 835 %!test |
737 %! assert(mean(x), a, 0.2); | 836 %! if (__random_statistical_tests__) |
738 %! assert(var(x), a, 2.); | 837 %! % statistical tests may fail occasionally. |
739 %! assert(skewness(x),2/sqrt(a), 0.05); | 838 %! randg("seed",12) |
740 %! assert(kurtosis(x),6/a, 0.2); | 839 %! a=10; x = randg(a,100000,1); |
840 %! assert(mean(x), a, 0.1); | |
841 %! assert(var(x), a, 0.5); | |
842 %! assert(skewness(x),2/sqrt(a), 0.1); | |
843 %! assert(kurtosis(x),6/a, 0.5); | |
844 %! endif | |
845 %!test | |
846 %! if (__random_statistical_tests__) | |
847 %! % statistical tests may fail occasionally. | |
848 %! randg("seed",12) | |
849 %! a=100; x = randg(a,100000,1); | |
850 %! assert(mean(x), a, 0.2); | |
851 %! assert(var(x), a, 2.); | |
852 %! assert(skewness(x),2/sqrt(a), 0.05); | |
853 %! assert(kurtosis(x),6/a, 0.2); | |
854 %! endif | |
741 */ | 855 */ |
742 | 856 |
743 | 857 |
744 DEFUN_DLD (randp, args, , | 858 DEFUN_DLD (randp, args, , |
745 "-*- texinfo -*-\n\ | 859 "-*- texinfo -*-\n\ |
803 return retval; | 917 return retval; |
804 } | 918 } |
805 | 919 |
806 /* | 920 /* |
807 %!test | 921 %!test |
808 %! rand("state",12) | 922 %! randp("state",12) |
809 %!assert(randp([-inf,-1,0,inf,nan]),[nan,nan,0,nan,nan]); % *** Please report | 923 %!assert(randp([-inf,-1,0,inf,nan]),[nan,nan,0,nan,nan]); % *** Please report |
810 %!test | 924 %!test |
925 %! % Test fixed state | |
926 %! randp("state",1); | |
927 %! assert(randp(5,1,6),[5 5 3 7 7 3]) | |
928 %!test | |
929 %! % Test fixed state | |
930 %! randp("state",1); | |
931 %! assert(randp(15,1,6),[13 15 8 18 18 15]) | |
932 %!test | |
933 %! % Test fixed state | |
934 %! randp("state",1); | |
935 %! assert(randp(1e9,1,6),[999915677 999976657 1000047684 1000019035 999985749 999977692]) | |
936 %!test | |
937 %! % Test fixed state | |
938 %! randp("seed",1); | |
939 %! assert(randp(5,1,6),[8 2 3 6 6 8]) | |
940 %!test | |
941 %! % Test fixed state | |
942 %! randp("seed",1); | |
943 %! assert(randp(15,1,6),[15 16 12 10 10 12]) | |
944 %!test | |
945 %! % Test fixed state | |
946 %! randp("seed",1); | |
947 %! assert(randp(1e9,1,6),[1000006208 1000012224 999981120 999963520 999963072 999981440]) | |
948 %!test | |
949 %! if (__random_statistical_tests__) | |
950 %! % statistical tests may fail occasionally. | |
951 %! randp("state",12) | |
952 %! for a=[5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03] | |
953 %! x = randp(a(1),100000,1); | |
954 %! assert(min(x)>=0); % *** Please report this!!! *** | |
955 %! assert(mean(x),a(1),a(2)); | |
956 %! assert(var(x),a(1),0.02*a(1)); | |
957 %! assert(skewness(x),1/sqrt(a(1)),a(3)); | |
958 %! assert(kurtosis(x),1/a(1),3*a(3)); | |
959 %! endfor | |
960 %! endif | |
961 %!test | |
962 %! if (__random_statistical_tests__) | |
963 %! % statistical tests may fail occasionally. | |
964 %! randp("state",12) | |
965 %! for a=[5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03] | |
966 %! x = randp(a(1)*ones(100000,1),100000,1); | |
967 %! assert(min(x)>=0); % *** Please report this!!! *** | |
968 %! assert(mean(x),a(1),a(2)); | |
969 %! assert(var(x),a(1),0.02*a(1)); | |
970 %! assert(skewness(x),1/sqrt(a(1)),a(3)); | |
971 %! assert(kurtosis(x),1/a(1),3*a(3)); | |
972 %! endfor | |
973 %! endif | |
974 %!test | |
975 %! randp("seed",12) | |
976 %!assert(randp([-inf,-1,0,inf,nan]),[nan,nan,0,nan,nan]); % *** Please report | |
977 %!test | |
811 %! % statistical tests may fail occasionally. | 978 %! % statistical tests may fail occasionally. |
812 %! for a=[5 15 1e9] | 979 %! randp("seed",12) |
813 %! x = randp(a,100000,1); | 980 %! for a=[5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03] |
981 %! x = randp(a(1),100000,1); | |
814 %! assert(min(x)>=0); % *** Please report this!!! *** | 982 %! assert(min(x)>=0); % *** Please report this!!! *** |
815 %! assert(mean(x),a,0.03); | 983 %! assert(mean(x),a(1),a(2)); |
816 %! assert(var(x),a,0.2); | 984 %! assert(var(x),a(1),0.02*a(1)); |
817 %! assert(skewness(x),1/sqrt(a),0.03); | 985 %! assert(skewness(x),1/sqrt(a(1)),a(3)); |
818 %! assert(kurtosis(x),1/a,0.08); | 986 %! assert(kurtosis(x),1/a(1),3*a(3)); |
819 %! end | 987 %! end |
820 %!test | 988 %!test |
821 %! % statistical tests may fail occasionally. | 989 %! % statistical tests may fail occasionally. |
822 %! for a=[5 15 1e9] | 990 %! randp("seed",12) |
823 %! x = randp(a*ones(100000,1),100000,1); | 991 %! for a=[5, 15, 1e9; 0.03, 0.03, -5e-3; 0.03, 0.03, 0.03] |
992 %! x = randp(a(1)*ones(100000,1),100000,1); | |
824 %! assert(min(x)>=0); % *** Please report this!!! *** | 993 %! assert(min(x)>=0); % *** Please report this!!! *** |
825 %! assert(mean(x),a,0.03); | 994 %! assert(mean(x),a(1),a(2)); |
826 %! assert(var(x),a,0.2); | 995 %! assert(var(x),a(1),0.02*a(1)); |
827 %! assert(skewness(x),1/sqrt(a),0.03); | 996 %! assert(skewness(x),1/sqrt(a(1)),a(3)); |
828 %! assert(kurtosis(x),1/a,0.08); | 997 %! assert(kurtosis(x),1/a(1),3*a(3)); |
829 %! end | |
830 %!test | |
831 %! rand("seed",12) | |
832 %!assert(randp([-inf,-1,0,inf,nan]),[nan,nan,0,nan,nan]); % *** Please report | |
833 %!test | |
834 %! % statistical tests may fail occasionally. | |
835 %! for a=[5 15 1e9] | |
836 %! x = randp(a,100000,1); | |
837 %! assert(min(x)>=0); % *** Please report this!!! *** | |
838 %! assert(mean(x),a,0.03); | |
839 %! assert(var(x),a,0.2); | |
840 %! assert(skewness(x),1/sqrt(a),0.03); | |
841 %! assert(kurtosis(x),1/a,0.08); | |
842 %! end | |
843 %!test | |
844 %! % statistical tests may fail occasionally. | |
845 %! for a=[5 15 1e9] | |
846 %! x = randp(a*ones(100000,1),100000,1); | |
847 %! assert(min(x)>=0); % *** Please report this!!! *** | |
848 %! assert(mean(x),a,0.03); | |
849 %! assert(var(x),a,0.2); | |
850 %! assert(skewness(x),1/sqrt(a),0.03); | |
851 %! assert(kurtosis(x),1/a,0.08); | |
852 %! end | 998 %! end |
853 */ | 999 */ |
854 | 1000 |
855 /* | 1001 /* |
856 ;;; Local Variables: *** | 1002 ;;; Local Variables: *** |