Jump to content

modify proportion-list for "gen-length-constant"


Recommended Posts

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;; A WAY TO MUTATE/MODIFY A PROPORTION-LIST FOR "gen-length-constant"
;;;; the SUM in all generations is CONSTANT

;;;; FUNCTION
(defun modify-prop-seq (generations values &key (value-step 1) (chance 1.0))
  (append (list values)
          (loop repeat (- generations 1)
            with rnd-seq 
            with new-seq
            
            do (if (prob? chance)
                 (setq rnd-seq (rnd-sample-seq 2 values)
                       new-seq (list (+ (car rnd-seq) value-step) (- (car (rest rnd-seq)) value-step))
                       values (loop for i in (pattern-map  (list (append (list rnd-seq) (list new-seq))) values)
                                when (> i 0) 
                                collect i))
                 (append values))
            
            collect values)))

;;;; tests
(modify-prop-seq 5 '(1 2 3 4 5 6 7 8 9))
(modify-prop-seq 5 '(2 1 8 5 1 3) :value-step 1 :chance 0.9)
(modify-prop-seq 5 '(4 4 4 4 4) :value-step 1 :chance 0.5)


;;;; practical-use -> every generation in 1 bar
(loop for i in (modify-prop-seq 5 '(2 1 8 5 1 3) :value-step 1 :chance 0.8)
  collect (gen-length-constant i '4/4))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

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