Posted September 1, 20231 yr (defun prob-mutation (alist blist &key (factor 1) (prob-list nil)) (loop for a in alist for b in blist for x in (if (null prob-list) (cumulative-sums (gen-repeat (length alist) (float (/ factor (length alist))))) prob-list) when (probp x) collect b else collect a)) ;;; with linear prob-incf (prob-mutation (gen-repeat 100 1) (gen-repeat 100 2)) => (1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 2 2 1 2 2 2 1 1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 2 1 1 2 2 2 2 1 1 2 2 2 1 1 2 1 1 1 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2) ;;; with an external prob-list 0 to 1.0 to 0 (setf half-sine (filter-first 100 (gen-sine 200 1 1.0))) (prob-mutation (gen-repeat 100 1) (gen-repeat 100 2) :prob-list half-sine) => (1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 1 2 1 2 1 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 1 1 2 2 2 2 2 2 2 1 1 2 1 2 1 2 1 1 2 1 1 2 1 1 1 2 1 1) ;;; with an external prob-list 0 to 0.3 to 0 (setf half-sine (filter-first 100 (gen-sine 200 1 0.3))) (prob-mutation (gen-repeat 100 1) (gen-repeat 100 2) :prob-list half-sine) => (1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 2 1 1 1 2 1 1 1 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 2 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1)
Create an account or sign in to comment