1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
;
; Alain Coulais, 5 Janvier 2011, under GNU GPL v2 or later
;
; few tests can help to check whether the
; computations are in good range or not
;
; ---------------------------------------
; because regression was introduced between July 17 and October 2
pro RANDOM_BASICS
;
a=RANDOMU(seed)
a=RANDOMU(1)
;
a=RANDOMU(seed, 12)
a=RANDOMU(1,12)
;
a=RANDOMU(seed, [12,3])
a=RANDOMU(1, [12,3])
;
end
;
; ---------------------------------------
;
pro RANDOM_GAMMA
;
window, 1
;
PLOT, HISTOGRAM(RANDOMN(SEED, 20000, gamma=1), BINSIZE=0.1)
OPLOT, HISTOGRAM(RANDOMN(SEED, 20000, gamma=2), BINSIZE=0.1)
OPLOT, HISTOGRAM(RANDOMN(SEED, 20000, gamma=3), BINSIZE=0.1)
OPLOT, HISTOGRAM(RANDOMN(SEED, 20000, gamma=4), BINSIZE=0.1)
;
end
;
; ------------------------------------------
;
; Idea: when the number is big enough, mean value
; of the realization should be close to the "value".
; If computation is wrong (e.g. calling bad noise, algo),
; we can expect not to have goor prediction ;-)
; (and this test fails "often" when NPB =< 100)
;
pro RANDOM_BINOMIAL, nbp=nbp, amplitude=amplitude, no_exit=no_exit, $
help=help, verbose=verbose, test=test
;
if KEYWORD_SET(help) then begin
print, 'pro RANDOM_BINOMIAL, nbp=nbp, amplitude=amplitude, no_exit=no_exit, $'
print, ' help=help, verbose=verbose, test=test'
return
endif
;
if ~KEYWORD_SET(nbp) then nbp=10000
if ~KEYWORD_SET(amplitude) then amplitude=10.
;
; Amplitude is a strictly posivite Integer
;
amplitude=FLOOR(amplitude)
if (amplitude EQ 1) then ratio=50. else ratio=100.
;
values=[0.10,0.25,0.50,0.75,0.90]
error=0
;
if KEYWORD_SET(verbose) then begin
print, format='(6A12)', ['Amplitude', 'values', 'expected', 'Mean', 'disp.', 'Error']
endif
for ii=0, N_ELEMENTS(values)-1 do begin
resu=RANDOMU(seed, nbp, BINOMIAL=[amplitude,values[ii]])
dispersion=ABS(MEAN(resu)-amplitude*values[ii])
if (dispersion GT amplitude/ratio) then error=error+1
if KEYWORD_SET(verbose) then begin
print, format='(i12,4f12,6x,I1.1)', amplitude, values[ii], $
amplitude*values[ii], MEAN(resu), dispersion, (dispersion GT amplitude/100.)
endif
;;
endfor
;
if KEYWORD_SET(test) then stop
;
if (error GT 0) then begin
MESSAGE, /continue, 'Error detected'
if ~KEYWORD_SET(no_exit) then EXIT, status=1
endif else begin
MESSAGE, /continue, 'success'
endelse
;
end
;
; ------------------------------------------
; extensions welcome
;
pro TEST_RANDOM, no_exit=no_exit, help=help, verbose=verbose, test=test
;
if KEYWORD_SET(help) then begin
print, 'pro TEST_RANDOM, no_exit=no_exit, help=help, verbose=verbose, test=test'
endif
;
RANDOM_BASICS
;
RANDOM_GAMMA
;
RANDOM_BINOMIAL, verbose=verbose, test=test, no_exit=no_exit, ampl=1.
RANDOM_BINOMIAL, verbose=verbose, test=test, no_exit=no_exit, ampl=1.5
RANDOM_BINOMIAL, verbose=verbose, test=test, no_exit=no_exit, ampl=10.
RANDOM_BINOMIAL, verbose=verbose, test=test, no_exit=no_exit, ampl=100.
;
end
|