Jump to content



Recommended Posts

if you want to modify "a weight" from GEN-generation to next GEN-generation you could use this...

(modifying a weight could be useful if you want to give your production-rules a global drift)




(defun modify-weight (&key weight (step 0.1) type (threshold 0.5) (span '(0 1)) (max-weight 1.0))
  (cond ((or (equal type 'incr) (equal type 'decr)) (progn 
                                                      (setq weight (cond ((equal type 'incr) (incf weight step))
                                                                         ((equal type 'decr) (decf weight step))))
                                                      (if (and (> weight 0) (< weight max-weight))
                                                        (append weight)
                                                        (cond ((>= weight max-weight) (random (- 1 threshold)))
                                                              ((<= weight 0) (+ (random (- 1 threshold)) threshold))))))
        ((equal type 'incr-noreset) (if (< weight max-weight)
                                      (incf weight step)
                                      (append max-weight)))
        ((equal type 'decr-noreset) (if (> weight 0)
                                      (decf weight step)
                                      (append 0)))        
        ((equal type 'rnd) (+ (random (- 1 threshold)) threshold))
        ((equal type 'rnd-span) (rnd-round (first span) (second span)))))

;;; EXAMPLES TO TEST THE FUNCTION -> ev. every example a few times to check it

(setf weight 0.1)
;;; counts up until default-max-weight (1.0), then rnd-reset
(setf weight (modify-weight :type 'incr :weight weight :step 0.2))

(setf weight 0.1)
;;; counts up, stays at max-weight
(setf weight (modify-weight :type 'incr-noreset :weight weight :step 0.2 :max-weight 3.0))

(setf weight 1.0)
;;; counts down until 0, then rnd-reset
(setf weight (modify-weight :type 'decr :weight weight :step 0.1))

(setf weight 1.0)
;;; counts up, stays at 0
(setf weight (modify-weight :type 'decr-noreset :weight weight :step 0.1))

(setf weight 1.0)
;;; rnd-weights, larger then threshold
(setf weight (modify-weight :type 'rnd :threshold 0.3))

(setf weight 1.0)
;;; rnd-weights, in SPAN
(setf weight (modify-weight :type 'rnd-span  :span '(0.3 0.6)))



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.

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