Commit c72f51dd authored by liam's avatar liam
Browse files

Use random number generators inside with-gsl-objects.


git-svn-id: svn+ssh://pop/opt/space/mathematics/gsl/trunk@3278 a3d8a0fb-c1db-0310-ace7-a616afeb9e30
parent ac62a39f
;; Generators of random numbers. ;; Generators of random numbers.
;; Liam Healy, Sat Jul 15 2006 - 14:43 ;; Liam Healy, Sat Jul 15 2006 - 14:43
;; Time-stamp: <2008-01-21 11:47:49EST generators.lisp> ;; Time-stamp: <2008-01-31 22:43:53EST generators.lisp>
;; $Id: $ ;; $Id: $
(in-package :gsl) (in-package :gsl)
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
:generator generator))) :generator generator)))
(if (eq generator t) (alloc instance) instance))) (if (eq generator t) (alloc instance) instance)))
(set-asf random-number-generator make-random-number-generator free rng-set 1)
;;;;**************************************************************************** ;;;;****************************************************************************
;;;; Initialization ;;;; Initialization
;;;;**************************************************************************** ;;;;****************************************************************************
...@@ -248,18 +250,18 @@ ...@@ -248,18 +250,18 @@
(lisp-unit:define-test random-number-generators (lisp-unit:define-test random-number-generators
(lisp-unit:assert-equal (lisp-unit:assert-equal
'(999 162 282 947 231 484 957 744 540 739 759) '(999 162 282 947 231 484 957 744 540 739 759)
(progn (with-gsl-objects ((random-number-generator rng *mt19937* 0))
(rng-set *rng-mt19937* 0)
(loop for i from 0 to 10 (loop for i from 0 to 10
collect collect
(uniform-fixnum *rng-mt19937* 1000)))) (uniform-fixnum rng 1000))))
(lisp-unit:assert-equal (lisp-unit:assert-equal
'("0.111776229978d+00" "0.959166794996d+00" "0.841526801158d+00" '("0.111776229978d+00" "0.959166794996d+00" "0.841526801158d+00"
"0.925403713680d+00" "0.275406984741d+00" "0.709304057392d+00" "0.925403713680d+00" "0.275406984741d+00" "0.709304057392d+00"
"0.554133304187d+00" "0.880695776958d+00" "0.597139396983d+00" "0.554133304187d+00" "0.880695776958d+00" "0.597139396983d+00"
"0.751874113340d+00" "0.931108462127d+00") "0.751874113340d+00" "0.931108462127d+00")
(lisp-unit:fp-sequence (lisp-unit:fp-sequence
(progn (with-gsl-objects ((random-number-generator rng *cmrg* 0))
(rng-set *rng-cmrg* 0) (loop for i from 0 to 10 collect (uniform rng))))))
(loop for i from 0 to 10
collect (uniform *rng-cmrg*))))))
;; Quasi-random sequences in arbitrary dimensions. ;; Quasi-random sequences in arbitrary dimensions.
;; Liam Healy, Sun Jul 16 2006 - 15:54 ;; Liam Healy, Sun Jul 16 2006 - 15:54
;; Time-stamp: <2008-01-21 11:39:10EST quasi.lisp> ;; Time-stamp: <2008-01-31 22:52:29EST quasi.lisp>
;; $Id: $ ;; $Id: $
(in-package :gsl) (in-package :gsl)
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
(defparameter *default-quasi-random-number-generator* nil) (defparameter *default-quasi-random-number-generator* nil)
(set-asf quasi-random-number-generator
make-quasi-random-number-generator free nil 2)
(defun make-quasi-random-number-generator (defun make-quasi-random-number-generator
(dimension (dimension
&optional (type *default-quasi-random-number-generator*) &optional (type *default-quasi-random-number-generator*)
...@@ -126,10 +129,9 @@ ...@@ -126,10 +129,9 @@
(lisp-unit:assert-equal (lisp-unit:assert-equal
'(0.5d0 0.5d0 0.75d0 0.25d0 0.25d0 0.75d0 0.375d0 0.375d0 0.875d0 0.875d0) '(0.5d0 0.5d0 0.75d0 0.25d0 0.25d0 0.75d0 0.375d0 0.375d0 0.875d0 0.875d0)
(with-data (vec vector-double 2) (with-data (vec vector-double 2)
(let ((gen (make-quasi-random-number-generator 2 *sobol*))) (with-gsl-objects ((quasi-random-number-generator gen 2 *sobol*))
(init gen) (loop repeat 5
(prog1 do (qrng-get gen vec)
(loop repeat 5 append (coerce (data vec) 'list))))))
do (qrng-get gen vec)
append (coerce (data vec) 'list))
(free gen))))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment