posner-initialise.lisp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. ;; This file specifies the operators for the DMTS tasks
  2. ;; - defines: timings; 'detect-main'; 'decay'; 'interpret'; 'operator-set'; 'dotted-replace'; 'clean-and-save'; 'check-fitness'; structures: input, model
  3. (defparameter $inputT 100) ;; perception + attend
  4. (defparameter $outputT 140) ;; intend + movement
  5. (defparameter $cogT 70) ;; basic cognitive process
  6. (defparameter $stmT 50) ;; basic STM process
  7. (defparameter $syntaxT 0) ;; prog2, if ;; these are different from cognitive operators
  8. (defparameter $learningT 0) ;; might just make this cog...
  9. (defun check-fitness (overall-fitness program)
  10. (when (< overall-fitness .10) ;; changed from .10
  11. (let ((ms (format nil
  12. "~%Good-fit!~%Fitness =====> ~4,3F
  13. ~A~%----------------------------------"
  14. overall-fitness program) )) ; overall-fitness *rand* program) ))
  15. (format t "~A" ms)
  16. (break ms)
  17. )))
  18. ;;(defvar *ResWagrate* .05) ;; rate of learning for Rescola-Wagner operator; [what is a good value based on the literature?]
  19. #|
  20. ### Setting up structures ###
  21. |#
  22. (defstruct input
  23. ;;(name 0)
  24. (location :centre)
  25. (type :stimulus)
  26. (direction nil)
  27. (modality nil)
  28. (store-time nil))
  29. (defstruct model
  30. "Defines the state of a model and its interactions with the environment"
  31. (clock 0)
  32. (current input-nil)
  33. (stm (list input-nil input-nil input-nil))
  34. (attFocus :centre) ;; focus of attention; default is centre
  35. (salient input-nil) ;; salient is what is salient in the visual field.
  36. response
  37. inputs ;; buffers for inputs
  38. strength-assoc
  39. prev-trial
  40. _screenLeft
  41. _screenCentre
  42. _screenRight
  43. ( _inputName "_")
  44. ( _type :stimulus))
  45. (defstruct result
  46. inputs
  47. (response "-")
  48. validity
  49. prob-valid
  50. (accuracy 0)
  51. (timing 0))
  52. #|
  53. ### detect-main ###
  54. |#
  55. (defun detect-main (md)
  56. (let ((current-stimuli (timeline (model-clock md))) ;; (stim1 centre) (stim2 nil)
  57. (att (model-attFocus md))
  58. (stim nil))
  59. ;; for this experiment theres only ever 1 stimulus at a time - need to change this if not the case anymore
  60. (when (equal (first (first current-stimuli)) 'stim2)
  61. (setf (second (first current-stimuli)) (input-location (second (model-inputs md)))))
  62. (setf stim (first (find-if #'(lambda (y)
  63. (equal (symbol-name (second y)) (symbol-name att)))
  64. current-stimuli)))
  65. (if stim
  66. (setf (model-salient md)
  67. (nth (- (parse-integer (subseq (symbol-name stim) 4)) 1) (model-inputs md)))
  68. (setf (model-salient md) input-nil)
  69. )))
  70. ;; for different implementations of decay see DMTS initialise
  71. #|
  72. ### decay ###
  73. |#
  74. ;;ACT-R DECAY BUFFER VERSION OF DECAY:
  75. (defun decay (md)
  76. (when (equal decay-toggle 1) ;; if we want decay
  77. (dotimes (y (length (model-stm md))) ;; for each item in stm
  78. (when (not (equal (input-store-time (nth y (model-stm md))) nil)) ;; check that the item is a thing, i.e. store-time isn't nil
  79. (let* ((temp-stim (nth y (model-stm md))) ;; save the stm-item as temp-stim
  80. (*time (/ (- (model-clock md) (input-store-time temp-stim)) 1000)) ;; time stored (s)
  81. (activation (- 1 (* 0.4 (log (+ 1 *time))))))
  82. (when (< activation *decay-threshold*) (setf (nth y (model-stm md)) input-nil))))))) ;; get rid if less than decay threshold
  83. #|
  84. ### Learning functions ###
  85. |#
  86. (defvar *ResWagrate* .1) ;; rate of learning for Rescola-Wagner operator; [what is a good value based on the literature?]
  87. ;; seems its mostly estimated from the data - i have increased it as it was doing very little before - but unsure what value to use.
  88. (defun Rescola-Wagner (alpha lambda V)
  89. "output delta-V (change in strength of association); alpha = rate of change; lambda = max value of current strenght of association;
  90. V = current strength of association"
  91. (* alpha (- lambda V)))
  92. (defun update-from-trial (rate strength el)
  93. "Updates strength of association after one trial. Outputs delta-V. Used in GEMS"
  94. ;;(print (list rate strength el))
  95. (cond ((equal el "V")
  96. (Rescola-Wagner rate 1.0 strength)) ;; max = 1.0
  97. ((equal el "I")
  98. (Rescola-Wagner rate 0.0 strength)) ;; min = 0.0
  99. (t (error "wrong element"))))
  100. (defun RW-predict-stim (strength-association cue)
  101. "Used in GEMS operator.
  102. (a) Input is strength-association. Outputs stimulus given cue. Pure anticipation: uses only cue, not stimulus itself.
  103. (b) Input is (priming strength-association). Combines info about cue and stimulus"
  104. (let ((p (random 1.0)))
  105. (cond ((equal cue :left)
  106. (if (< p strength-association) :left :right))
  107. ((equal cue :right)
  108. (if (< p strength-association) :right :left))
  109. ;; (t (error "wrong cue"))
  110. ))) ;; if it isn't 1 or 2, then its the default and nothings been put into stm - so just do nothing.
  111. ;;
  112. (setf pre-val "")
  113. #|
  114. ### convenience functions ###
  115. |#
  116. ;; These convenience functions allow interpret/display-pseudocode to
  117. ;; work with both s-expressions and syntax-tree:node structures.
  118. (defun operator-label (operator)
  119. "Returns label of given operator"
  120. (typecase operator
  121. (list
  122. (intern (symbol-name (first operator)) "KEYWORD"))
  123. (syntax-tree:node
  124. (intern (symbol-name (syntax-tree:node-label operator)) "KEYWORD"))
  125. (otherwise
  126. (error "Invalid operator type"))))
  127. (defun operator-children (operator)
  128. "Returns children of given operator"
  129. (typecase operator
  130. (list
  131. (rest operator))
  132. (syntax-tree:node
  133. (syntax-tree:node-children operator))
  134. (otherwise
  135. (error "Invalid operator type"))))
  136. #|
  137. ### Fitness functions ###
  138. |#
  139. (defun fitness-accuracy (accuracy d-a)
  140. "Computes the f_a objective function: 100% is target mean accuracy."
  141. ;;(abs (- 1.0 accuracy)))
  142. (/ (abs (- accuracy d-a)) d-a))
  143. (defun fitness-acc-sd (accuracy-sd d-a)
  144. "Computes the f_a objective function: 100% is target mean accuracy."
  145. ;;(abs (- 1.0 accuracy)))
  146. (/ (abs (- accuracy-sd d-a)) d-a))
  147. (defun fitness-time (response-time d-rt)
  148. "Computes the f_t objective function."
  149. ;;(gems:half-sigmoid (/ (abs (- response-time 200)) *time-rt*)))
  150. ;;(/ (abs (- response-time *data-rt*)) *data-rt*))
  151. (gems:half-sigmoid (/ (abs (- response-time d-rt)) d-rt)))
  152. (defun fitness-size (program-size)
  153. "Computes the f_s objective function"
  154. (gems:half-sigmoid (/ program-size *size-ps*)))
  155. #|
  156. (defun fitness-no-phase (f-a f-t f-s)
  157. "Computes the overall fitness"
  158. (+ (* *fitness-accuracy* f-a)
  159. (* *fitness-time* f-t)
  160. (* *fitness-size* f-s)))
  161. (defun fitness-for-phase (f-a f-t f-s)
  162. "Computes the fitness for current phase"
  163. (case *phase*
  164. (1 ; single objective
  165. f-a)
  166. (2 ; two objectives
  167. (/ (+ (* *fitness-accuracy* f-a)
  168. (* *fitness-time* f-t))
  169. (+ *fitness-accuracy* *fitness-time*)))
  170. (otherwise ; all three objectives
  171. (fitness-no-phase f-a f-t f-s))))
  172. (defun overall-phased-fitness (f-a f-t f-s)
  173. "Computes fitness, using the phases"
  174. (when (and (<= *phase* 3) ;; this is wrong no? will never do anything with phase 3? changed from <
  175. (< (fitness-for-phase f-a f-t f-s) 0.1)) ;; changed from 0.1
  176. (incf *phase*))
  177. (fitness-for-phase f-a f-t f-s))
  178. |#
  179. (defun fitness-no-phase (f-a f-t f-s)
  180. "Computes the overall fitness - LB edit for Posner"
  181. (let* ((acc-weight (/ *fitness-accuracy* (length f-a))) ;; weight for each indiv data point
  182. (rt-weight (/ *fitness-time* (length f-t))))
  183. (+ (reduce #'+ (mapcar #'(lambda (x) (* x acc-weight)) f-a))
  184. (reduce #'+ (mapcar #'(lambda (x) (* x rt-weight)) f-t))
  185. (* *fitness-size* f-s))))
  186. (defun fitness-for-phase (f-a f-t f-s)
  187. "Computes the fitness for current phase - LB edit for Posner"
  188. (case *phase*
  189. (1 ; single objective
  190. (reduce #'+ (mapcar #'(lambda (x) (* x (/ 1 (length f-a)))) f-a))) ;; just split the weight between each
  191. (2 ; two objectives
  192. (let* ((acc-weight (/ *fitness-accuracy* (length f-a))) ;; weight for each indiv data point
  193. (rt-weight (/ *fitness-time* (length f-t))))
  194. (/ (+ (reduce #'+ (mapcar #'(lambda (x) (* x acc-weight)) f-a))
  195. (reduce #'+ (mapcar #'(lambda (x) (* x rt-weight)) f-t)))
  196. (+ *fitness-accuracy* *fitness-time*))))
  197. (otherwise ; all three objectives
  198. (fitness-no-phase f-a f-t f-s))))
  199. (defun overall-phased-fitness (f-a f-t f-s)
  200. "Computes fitness, using the phases"
  201. (when (and (< *phase* 3)
  202. (< (fitness-for-phase f-a f-t f-s) 0.1))
  203. (incf *phase*))
  204. (fitness-for-phase f-a f-t f-s))
  205. ;; order of results - .5, .68, .86 (100 trials of each, each in its own list - so all-results is 3 lists of 100 items
  206. (defun evaluate-fitness (individual)
  207. (let* ((program (gems:individual-tree individual))
  208. (all-results (run-experiment program))
  209. ;; details for the progam-size (will be the same for all the conditions)
  210. (program-size (gems:program-size program))
  211. (temp-size (fitness-size program-size))
  212. ;; set up to save fit vals
  213. (temp-rt nil)
  214. (temp-acc nil)
  215. (mean-rt nil)
  216. (mean-acc nil)
  217. )
  218. (dotimes (prob-count (length all-results)) ;; each block validity
  219. (let* ((prob-val (nth prob-count all-results))
  220. ;; separate the valid and invalid trials
  221. (valid-trials (remove-if-not #'(lambda (x) (equal (result-validity x) "V")) prob-val))
  222. (invalid-trials (remove-if #'(lambda (x) (equal (result-validity x) "V")) prob-val))
  223. ;; get the mean and the fitness value for each condition
  224. (rt-V-mean (alexandria:mean (mapcar #'result-timing valid-trials))) ;; this is just 1 value
  225. (rt-v-fit (fitness-time rt-V-mean (fitness-values-rt-v (nth prob-count *fit-vals*))))
  226. (rt-I-mean (alexandria:mean (mapcar #'result-timing invalid-trials)))
  227. (rt-i-fit (fitness-time rt-I-mean (fitness-values-rt-i (nth prob-count *fit-vals*))))
  228. (acc-V-mean (alexandria:mean (mapcar #'result-accuracy valid-trials)))
  229. (acc-v-fit (fitness-accuracy acc-V-mean (fitness-values-acc-v (nth prob-count *fit-vals*))))
  230. (acc-I-mean (alexandria:mean (mapcar #'result-accuracy invalid-trials)))
  231. (acc-i-fit (fitness-accuracy acc-I-mean (fitness-values-acc-i (nth prob-count *fit-vals*))))
  232. (overall-fitness 1.0)
  233. )
  234. ;; save the fit values to a list
  235. (setf temp-rt (append temp-rt (list rt-v-fit rt-i-fit)))
  236. (setf temp-acc (append temp-acc (list acc-v-fit acc-i-fit)))
  237. (setf mean-rt (append mean-rt (list rt-V-mean rt-I-mean)))
  238. (setf mean-acc (append mean-acc (list acc-V-mean acc-I-mean)))
  239. ))
  240. (setf overall-fitness
  241. (if *phased*
  242. (overall-phased-fitness temp-acc temp-rt temp-size)
  243. (fitness-no-phase temp-acc temp-rt temp-size)))
  244. (values overall-fitness
  245. ;;(list accuracy f-a response-time f-t program-size f-s *phased* *phase* run-details))))
  246. (list mean-rt mean-acc temp-rt temp-acc program-size temp-size *phased* *phase*))))
  247. #|
  248. ### interpret ###
  249. |#
  250. ;; interpret function evaluates the given operator (program), in the context of
  251. ;; md, which is a model+environment definition
  252. (defun interpret (operator md)
  253. ;;(when (equalp nil (model-response md))
  254. (when (syntax-tree:node-p operator) (incf (syntax-tree:node-entries operator)))
  255. (unless (> (model-clock md) 10000) ; time-out - adjust this if required
  256. (case (operator-label operator)
  257. (:nil
  258. (incf (model-clock md) $cogT)
  259. (setf (model-current md) input-nil))
  260. #|
  261. ;;prog-functions
  262. |#
  263. (:prog2
  264. (incf (model-clock md) $syntaxT)
  265. (interpret (first (operator-children operator)) md)
  266. (interpret (second (operator-children operator)) md))
  267. (:prog3
  268. (incf (model-clock md) $syntaxT)
  269. (interpret (first (operator-children operator)) md)
  270. (interpret (second (operator-children operator)) md)
  271. (interpret (third (operator-children operator)) md))
  272. (:prog4
  273. (incf (model-clock md) $syntaxT)
  274. (interpret (first (operator-children operator)) md)
  275. (interpret (second (operator-children operator)) md)
  276. (interpret (third (operator-children operator)) md)
  277. (interpret (fourth (operator-children operator)) md))
  278. #|
  279. ;;while, wait, dotime functions
  280. |#
  281. (:while-100
  282. (incf (model-clock md) $syntaxT)
  283. (let ((start-time (model-clock md)))
  284. (do ((x 1 (incf x))) ;; as a safeguard...
  285. ((or (>= (model-clock md) (+ start-time 100))
  286. (> x 4))) ;; as a safeguard...
  287. (interpret (first (operator-children operator)) md))))
  288. (:while-200
  289. (incf (model-clock md) $syntaxT)
  290. (let ((start-time (model-clock md)))
  291. (do ((x 1 (incf x))) ;; as a safeguard...
  292. ((or (>= (model-clock md) (+ start-time 200))
  293. (> x 5))) ;; as a safeguard...
  294. (interpret (first (operator-children operator)) md))))
  295. (:wait-.5trial
  296. (incf (model-clock md) (/ (second *response-window*) 2)))
  297. (:wait-.25trial
  298. (incf (model-clock md) (/ (second *response-window*) 4)))
  299. (:wait-.1trial
  300. (incf (model-clock md) (/ (second *response-window*) 10)))
  301. (:wait-25
  302. (incf (model-clock md) 25))
  303. (:wait-50
  304. (incf (model-clock md) 50))
  305. (:wait-100
  306. (incf (model-clock md) 100))
  307. (:wait-200
  308. (incf (model-clock md) 200))
  309. (:wait-1000
  310. (incf (model-clock md) 1000))
  311. (:wait-1500
  312. (incf (model-clock md) 1500))
  313. (:dotimes-2
  314. (incf (model-clock md) $syntaxT)
  315. (dotimes (i 2)
  316. (interpret (first (operator-children operator)) md)))
  317. (:dotimes-3
  318. (incf (model-clock md) $syntaxT)
  319. (dotimes (i 3)
  320. (interpret (first (operator-children operator)) md)))
  321. (:dotimes-4
  322. (incf (model-clock md) $syntaxT)
  323. (dotimes (i 4)
  324. (interpret (first (operator-children operator)) md)))
  325. #|
  326. ;; learning functions
  327. |#
  328. (:match-probability
  329. ;; match the probability for the block, need to relate to cue given
  330. (incf (model-clock md) $cogT)
  331. (let* ((a-s (append (model-stm md) (list (model-current md)))) ;; put all stim together
  332. (cue-stim (find-if #'(lambda (y) (equal :cue (input-type y))) a-s)) ;; look for the cue item
  333. (pr (< (random 100) (* 100 current-prob)))) ;; get a random number and see if its below the prob
  334. ;;(when (> (model-clock md) (first *response-window*))
  335. ;;86% of the time it is valid - so if the value is T (i.e. under 86) it should match the cue
  336. (if cue-stim ;; have the cue
  337. ;;(when cue-stim ;; have the cue
  338. (case (input-direction cue-stim)
  339. (:left (if pr (interpret '(respond-left) md)
  340. (interpret '(respond-right) md)))
  341. (:right (if pr (interpret '(respond-right) md)
  342. (interpret '(respond-left) md))))
  343. ;;(setf (model-response md) nil)
  344. )))
  345. (:RW-cue-strength
  346. ;; uses cue and strength of association to predict stimulus
  347. (incf (model-clock md) (- $cogT (* 85 (model-strength-assoc md))))
  348. (let* ((a-s (append (model-stm md) (list (model-current md)))) ;; put everything together
  349. (cue-stim (find-if #'(lambda (y) (equal :cue (input-type y))) a-s))) ;; find item that is cue
  350. #|
  351. (when cue-stim ;; if find the cue use RW to set response
  352. (let* ((prediction (RW-predict-stim (model-strength-assoc md) (input-direction cue-stim))))
  353. (case prediction
  354. (:left (interpret '(respond-left) md))
  355. (:right (interpret '(respond-right) md)))))))
  356. |#
  357. (if cue-stim ;; if find the cue use RW to set response
  358. (let* ((prediction (RW-predict-stim (model-strength-assoc md) (input-direction cue-stim))))
  359. (case prediction
  360. (:left (interpret '(respond-left) md))
  361. (:right (interpret '(respond-right) md))))
  362. ;;(setf (model-response md) nil)
  363. )))
  364. ;; (setf (model-response md) (RW-predict-stim (model-strength-assoc md) (input-direction cue-stim)))
  365. ;; )))
  366. (:RW-cue-percept
  367. ;; uses both cue and perception of stimulus to select stimulus
  368. ;; made some changes so interpret response rather than setf response
  369. (let* ((str-prime (model-strength-assoc md))
  370. (a-s (append (model-stm md) (list (model-current md)))) ;; put everything together
  371. (cue-stim (find-if #'(lambda (y) (equal :cue (input-type y))) a-s))
  372. (target-stim (find-if #'(lambda (y) (equal :target (input-type y))) a-s)))
  373. (incf (model-clock md) (- $cogT (* 85 str-prime)))
  374. ;;(when (AND cue-stim target-stim)
  375. (if (AND cue-stim target-stim)
  376. ;; need to have both cue-stim and target-stim available
  377. ;;(incf (model-clock md) (- $cogT (* 85 str-prime)))
  378. ;; 85 ms is from Meyer & Schvaneveldt (1971); reduction in time proportionate to strength of priming
  379. (case
  380. (RW-predict-stim
  381. (if (equal (input-direction cue-stim) (input-location target-stim)) ;; if the cue and target are in the same place
  382. (+ (* 0.95 1) (* 0.05 str-prime)) ;; we assume perfect perception of stimulus -> p = 1
  383. (- (* 0.95 1) (* 0.05 str-prime))) ;; simple linear combination of probabilities; weights are arbitrary but reasonable (to check!)
  384. (input-direction cue-stim))
  385. (:left (interpret '(respond-left) md))
  386. (:right (interpret '(respond-right) md)))
  387. ;;(setf (model-response md) nil)
  388. )))
  389. (:if-strength-assoc
  390. ;; just a basic threshold type operator - if the strength-assoc is over a
  391. ;; certain value then just respond with the cue
  392. (incf (model-clock md) (- $cogT (* 85 (model-strength-assoc md))))
  393. (if (> (model-strength-assoc md) 0.7) ;; s-t as strength threshold
  394. (interpret '(respond-cue) md)
  395. ;;(setf (model-response md) nil)
  396. ))
  397. (:prev-val
  398. ;; look at validity of previous trial
  399. ;; previous valid trial would produce the displacement of the preparatory bias to the location suggested by the cue
  400. ;; So fast responses in VV, slow for VI, intermediate speeds for II and IV.
  401. (if (equalp (model-prev-trial md) "V")
  402. (interpret '(respond-cue) md)))
  403. #|
  404. ;;attention functions
  405. |#
  406. (:attend
  407. (incf (model-clock md) $cogT)
  408. (setf (model-current md) (model-salient md)))
  409. (:move-att-centre
  410. (when (not (equal (model-attFocus md) :centre)) ;; only do it if it isn't already there
  411. (incf (model-clock md) $cogT)
  412. (setf (model-attFocus md) :centre)))
  413. (:move-att-left
  414. (when (not (equal (model-attFocus md) :left)) ;; only do it if it isn't already there
  415. (incf (model-clock md) $cogT)
  416. (setf (model-attFocus md) :left)))
  417. (:move-att-right
  418. (when (not (equal (model-attFocus md) :right)) ;; only do it if it isn't already there
  419. (incf (model-clock md) $cogT)
  420. (setf (model-attFocus md) :right)))
  421. (:move-att-cue
  422. ;;move attention in line with cue direction - processing the cue means ive added cog time
  423. ;; can change so time is in line with strength-assoc?
  424. (incf (model-clock md) $cogT)
  425. ;;(incf (model-clock md) (- $cogT (* 85 (model-strength-assoc md))))
  426. (let* ((a-s (append (model-stm md) (list (model-current md)))) ;; put everything together
  427. (cue-stim (find-if #'(lambda (y) (equal :cue (input-type y))) a-s))) ;; find item that is cue
  428. (when cue-stim
  429. (case (input-direction cue-stim)
  430. (:left (interpret '(move-att-left) md))
  431. (:right (interpret '(move-att-right) md))
  432. (:centre (interpret '(move-att-centre) md))
  433. ))))
  434. (:attn-capture-location
  435. ;;changed for Arjona because only ever have 1 stimulus find where the stimulus is and put attention there.
  436. (let* ((time-details (first (timeline (model-clock md))))) ;; remove outer bracket - only ever 1 stim
  437. ;;(incf (model-clock md) $cogT)
  438. (if time-details
  439. (case (first time-details)
  440. ('stim1 (interpret '(move-att-centre) md)) ;; stim 1 is always in the centre
  441. ('stim2 (case (input-location (second (model-inputs md)))
  442. (:left (interpret '(move-att-left) md))
  443. (:right (interpret '(move-att-right) md))))
  444. ;;('stim1 (setf (model-attfocus md) (input-location (first (model-inputs md)))))
  445. ;;('stim2 (setf (model-attfocus md) (input-location (second (model-inputs md))))))
  446. ))))
  447. (:shift-attn-cw
  448. ;; move attention to a differnt stimulus, L to R
  449. (incf (model-clock md) $cogT)
  450. (case (model-attfocus md)
  451. (:left (interpret '(move-att-centre) md))
  452. (:centre (interpret '(move-att-right) md))
  453. (:right (interpret '(move-att-left) md))))
  454. (:shift-attn-ccw
  455. ;; move attention to a different stimulus, R to L
  456. (incf (model-clock md) $cogT)
  457. (case (model-attfocus md)
  458. (:left (interpret '(move-att-right) md))
  459. (:centre (interpret '(move-att-left) md))
  460. (:right (interpret '(move-att-centre) md))))
  461. (:detect
  462. (detect-main md)
  463. (incf (model-clock md) $inputT))
  464. (:detect-attend
  465. (interpret '(detect) md)
  466. (interpret '(attend) md))
  467. #|
  468. ;;comparison-functions
  469. |#
  470. #|
  471. ;; compare stm1 and current, if true respond current location
  472. (:compare-current1-Rc
  473. (decay md)
  474. (incf (model-clock md) $cogT)
  475. (when (not (equal (input-type (model-current md)) (input-type (first (model-stm md))))) ;; check that they aren't the same stimulus type (target/stimulus)
  476. (when (equal (input-name (model-current md)) (input-name (first (model-stm md))))
  477. (interpret '(respond-current) md))))
  478. #| (setf (model-response md)
  479. (input-location (model-current md))))))|#
  480. (:compare-current1-R1
  481. (decay md)
  482. (incf (model-clock md) $cogT)
  483. (when (not (equal (input-type (model-current md)) (input-type (first (model-stm md))))) ;; check that they aren't the same stimulus type (target/stimulus)
  484. (when (equal (input-name (model-current md)) (input-name (first (model-stm md))))
  485. (setf (model-response md)
  486. (input-location (first (model-stm md)))))))
  487. |#
  488. (:if-current-stm-Rstm
  489. (decay md)
  490. (incf (model-clock md) $cogT)
  491. (let* ((match (find-if #'(lambda (n) (equal (input-name (model-current md)) (input-name n)))
  492. (model-stm md))))
  493. (when match
  494. (case (input-location match)
  495. (:centre (interpret '(respond-centre) md))
  496. (:left (interpret '(respond-left) md))
  497. (:right (interpret '(respond-right) md))
  498. ))))
  499. (:if-current-stm-Rc
  500. (decay md)
  501. (incf (model-clock md) $cogT)
  502. (let* ((match (find-if #'(lambda (n) (equal (input-name (model-current md)) (input-name n)))
  503. (model-stm md))))
  504. (when match
  505. (interpret '(respond-current) md))))
  506. (:if-stm1-R
  507. (decay md)
  508. (incf (model-clock md) $cogT)
  509. (let* ((match (find-if #'(lambda (n) (equal (input-name (first (model-stm md))) (input-name n)))
  510. (rest (model-stm md)))))
  511. (when match
  512. (case (input-location match)
  513. (:centre (interpret '(respond-centre) md))
  514. (:left (interpret '(respond-left) md))
  515. (:right (interpret '(respond-right) md))
  516. ))))
  517. (:if-stm2-R
  518. (decay md)
  519. (incf (model-clock md) $cogT)
  520. (let* ((new-stm-order (list (second (model-stm md)) (first (model-stm md)) (third (model-stm md))))
  521. (match (find-if #'(lambda (n) (equal (input-name (first new-stm-order)) (input-name n)))
  522. (rest new-stm-order))))
  523. (when match
  524. (case (input-location match)
  525. (:centre (interpret '(respond-centre) md))
  526. (:left (interpret '(respond-left) md))
  527. (:right (interpret '(respond-right) md))
  528. ))))
  529. (:if-stm3-R
  530. (decay md)
  531. (incf (model-clock md) $cogT)
  532. (let* ((new-stm-order (list (third (model-stm md)) (first (model-stm md)) (second (model-stm md))))
  533. (match (find-if #'(lambda (n) (equal (input-name (first new-stm-order)) (input-name n)))
  534. (rest new-stm-order))))
  535. (when match
  536. (case (input-location match)
  537. (:centre (interpret '(respond-centre) md))
  538. (:left (interpret '(respond-left) md))
  539. (:right (interpret '(respond-right) md))
  540. ))))
  541. #|
  542. (:compare-1-2-p
  543. (decay md)
  544. (incf (model-clock md) $cogT)
  545. (when (not (equal (input-type (first (model-stm md))) (input-type (second (model-stm md))))) ;; check that they aren't the same stimulus type (target/stimulus)
  546. (equal (input-name (first (model-stm md))) (input-name (second (model-stm md))))))
  547. |#
  548. (:compare-1-2-p
  549. (decay md)
  550. (incf (model-clock md) $cogT)
  551. (equal (input-name (first (model-stm md))) (input-name (second (model-stm md)))))
  552. (:compare-2-3-p
  553. (decay md)
  554. (incf (model-clock md) $cogT)
  555. (equal (input-name (second (model-stm md))) (input-name (third (model-stm md)))))
  556. (:compare-1-3-p
  557. (decay md)
  558. (incf (model-clock md) $cogT)
  559. (equal (input-name (first (model-stm md))) (input-name (third (model-stm md)))))
  560. (:compare-current-1-p
  561. (decay md)
  562. (incf (model-clock md) $cogT)
  563. ;;(when (not (equal (input-type (first (model-stm md))) (input-type (second (model-stm md))))) ;; check that they aren't the same stimulus type (target/stimulus)
  564. (equal (input-name (first (model-stm md))) (input-name (model-current md))))
  565. (:compare-current-2-p
  566. (decay md)
  567. (incf (model-clock md) $cogT)
  568. (equal (input-name (second (model-stm md))) (input-name (model-current md))))
  569. (:compare-current-3-p
  570. (decay md)
  571. (incf (model-clock md) $cogT)
  572. (equal (input-name (third (model-stm md))) (input-name (model-current md))))
  573. (:magic-operator
  574. (decay md)
  575. (incf (model-clock md) $cogT)
  576. ;;find the target
  577. (let* ((target (find-if #'(lambda (n) (equal :target (input-type n)))
  578. (model-stm md)))
  579. ;; find the correct stimulus
  580. (correct-stim (when target (find-if #'(lambda (n) (and (equal (input-name target) (input-name n)) (equal :stimulus (input-type n))))
  581. (model-stm md)))))
  582. ;; respond with correct location
  583. (when correct-stim (setf (model-response md) (input-location correct-stim)))
  584. ))
  585. (:retrieve-target
  586. (decay md)
  587. (incf (model-clock md) $cogT)
  588. (let* ((target (find-if #'(lambda (n) (equal :target (input-type n)))
  589. (model-stm md))))
  590. (when target
  591. (setf (model-current md) target)
  592. (setf (input-store-time (model-current md)) nil))))
  593. (:retrieve-cue
  594. (decay md)
  595. (incf (model-clock md) $cogT)
  596. (let* ((target (find-if #'(lambda (n) (equal :cue (input-type n)))
  597. (model-stm md))))
  598. (when target
  599. (setf (model-current md) target)
  600. (setf (input-store-time (model-current md)) nil))))
  601. #|
  602. (:compare-stm-items
  603. (incf (model-clock md) $cogT)
  604. (let* (stm-target (find-if #'(lambda (x) (equal (input-type x) :target)) (model-stm md)))
  605. )
  606. (find-if #'(lambda (x) (equal (input-name (first (model-stm md))) (input-name x))
  607. (list (second (model-stm md)) (third (model-stm md)))))
  608. (when (not (equal (first (model-stm md)) (second (model-stm md))))
  609. |#
  610. #|
  611. (:find-stm-match
  612. (incf (model-clock md) $cogT)
  613. (when (not (equal (model-current md) (first (model-stm md)))) ;; check that they aren't exactly the same thing!
  614. (find-if #'(lambda (x) (equal (input-name (model-current md)) (input-name x))
  615. (model-stm md)))
  616. (:compare-current-stm-1
  617. (incf (model-clock md) $cogT)
  618. (let* (stm1 (first (model-stm md)))
  619. (when (equal (input-name (model-current md)) (input-name stm1))
  620. (setf (model-response md)
  621. (input-location stm1)))))
  622. |#
  623. #|
  624. (when (= (model-current md) (first (model-stm md)))
  625. (setf (model-response md)
  626. (string (aref (symbol-name (model-attFocus md)) 0)))))
  627. |#
  628. ;; some kind of shift attention to opposite side function?
  629. #|
  630. ;;predicates and if
  631. |#
  632. (:if
  633. (incf (model-clock md) $syntaxT)
  634. (if (interpret (first (operator-children operator)) md)
  635. (interpret (second (operator-children operator)) md)
  636. (interpret (third (operator-children operator)) md)))
  637. (:current-cue-p
  638. ;; looking at whether the model-current input is the target or a comparison stimulus
  639. (incf (model-clock md) $cogT)
  640. (equal (input-type (model-current md)) :cue))
  641. (:current-target-p
  642. ;; looking at whether the model-current input is the target or a comparison stimulus
  643. (incf (model-clock md) $cogT)
  644. (equal (input-type (model-current md)) :target))
  645. #|
  646. ;;stm functions
  647. |#
  648. (:put-stm
  649. (decay md)
  650. (incf (model-clock md) $cogT)
  651. (setf (model-stm md)
  652. ;;(if (= 3 (length (model-stm md))) ;; starts with 3 places
  653. (list (copy-structure (model-current md))
  654. (first (model-stm md))
  655. (second (model-stm md)))
  656. )
  657. (setf (input-store-time (first (model-stm md))) (model-clock md))
  658. )
  659. (:detect-attend-putstm
  660. (interpret '(prog2 (detect-attend) (put-stm)) md))
  661. (:rehearsal-1
  662. (decay md)
  663. (incf (model-clock md) $stmT)
  664. ;; reinforce what is already in a stm store - i.e. change the store-time
  665. (when (not (equal input-nil (first (model-stm md)))) ;; make sure its not just changing input-nil
  666. (setf (input-store-time (first (model-stm md))) (model-clock md))))
  667. (:rehearsal-2
  668. (decay md)
  669. (incf (model-clock md) $stmT)
  670. ;; reinforce what is already in a stm store - i.e. change the store-time
  671. (when (not (equal input-nil (second (model-stm md)))) ;; make sure its not just changing input-nil
  672. (setf (input-store-time (second (model-stm md))) (model-clock md))))
  673. (:rehearsal-3
  674. (decay md)
  675. (incf (model-clock md) $stmT)
  676. ;; reinforce what is already in a stm store - i.e. change the store-time
  677. (when (not (equal input-nil (third (model-stm md)))) ;; make sure its not just changing input-nil
  678. (setf (input-store-time (third (model-stm md))) (model-clock md))))
  679. (:retrieve-1
  680. (decay md)
  681. (incf (model-clock md) $stmT)
  682. (setf
  683. (model-current md) (copy-structure (first (model-stm md)))
  684. (input-store-time (model-current md)) nil))
  685. (:retrieve-2
  686. (decay md)
  687. (incf (model-clock md) $stmT)
  688. (setf
  689. (model-current md) (copy-structure (second (model-stm md)))
  690. (input-store-time (model-current md)) nil))
  691. (:retrieve-3
  692. (decay md)
  693. (incf (model-clock md) $stmT)
  694. (setf
  695. (model-current md) (copy-structure (third (model-stm md)))
  696. (input-store-time (model-current md)) nil))
  697. #|
  698. ;;response functions
  699. |#
  700. (:respond-left
  701. (incf (model-clock md) $outputT)
  702. ;;(when (> (model-clock md) (first *response-window*))
  703. (setf (model-response md) :left))
  704. (:respond-right
  705. (incf (model-clock md) $outputT)
  706. ;;(when (> (model-clock md) (first *response-window*))
  707. (setf (model-response md) :right))
  708. (:respond-centre
  709. (incf (model-clock md) $outputT)
  710. ;;(when (> (model-clock md) (first *response-window*))
  711. (setf (model-response md) :centre))
  712. (:respond-current
  713. (incf (model-clock md) $outputT)
  714. (when (not (equal input-nil (model-current md)))
  715. (setf (model-response md) (input-location (model-current md)))))
  716. (:respond-cue
  717. (incf (model-clock md) $outputT)
  718. (let* ((a-s (append (model-stm md) (list (model-current md))))
  719. (cue-stim (find-if #'(lambda (y) (equal :cue (input-type y))) a-s))) ;; look for the cue item
  720. (when cue-stim
  721. (case (input-direction cue-stim)
  722. (:left (setf (model-response md) :left))
  723. (:right (setf (model-response md) :right))
  724. ))))
  725. (:respond-cue-OPP
  726. (incf (model-clock md) $outputT)
  727. (let* ((a-s (append (model-stm md) (list (model-current md))))
  728. (cue-stim (find-if #'(lambda (y) (equal :cue (input-type y))) a-s))) ;; look for the cue item
  729. (when cue-stim
  730. (case (input-direction cue-stim)
  731. (:left (setf (model-response md) :right))
  732. (:right (setf (model-response md) :left))
  733. ))))
  734. (:respond-attfocus
  735. (incf (model-clock md) $outputT)
  736. (setf (model-response md) (model-attfocus md)))
  737. #|
  738. ;; wait operators, used for simplifying code
  739. |#
  740. (:wait-input
  741. (incf (model-clock md) $inputT))
  742. (:wait-output
  743. (incf (model-clock md) $outputT))
  744. (:wait-cognitive
  745. (incf (model-clock md) $cogT))
  746. (:wait-stm
  747. (incf (model-clock md) $stmT))
  748. (:wait-input-cog
  749. (incf (model-clock md) (+ $inputT $cogT)))
  750. (:wait-input-cog-cog
  751. (incf (model-clock md) (+ $inputT $cogT $cogT)))
  752. #|
  753. (:wait-input-stm
  754. (incf (model-clock md) (+ $inputT $stmT)))
  755. (:wait-input-output
  756. (incf (model-clock md) (+ $inputT $outputT)))
  757. (:wait-output-cognitive
  758. (incf (model-clock md) (+ $outputT $cogT)))
  759. (:wait-output-stm
  760. (incf (model-clock md) (+ $outputT $stmT)))
  761. (:wait-cognitive-stm
  762. (incf (model-clock md) (+ $cogT $stmT)))
  763. |#
  764. (otherwise ; error if comes across an unknown operator
  765. (error "interpret: unknown operator ~a" (operator-label operator))))))
  766. #|
  767. ### operator-set ###
  768. |#
  769. ;; operator set (name . number-of-children)
  770. ;; TIP: comment out individual lines to ignore specific operators
  771. (setf op-set
  772. '((WAIT-1500 . 0)
  773. (WAIT-1000 . 0)
  774. (WAIT-200 . 0)
  775. (WAIT-100 . 0)
  776. (WAIT-50 . 0)
  777. (WAIT-25 . 0)
  778. (wait-.5trial . 0)
  779. (wait-.25trial . 0)
  780. (wait-.1trial . 0)
  781. (PROG4 . 4)
  782. (PROG3 . 3)
  783. (PROG2 . 2)
  784. (DOTIMES-4 . 1)
  785. (DOTIMES-3 . 1)
  786. (DOTIMES-2 . 1)
  787. (WHILE-200 . 1)
  788. (WHILE-100 . 1)
  789. (NIL . 0)
  790. (IF . 3)
  791. (MOVE-ATT-RIGHT . 0)
  792. (MOVE-ATT-LEFT . 0)
  793. (MOVE-ATT-CENTRE . 0)
  794. (move-att-cue . 0)
  795. (shift-attn-cw . 0)
  796. (shift-attn-ccw . 0)
  797. (detect . 0)
  798. (ATTEND . 0)
  799. (PUT-STM . 0)
  800. (rehearsal-1 . 0)
  801. (rehearsal-2 . 0)
  802. (rehearsal-3 . 0)
  803. (retrieve-1 . 0)
  804. (retrieve-2 . 0)
  805. (retrieve-3 . 0)
  806. (retrieve-target . 0)
  807. (retrieve-cue . 0)
  808. (detect-attend . 0)
  809. (detect-attend-putstm . 0)
  810. (attn-capture-location . 0)
  811. ;(if-current-stm-Rstm . 0)
  812. ;(if-current-stm-Rc . 0)
  813. ;(if-stm1-R . 0)
  814. ;(if-stm2-R . 0)
  815. ;(if-stm3-R . 0)
  816. (current-target-p . 0)
  817. (current-cue-p . 0)
  818. (respond-left . 0)
  819. (respond-right . 0)
  820. (respond-centre . 0)
  821. (respond-current . 0)
  822. (respond-cue . 0)
  823. (respond-cue-OPP . 0)
  824. ;;(response-attfocus . 0)
  825. (match-probability . 0)
  826. (RW-cue-strength . 0)
  827. (RW-cue-percept . 0)
  828. (if-strength-assoc . 0)
  829. (prev-val . 0)
  830. )
  831. )
  832. ;;(defun operator-set ()
  833. ;; op-set)
  834. (setf wait-op-set
  835. '((wait-input . 0)
  836. (wait-output . 0)
  837. (wait-cognitive . 0)
  838. (wait-stm . 0)
  839. ;;(wait-cog-output . 0)
  840. (wait-input-cog . 0)
  841. (wait-input-cog-cog . 0)))
  842. (setf dotted-replace
  843. '((attend . wait-cognitive)
  844. (MOVE-ATT-RIGHT . wait-cognitive)
  845. (MOVE-ATT-LEFT . wait-cognitive)
  846. (MOVE-ATT-CENTRE . wait-cognitive)
  847. (move-att-cue . wait-cognitive)
  848. (shift-attn-cw . wait-cognitive)
  849. (shift-attn-ccw . wait-cognitive)
  850. (detect . wait-input)
  851. (rehearsal-1 . wait-cognitive)
  852. (rehearsal-2 . wait-cognitive)
  853. (rehearsal-3 . wait-cognitive)
  854. (retrieve-1 . wait-stm)
  855. (retrieve-2 . wait-stm)
  856. (retrieve-3 . wait-stm)
  857. (retrieve-target . wait-stm)
  858. (retrieve-cue . wait-stm)
  859. (attn-capture-location . wait-cognitive)
  860. (PUT-STM . wait-cognitive)
  861. (detect-attend . wait-input-cog)
  862. (detect-attend-putstm . wait-input-cog-cog)
  863. ;;(COMPARE-CURRENT1-Rc . wait-cognitive)
  864. ;;(COMPARE-CURRENT1-R1 . wait-cognitive)
  865. ;;(compare-1-2-p . wait-cognitive)
  866. ;;(compare-1-3-p . wait-cognitive)
  867. ;;(compare-2-3-p . wait-cognitive)
  868. ;;(if-current-stm-Rstm . wait-cognitive)
  869. ;;(if-current-stm-Rc . wait-cognitive)
  870. ;;(if-stm1-R . wait-cognitive)
  871. ;;(if-stm2-R . wait-cognitive)
  872. ;;(if-stm3-R . )
  873. ;;(compare-current-1-p . wait-cognitive)
  874. ;;(compare-current-2-p . wait-cognitive)
  875. ;;(compare-current-3-p . wait-cognitive)
  876. (current-target-p . wait-cognitive)
  877. (current-cue-p . wait-cognitive)
  878. ;;(magic-operator . wait-cognitive)
  879. (respond-left . wait-output)
  880. (respond-right . wait-output)
  881. (respond-centre . wait-output)
  882. (respond-current . wait-output)
  883. (respond-cue . wait-output)
  884. (respond-cue-opp . wait-output)
  885. (match-probability . wait-cognitive)
  886. (RW-cue-strength . wait-cognitive)
  887. (RW-cue-percept . wait-cognitive)
  888. (if-strength-assoc . wait-cognitive)
  889. )
  890. )
  891. (defun operator-set () op-set)
  892. #|
  893. ### interpretation
  894. |#
  895. (defun best-models (experiment-name)
  896. (let* ((temp-results (gpstats:read-trace (format nil "~a" experiment-name)))
  897. (last-generation (rest (first (last temp-results)))) ;; puts it into necessary format
  898. (best-models (gpstats:best-individuals-in-generation last-generation)))
  899. (setf yay-model best-models)
  900. (setf clean-models (gpstats:clean-individuals best-models #'run-experiment))
  901. ;;(print (format nil "~a final models" (length clean-models)))
  902. ))