(defun runPom2(type &optional (treatment nil)) (if (not (null treatment)) (clampValue treatment :reset t)) ;Outside of this function the clamped values are supposed to be clamped and ;POM2 completes the values when POM2 i runing (let ((conntinue 1) (scores '()) (minIterations 1) (maxIterations 1) (iteration 0)) ;run at least minIterations and at most maxIterations ;between there the cont function tells if to terminate (while (and (or conntinue (< iteration minIterations)) (< iteration maxIterations)) (progn (incf iteration) (push (score (POM2 1 type)) scores) (setf conntinue (cont scores)))) ;(format t "~A, " iteration) (nDecimal (myMean scores) 4))) (defun cont (scores) ;This is the function that terminates the simulation (if (< (standardDev scores) 0.05) nil 1)) (defun standardDev (scores) ;Calculates the standard deviation (let ((xBar (myMean scores))) (if (second scores) (sqrt (/ (apply #'+ (mapcar #'(lambda (x) (* (- x xBar) (- x xBar))) scores)) (- (length scores) 1))) 10000))) (defun myMean (scores) ;Calculates the mean (/ (apply #'+ scores) (length scores)))