posner-ARJONA.lisp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #| set up inputs |#
  2. (setf input-1 (make-input :type :cue :location :centre :direction nil :store-time 0 :modality :visual))
  3. (setf input-2 (make-input :type :target :location nil :direction nil :store-time 0 :modality :auditory))
  4. (setf input-nil (make-input :location nil :direction nil :type nil :store-time 0 :modality nil))
  5. (setf test-input-1 (make-input :type :cue :location :centre :direction :left :store-time 0 :modality :visual))
  6. (setf test-input-2 (make-input :type :target :location :left :direction nil :store-time 0 :modality :auditory))
  7. (setf test-input-3 (make-input :type :target :location :right :direction nil :store-time 0 :modality :auditory))
  8. (defun get-cue-validity (input-pair)
  9. (if (equal (first input-pair)
  10. (second input-pair))
  11. "V" "I"))
  12. #| arjona specifics |#
  13. (setf *response-window* '(970 2070))
  14. (setf ntrials 100)
  15. (setf *strength-assoc* .5)
  16. (setf *cue-probs* '(.86 .68 .5))
  17. (defun create-stimuli (ntrials cue-validity-prob) ;;; creates a list of n cue-stimulus pairs
  18. (let* ((temp-list nil)
  19. (valid-n (round (* cue-validity-prob ntrials)))
  20. (invalid-n (- ntrials valid-n)))
  21. (append temp-list (make-list (/ valid-n 2) :initial-element '(:left :left))
  22. (make-list (/ valid-n 2) :initial-element '(:right :right))
  23. (make-list (/ invalid-n 2) :initial-element '(:left :right))
  24. (make-list (/ invalid-n 2) :initial-element '(:right :left)))))
  25. ;;(setf *cue-stimuli-list* (create-stimuli ntrials cue-validity))
  26. ;; target-response
  27. ;; timeline
  28. (defun timeline (time)
  29. (cond
  30. ((and (>= time 0) (< time 300)) 'NIL)
  31. ((and (>= time 300) (< time 600)) '((stim1 centre)))
  32. ((and (>= time 600) (< time 970)) 'NIL)
  33. ((and (>= time 970) (< time 1070)) '((stim2 nil)))
  34. ((and (>= time 1070) (< time 2070)) 'NIL)
  35. (t nil)))
  36. #| fitness values |#
  37. ;; the RT data is only for correct responses.
  38. (defvar *fitness-accuracy* 0.8) ; multiplier for f_a
  39. (defvar *fitness-time* 0.2) ; multiplier for f_t
  40. (defvar *fitness-size* 0.0) ; multiplier for f_s
  41. (defvar *data-rt-V-50* 376) ; parameter used in computing f_t
  42. (defvar *data-rt-I-50* 399)
  43. (defvar *data-acc-V-50* 0.9697) ; parameter used in computing f_a
  44. (defvar *data-acc-I-50* 0.949)
  45. (defvar *data-rt-V-68* 355)
  46. (defvar *data-rt-I-68* 394)
  47. (defvar *data-acc-V-68* 0.9708)
  48. (defvar *data-acc-I-68* 0.9568)
  49. (defvar *data-rt-V-86* 349)
  50. (defvar *data-rt-I-86* 404)
  51. (defvar *data-acc-V-86* 0.9623)
  52. (defvar *data-acc-I-86* 0.9155)
  53. (defstruct fitness-values
  54. prob-val
  55. rt-v
  56. rt-i
  57. acc-v
  58. acc-i)
  59. (setf *fit-vals*
  60. (list
  61. (make-fitness-values :prob-val 50 :rt-v *data-rt-V-50* :rt-i *data-rt-I-50* :acc-v *data-acc-V-50* :acc-i *data-acc-I-50*)
  62. (make-fitness-values :prob-val 68 :rt-v *data-rt-V-68* :rt-i *data-rt-I-68* :acc-v *data-acc-V-68* :acc-i *data-acc-I-68*)
  63. (make-fitness-values :prob-val 86 :rt-v *data-rt-V-86* :rt-i *data-rt-I-86* :acc-v *data-acc-V-86* :acc-i *data-acc-I-86*)
  64. ))
  65. #|
  66. ### Run experiment ###
  67. |#
  68. (defun run-experiment (program)
  69. "Run a single experiment against the given program, returning information on performance"
  70. (let* ((experiment-results '()))
  71. (dolist (cue-prob *cue-probs*)
  72. (let* ((cond-results '())
  73. (current-stimuli (alexandria:shuffle (create-stimuli ntrials cue-prob))))
  74. (setf s-a *strength-assoc*) ;; reset this between blocks
  75. (setf current-prob cue-prob) ;; this is *current-cue-validity* in old code
  76. (dolist (input-list current-stimuli)
  77. (setf (input-direction input-1) (first input-list))
  78. (setf (input-location input-2) (second input-list))
  79. (let* ((md (make-model :inputs (list input-1 input-2) :strength-assoc s-a :prev-trial pre-val)))
  80. ;; update the timeline info so know where the second stim is
  81. (setf (second (first (timeline (first *response-window*))))
  82. (input-location input-2))
  83. (interpret program md)
  84. (let* ((result (make-result :inputs input-list :validity (get-cue-validity input-list) :prob-valid cue-prob)))
  85. (when (AND (< (first *response-window*) (model-clock md)) (> (second *response-window*) (model-clock md))) ; when clock is before end time for response
  86. (setf (result-response result) (model-response md)) ; record model's response
  87. (setf (result-accuracy result) ; record accuracy
  88. (if (string= (result-response result) (second input-list)) 1 0))
  89. (setf (result-timing result) (- (model-clock md) (first *response-window*))) ; record the response time
  90. )
  91. (push result cond-results)
  92. (incf s-a (update-from-trial *ResWagrate* (model-strength-assoc md) (result-validity result)))
  93. (setf pre-val (result-validity result))
  94. )))
  95. (push cond-results experiment-results)))
  96. experiment-results))
  97. (defun run-gp (&key (max-generations 100)
  98. (population-size 1000)
  99. (f-a *fitness-accuracy*) ; proportion of accuracy objective to include in fitness
  100. (f-t *fitness-time*) ; proportion of response time objective
  101. (f-s *fitness-size*) ; proportion of program size objective
  102. ;;(rt *data-rt*) ; parameter for calculating response time objective
  103. ;;(acc *data-acc*) ; parameter for calculating accuracy objective
  104. (size 100) ; program size
  105. (logger nil) ; logger function
  106. (phased nil) ; set to t to use phased introduction
  107. ;;(fit-struct 1) ; default to fit all at the same time
  108. (mutation-rate 0.05)
  109. (i-depth 2) ;initial depth
  110. )
  111. "Sets all relevant parameters for the GP system and model evaluation"
  112. (setf
  113. *max-generations* max-generations
  114. *fitness-accuracy* f-a
  115. *fitness-time* f-t
  116. *fitness-size* f-s
  117. ;;*data-rt* rt ;; these are set in *fit-vals*
  118. ;;*data-acc* acc
  119. *size-ps* size
  120. *phased* phased
  121. *phase* 1 ; no need for this to change
  122. ;;*fit-struct* fit-struct
  123. )
  124. (gems:launch (operator-set) #'evaluate-fitness
  125. :total-generations max-generations
  126. :population-size population-size
  127. :initial-depth i-depth
  128. :maximum-depth 10
  129. :elitism t
  130. :type :steady-state
  131. :mutation-rate mutation-rate ; mutation-rate. default is 0.05. is a probability.
  132. :logger logger))