(defun new-random-grove (min max min.sd max.sd &optional (mu 1.5181932) (tau 0.0036737733) (timespersd 10000) (filename "randomdata.dat")) (let ((x 0) (y 0) (tempval 0)) (with-open-file (out filename :direction :output :if-exists :supersede) (format out "### splot '~a' index 0" filename) (dotimes (i (- max.sd min.sd)) (format out ", '~a' index ~a" filename (+ i 1))) (dotimes (i (+ (- max.sd min.sd) 1)) ;(format out "~%~%###SD: ~a~%" (+ i 1)) (format out "~%~%###SD: ~a~%" (+ i min.sd)) (dotimes (j timespersd) (setf x (+ (random (- max min)) min)) (setf y (+ (random (- max min)) min)) (handler-case (progn (setf tempval (grovenew x y (* (+ i 1) (expt 10 -5)) mu tau))) (floating-point-overflow () (setf tempval 10))) (if (> tempval 10) (setf tempval 10)) (format out "~a ~a ~a~%" x y tempval)))) 'done)) (defun grovenew (x y sd &optional (mu 1.5181932) (tau 0.0036737733)) (let* ((u (/ tau sd)) (v (/ (* (- x y)(- x y) ) (* -4 sd sd) )) (w (/ (* (- y mu)(- y mu) ) (* 2 tau tau))) (lr (* u (exp ( + v w ))))) lr)) (defun handle-grove (x y sd &optional (mu 1.5181932) (tau 0.0036737733) (maxallowed 10) (filename "sliderdata.dat")) (let (tempval) (handler-case (progn (setf tempval (grovenew x y sd mu tau))) (floating-point-overflow () (setf tempval maxallowed))) (if (> tempval maxallowed) (setf tempval maxallowed)) (with-open-file (out filename :direction :output :if-exists :supersede) (format out "~a ~a ~a" x y tempval)) tempval))