Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: [OT] - probability algorithm question

Author: David Hanley

Date: 11:22:51 12/31/01

Go up one level in this thread


I think the best way to do this is to:

1) Build up a pool of _n_ entries

2) put the first _n_ results into this pool

3) For result _c_ past _n_ put them into the pool with a probability of 1/(c/n)
of replacing element random(n).  At every point, the pool will resemble a
statitical sample of all the results thus far.

4) You can carry out your statistical tests on this pool.  It should broadly
match the results you'd get on the entire amount.

I thought this was pretty nteresting, so i decided to hack up some quick code to
test it:

(defun make-pool( size )
  (let ((pool (make-array size :fill-pointer 0))
        (added 0))
    #'(lambda( item )
        (if (< added size)
            (vector-push item pool)
          (if (< (random 1.0) (/ 1.0 (/ added size)))
              (setf (aref pool (random size)) item)))
        (incf added)
        (values pool added))))

; some testing code:

(defun average( x )
  (/ (reduce #'+ x) (length x)))

(defun test-pool(size items)
  (let ((mp (make-pool size))
        (arr nil))
    (loop for x below items do (setf arr (funcall mp x)))
    (format t "average for a pool of size ~d for numbers to ~d is ~d~%"
            size items (float (average arr)))))


i ran some tests and it seems to work OK

CL-USER 26 : 2 > (loop repeat 10 do (test-pool 50 1000))
average for a pool of size 50 for numbers to 1000 is 463.5
average for a pool of size 50 for numbers to 1000 is 591.66
average for a pool of size 50 for numbers to 1000 is 505.12
average for a pool of size 50 for numbers to 1000 is 451.14
average for a pool of size 50 for numbers to 1000 is 498.52
average for a pool of size 50 for numbers to 1000 is 561.76
average for a pool of size 50 for numbers to 1000 is 486.5
average for a pool of size 50 for numbers to 1000 is 514.26
average for a pool of size 50 for numbers to 1000 is 469.4
average for a pool of size 50 for numbers to 1000 is 465.92
NIL





This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.