Jump to content

prob-mutation


Recommended Posts

(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)


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy