posner-tests.lisp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. ;; This file was created by Laura
  2. ;; It will run a series of tests for the operators involved in the Posner experiment.
  3. ;; THIS IS SPECIFICALLY FOR ARJONA
  4. ;; code checking
  5. (defun check (query error-message)
  6. (if query
  7. (format t ".")
  8. (format t "~&Error: ~a~&" error-message)))
  9. ;; need to load the relevant information in order to run the checks
  10. ;; will just run the Chao experiment file for this - this includes all run-gp run-experiment and loads interpret file
  11. (require :asdf)
  12. (require :gems)
  13. (setf *default-pathname-defaults*
  14. #P"/Users/bartletl/Documents/portacle/projects/gems-1.2-alpha-3/posner/")
  15. ;;#P"/home/laurab/common-lisp/gems-1.2-alpha-3/posner/")
  16. (load "posner-initialise.lisp")
  17. (load "posner-ARJONA.lisp")
  18. ;; TESTING JUST THE DECAY TOGGLE STUFF
  19. #|
  20. (setf decay-toggle 1) ;; just on for these tests
  21. (setf *decay-threshold* 0.6) ;; just try different values
  22. (defparameter stored-state (make-random-state t))
  23. (setf *random-state* (make-random-state stored-state)) ;; to load previous
  24. (defun test-decay ()
  25. (setf *decay-threshold* 0.6) ;; just try different values
  26. (let* ((md (make-model :current test-input-1 :salient test-input-2)))
  27. (interpret '(prog3 (put-stm) (attend) (put-stm)) md)
  28. (check (equal 2 (input-name (second (model-stm md)))) "test-input-1 is in stm2")
  29. (check (equal 3 (input-name (first (model-stm md)))) "test-input-2 is in stm1")
  30. (setf (model-clock md) 1500)
  31. (interpret '(rehearsal-1) md)
  32. (setf (model-clock md) 2000)
  33. (interpret '(retrieve-1) md)
  34. ;;(print md)
  35. (check (equal nil (input-name (second (model-stm md)))) "test-input-1 has decayed")
  36. (check (equal 3 (input-name (first (model-stm md)))) "test-input-2 is still good")
  37. (setf *decay-threshold* 0.0)
  38. (let* ((md (make-model :current test-input-1 :salient test-input-2)))
  39. (interpret '(prog3 (put-stm) (attend) (put-stm)) md)
  40. (check (equal 2 (input-name (second (model-stm md)))) "test-input-1 is in stm2")
  41. (check (equal 3 (input-name (first (model-stm md)))) "test-input-2 is in stm1")
  42. (setf (model-clock md) 1500)
  43. (interpret '(rehearsal-1) md)
  44. (setf (model-clock md) 2000)
  45. (interpret '(retrieve-1) md)
  46. ;;(print md)
  47. (check (equal 2 (input-name (second (model-stm md)))) "test-input-1 has NOT decayed")
  48. (check (equal 3 (input-name (first (model-stm md)))) "test-input-2 is still good")
  49. (interpret '(prog2 (wait-1500) (retrieve-1)) md)
  50. (check (equal 2 (input-name (second (model-stm md)))) "test-input-1 has NOT decayed - again")
  51. (check (equal 3 (input-name (first (model-stm md)))) "test-input-2 is still good - again")
  52. )))
  53. |#
  54. (setf decay-toggle 0) ;; just off for tests for now
  55. (defun test-nil-op ()
  56. (let ((md (make-model :current test-input-1)))
  57. (check (equal :centre (input-location (model-current md))) "initial current value")
  58. (interpret '(nil) md)
  59. (check (equal nil (input-location (model-current md))) "nil current location")
  60. (check (equal nil (input-type (model-current md))) "nil current type")))
  61. ;; WORKS: Aj
  62. (defun test-if-resp ()
  63. (let ((md (make-model :salient test-input-2 :current test-input-1 :clock (first *response-window*))))
  64. (interpret '(if (current-target-p) (respond-left) (respond-right)) md)
  65. (check (equal (model-response md) :right) "input-1 is cue, so false")
  66. (interpret '(if (current-cue-p) (respond-left) (respond-right)) md)
  67. (check (equal (model-response md) :left) "input-1 is cue, so true")
  68. (interpret '(attend) md)
  69. (interpret '(if (current-cue-p) (respond-left) (respond-right)) md)
  70. (check (equal (model-response md) :right) "input-2 is target, so false")
  71. (interpret '(if (current-target-p) (respond-left) (respond-right)) md)
  72. (check (equal (model-response md) :left) "input-2 is target, so true")))
  73. ;; WORKS: Aj
  74. (defun test-prog ()
  75. (let ((md (make-model)))
  76. (check (equal 0 (model-clock md)) "initial clock 0")
  77. (interpret '(prog2 (wait-100) (wait-100)) md)
  78. (check (equal 200 (model-clock md)) "updated clock 2x100")
  79. (interpret '(prog3 (wait-100) (wait-100) (wait-100)) md)
  80. (check (equal 500 (model-clock md)) "updated clock 3x100")
  81. (interpret '(prog4 (wait-100) (wait-100) (wait-100) (wait-100)) md)
  82. (check (equal 900 (model-clock md)) "updated clock 4x100")))
  83. ;; WORKS: Aj
  84. (defun test-put-stm ()
  85. (let ((md (make-model :current test-input-1 :salient test-input-2)))
  86. (check (equal nil (input-location (first (model-stm md)))) "initial empty stm1")
  87. (check (equal nil (input-location (second (model-stm md)))) "initial empty stm2")
  88. (check (equal nil (input-location (third (model-stm md)))) "initial empty stm3")
  89. (interpret '(put-stm) md)
  90. (check (equal :centre (input-location (first (model-stm md)))) "fill stm1")
  91. (check (equal nil (input-location (second (model-stm md)))) "second empty stm2")
  92. (check (equal nil (input-location (third (model-stm md)))) "second empty stm3")
  93. (interpret '(prog2 (attend) (put-stm)) md)
  94. (check (equal :left (input-location (first (model-stm md)))) "update stm1")
  95. (check (equal :centre (input-location (second (model-stm md)))) "move 1 to stm2")
  96. (check (equal nil (input-location (third (model-stm md)))) "third empty stm3")
  97. ;;(print md)
  98. (interpret '(put-stm) md)
  99. (check (equal :left (input-location (first (model-stm md)))) "update stm1 again")
  100. (check (equal :left (input-location (second (model-stm md)))) "move 1 to stm2 again")
  101. (check (equal :centre (input-location (third (model-stm md)))) "move 2 to stm3")
  102. (interpret '(put-stm) md)
  103. (check (equal :left (input-location (first (model-stm md)))) "update stm1 again again")
  104. (check (equal :left (input-location (second (model-stm md)))) "move 1 to stm2 again again")
  105. (check (equal :left (input-location (third (model-stm md)))) "remove the previous stm3")
  106. ))
  107. ;; WORKS: Aj
  108. (defun test-attend ()
  109. (let ((md (make-model :salient test-input-1)))
  110. (check (equal nil (input-location (model-current md))) "check current is empty")
  111. (interpret '(attend) md)
  112. (check (equal :centre (input-location (model-current md))) "current updated with salient")
  113. ))
  114. ;; WORKS: Aj
  115. (defun test-move-att ()
  116. (let ((md (make-model :attfocus :left :current test-input-1)))
  117. (check (equal :left (model-attfocus md)) "model start left")
  118. (interpret '(move-att-left) md)
  119. (check (equal 0 (model-clock md)) "nothing changed so no change to clock")
  120. (interpret '(move-att-centre) md)
  121. (check (equal :centre (model-attfocus md)) "model moved to centre")
  122. (interpret '(move-att-centre) md)
  123. (check (equal 70 (model-clock md)) "nothing changed so no change to clock")
  124. (interpret '(move-att-left) md)
  125. (check (equal :left (model-attfocus md)) "model moved to left")
  126. (interpret '(move-att-right) md)
  127. (check (equal :right (model-attfocus md)) "model moved to right")
  128. (interpret '(move-att-right) md)
  129. (check (equal 210 (model-clock md)) "nothing changed so no change to clock")
  130. (interpret '(move-att-cue) md)
  131. (check (equal :left (model-attfocus md)) "model moved to left, because cue direction")
  132. (check (equal 350 (model-clock md)) "clock increased because operations")
  133. (interpret '(move-att-cue) md)
  134. (check (equal 420 (model-clock md)) "clock increased but only but cog for cue")
  135. (let ((md (make-model :attfocus :right)))
  136. (interpret '(move-att-cue) md)
  137. (check (equal :right (model-attfocus md)) "no cue saved so no effect (except time)")
  138. (check (equal 70 (model-clock md)) "time change")
  139. )))
  140. ;; WORKS: Aj
  141. (defun test-attn-capture-loc ()
  142. (let ((md (make-model :attfocus :left :inputs (list test-input-1 test-input-2) :clock 310)))
  143. (check (equal :left (model-attfocus md)) "model start left")
  144. (interpret '(attn-capture-location) md)
  145. ;;(print md)
  146. (check (equal :centre (model-attfocus md)) "attn captured to centre")
  147. (let ((md (make-model :clock (first *response-window*) :inputs (list test-input-1 test-input-2))))
  148. (check (equal :centre (model-attfocus md)) "attnfocus is at default centre position")
  149. ;;(setf test-mod md)
  150. (interpret '(attn-capture-location) md)
  151. (check (equal :left (model-attfocus md)) "attnfocus is left, in line with test-input-2")
  152. (let ((md (make-model :inputs (list test-input-1 test-input-2) :attfocus :right))) ;; default clock, so no stim
  153. (check (equal :right (model-attfocus md)) "attn right at start")
  154. (check (equal 0 (model-clock md)) "clock default 0")
  155. (interpret '(attn-capture-location) md)
  156. (check (equal :right (model-attfocus md)) "attn still to right - no stim")))))
  157. ;; WORKS: Arjona
  158. (defun test-detect ()
  159. (let ((md (make-model :inputs (list test-input-1) :clock 300)))
  160. (check (equal input-nil (model-salient md)) "salient is nil")
  161. (interpret '(detect) md)
  162. (check (equal test-input-1 (model-salient md)) "salient is now test-input 1"))
  163. (let ((md (make-model :inputs (list test-input-1) :attfocus :left :clock 300)))
  164. (check (equal input-nil (model-salient md)) "salient is nil")
  165. (interpret '(detect) md)
  166. (check (equal input-nil (model-salient md)) "salient is still nil because stim in centre")))
  167. ;; WORKS: Aj
  168. (defun test-respond ()
  169. (let ((md (make-model :current test-input-1)))
  170. (check (equal nil (model-response md)) "response is nil")
  171. (interpret '(respond-current) md)
  172. (check (equal :centre (model-response md)) "responding with what is in current")
  173. (interpret '(respond-left) md)
  174. (check (equal :left (model-response md)) "responding left")
  175. (interpret '(respond-right) md)
  176. (check (equal :right (model-response md)) "responding right")
  177. (interpret '(respond-cue) md)
  178. (check (equal :left (model-response md)) "respond left, direction of cue")
  179. (interpret '(respond-cue-opp) md)
  180. (check (equal :right (model-response md)) "respond right, opposite direction of cue")
  181. (interpret '(prog2 (nil) (respond-current)) md)
  182. (check (equal :right (model-response md)) "still left because nothing in current")
  183. ))
  184. ;; WORKS: Aj
  185. (defun test-prev-cue ()
  186. (let ((md (make-model :current test-input-1 :prev-trial "V")))
  187. (interpret '(prev-val) md)
  188. (check (equalp (model-response md) :left) "response in line with previous trial validity")
  189. (let ((md (make-model :current test-input-1 :prev-trial "I")))
  190. (interpret '(prev-val) md)
  191. (check (equalp (model-response md) nil) "no change in response because no benefit from valid")
  192. )))
  193. (defun test-rehearsal ()
  194. (let ((md (make-model :current test-input-1 :salient test-input-2)))
  195. (interpret '(prog2 (dotimes-2 (put-stm)) (prog2 (attend) (put-stm))) md)
  196. (check (equal (input-location test-input-1) (input-location (second (model-stm md)))) "put item1 in stm2")
  197. (check (equal (input-location test-input-1) (input-location (third (model-stm md)))) "put item1 in stm3")
  198. (check (equal (input-location test-input-2) (input-location (first (model-stm md)))) "put item2 in stm1")
  199. (check (not (equal (input-store-time (third (model-stm md))) (model-clock md))) "stm3 not same as clock")
  200. (check (not (equal (input-store-time (second (model-stm md))) (model-clock md))) "stm2 not same as clock")
  201. (interpret '(rehearsal-2) md)
  202. (check (equal (input-store-time (second (model-stm md))) (model-clock md)) "updated store time stm2")
  203. (interpret '(rehearsal-3) md)
  204. (check (equal (input-store-time (third (model-stm md))) (model-clock md)) "updated store time stm3")
  205. (check (not (equal (input-store-time (first (model-stm md))) (model-clock md))) "stm1 not same as clock")
  206. (interpret '(rehearsal-1) md)
  207. (check (equal (input-store-time (first (model-stm md))) (model-clock md)) "updated store time stm1")
  208. ))
  209. ;; WORKS: Aj
  210. (defun test-while ()
  211. (let ((md (make-model :current test-input-1 :salient test-input-2)))
  212. (interpret '(while-200 (put-stm)) md)
  213. (check (equal (input-location input-1) (input-location (third (model-stm md)))) "repeated enough that input1 is in stm3")
  214. (interpret '(prog2 (attend) (while-100 (put-stm))) md)
  215. (check (equal (input-location test-input-1) (input-location (third (model-stm md)))) "input1 is still in stm3")
  216. (check (equal (input-location test-input-2) (input-location (second (model-stm md)))) "input2 is in stm2")
  217. (check (equal (input-location test-input-2) (input-location (first (model-stm md)))) "input2 is in stm1")
  218. ))
  219. ;; WORKS: Aj
  220. (defun test-wait ()
  221. (let ((md (make-model)))
  222. (check (equal 0 (model-clock md)) "model-clock at 0")
  223. (interpret '(wait-25) md)
  224. (check (equal 25 (model-clock md)) "model-clock at 25")
  225. (interpret '(wait-50) md)
  226. (check (equal 75 (model-clock md)) "model-clock at 75")
  227. (interpret '(wait-100) md)
  228. (check (equal 175 (model-clock md)) "model-clock at 175")
  229. (interpret '(wait-200) md)
  230. (check (equal 375 (model-clock md)) "model-clock at 375")
  231. (interpret '(wait-1000) md)
  232. (check (equal 1375 (model-clock md)) "model-clock at 1375")
  233. (interpret '(wait-1500) md)
  234. (check (equal 2875 (model-clock md)) "model-clock at 2875")
  235. (interpret '(wait-.5trial) md)
  236. (check (equal (+ 2875 (/ (second *response-window*) 2)) (model-clock md)) "model-clock added .5 of trial")
  237. (setf (model-clock md) 0)
  238. (interpret '(wait-.25trial) md)
  239. (check (equal (/ (second *response-window*) 4) (model-clock md)) "model-clock added .25 of trial")
  240. (setf (model-clock md) 0)
  241. (interpret '(wait-.1trial) md)
  242. (check (equal (/ (second *response-window*) 10) (model-clock md)) "model-clock added .25 of trial")
  243. ;;(print md)
  244. ))
  245. ;; WORKS: Aj
  246. (defun test-dotimes ()
  247. (let ((md (make-model)))
  248. (check (equal 0 (model-clock md)) "model-clock at 0")
  249. (interpret '(dotimes-2 (wait-100)) md)
  250. (check (equal 200 (model-clock md)) "model-clock at 200")
  251. (interpret '(dotimes-3 (wait-100)) md)
  252. (check (equal 500 (model-clock md)) "model-clock at 500")
  253. (interpret '(dotimes-4 (wait-100)) md)
  254. (check (equal 900 (model-clock md)) "model-clock at 900")
  255. ))
  256. ;; WORKS: Aj
  257. (defun avg (faff) (/ (apply '+ faff) (length faff)))
  258. (defun test-match-prob ()
  259. (setf tally-86 nil)
  260. (setf tally-50 nil)
  261. (setf tally-68 nil)
  262. (dotimes (more 50)
  263. (setf current-prob 0.86)
  264. (setf tally 0)
  265. (let* ((md (make-model :current test-input-1)))
  266. (check (equal :left (input-direction (model-current md))) "check input direction is left")
  267. (dotimes (rep 100)
  268. (interpret '(match-probability) md)
  269. (when (equalp :left (model-response md)) (setf tally (1+ tally))))
  270. ;;(check (< 66 tally) "is it in line with response?")
  271. (push tally tally-86)
  272. (let* ((md (make-model :current test-input-1)))
  273. (setf current-prob 0.5)
  274. (setf tally 0)
  275. (dotimes (rep 100)
  276. (interpret '(match-probability) md)
  277. (when (equalp :left (model-response md)) (setf tally (1+ tally))))
  278. ;;(check (AND (< 30 tally) (> 70 tally)) "is it in line with response?")
  279. (push tally tally-50)
  280. (let* ((md (make-model :current test-input-1)))
  281. (setf current-prob 0.68)
  282. (setf tally 0)
  283. (dotimes (rep 100)
  284. (interpret '(match-probability) md)
  285. (when (equalp :left (model-response md)) (setf tally (1+ tally))))
  286. ;;(check (AND (< tally 88) (> tally 48)) "is it in line with response?")
  287. (push tally tally-68)
  288. ))))
  289. (print tally-86)
  290. (print (avg tally-86))
  291. (check (< 66 (avg tally-86)) "tally-86 avg")
  292. (print tally-50)
  293. (print (avg tally-50))
  294. (check (AND (< 30 (avg tally-50)) (> 70 (avg tally-50))) "tally-50 avg")
  295. (print tally-68)
  296. (print (avg tally-68))
  297. (check (AND (< (avg tally-68) 88) (> (avg tally-68) 48)) "tally-68 avg")
  298. )
  299. ;; WORKS: Aj
  300. (defun test-RW-cue-strength () ;; so it takes the *strength-assoc* and works out how likely the cue is. In run-experiment, the *strength-assoc* is updated based on the validity of the trial. so can just run with a variety of strength-assoc's and see whether it outputs in line with that.
  301. (setf tally-50 nil)
  302. (setf tally-75 nil)
  303. (setf tally-25 nil)
  304. (dotimes (more 10)
  305. (setf tally 0)
  306. (dotimes (we 100)
  307. (let ((md (make-model :strength-assoc 0.5 :current test-input-1)))
  308. (interpret '(RW-cue-strength) md)
  309. (when (equalp :left (model-response md)) (setf tally (1+ tally)))))
  310. (push tally tally-50)
  311. (setf tally 0)
  312. (dotimes (we 100)
  313. (let ((md (make-model :strength-assoc 0.75 :current test-input-1)))
  314. (interpret '(RW-cue-strength) md)
  315. (when (equalp :left (model-response md)) (setf tally (1+ tally)))))
  316. (push tally tally-75)
  317. (setf tally 0)
  318. (dotimes (we 100)
  319. (let ((md (make-model :strength-assoc 0.25 :current test-input-1)))
  320. (interpret '(RW-cue-strength) md)
  321. (when (equalp :left (model-response md)) (setf tally (1+ tally)))))
  322. (push tally tally-25))
  323. (print tally-75)
  324. (print (avg tally-75))
  325. (check (AND (< 55 (avg tally-75)) (> 95 (avg tally-75))) "tally-75 avg")
  326. (print tally-50)
  327. (print (avg tally-50))
  328. (check (AND (< 30 (avg tally-50)) (> 70 (avg tally-50))) "tally-50 avg")
  329. (print tally-25)
  330. (print (avg tally-25))
  331. (check (AND (< (avg tally-25) 45) (> (avg tally-25) 5)) "tally-25 avg")
  332. )
  333. ;; WORKS: Aj (still need to test the updating of the strength-assoc)
  334. (defun test-RW-cue-percept ()
  335. ;; uses the cue and perception of stimulus (not strength of learning?)
  336. ;; still uses the strength-assoc, but it only slighty affects things.
  337. ;; RW-predict-stim (strength-assoc, cue-direction)
  338. (setf tally-50-match nil)
  339. (setf tally-90-match nil)
  340. (setf tally-10-match nil)
  341. (setf tally-50-no nil)
  342. (setf tally-90-no nil)
  343. (setf tally-10-no nil)
  344. (let* ((md (make-model :strength-assoc 0.5 :current test-input-1)))
  345. (interpret '(RW-cue-percept) md)
  346. (check (equal nil (model-response md)) "don't have the target so shouldnt do anything")
  347. (dotimes (faff 100)
  348. (setf tally 0)
  349. (dotimes (we 100)
  350. (let* ((md (make-model :strength-assoc 0.5 :current test-input-2 :stm (list test-input-1 input-nil input-nil))))
  351. (interpret '(rw-cue-percept) md)
  352. (when (equalp :left (model-response md)) (setf tally (1+ tally)))))
  353. (push tally tally-50-match)
  354. ;;(setf (model-strength-assoc md) 0.90)
  355. (setf tally 0)
  356. (dotimes (we 100)
  357. (let* ((md (make-model :strength-assoc 0.9 :current test-input-2 :stm (list test-input-1 input-nil input-nil))))
  358. (interpret '(rw-cue-percept) md)
  359. (when (equal :left (model-response md)) (setf tally (1+ tally)))))
  360. (push tally tally-90-match)
  361. ;;(setf (model-strength-assoc md) 0.10)
  362. (setf tally 0)
  363. (dotimes (we 100)
  364. (let* ((md (make-model :strength-assoc 0.1 :current test-input-2 :stm (list test-input-1 input-nil input-nil))))
  365. (interpret '(rw-cue-percept) md)
  366. (when (equal :left (model-response md)) (setf tally (1+ tally)))))
  367. (push tally tally-10-match)
  368. )
  369. ;;(interpret '(attend) md)
  370. ;;(print md)
  371. ;;(check (equal (input-location test-input-3) (model-response md)) "current is now not matched with cue")
  372. (dotimes (faff 100)
  373. (setf tally 0)
  374. (dotimes (we 100)
  375. (let* ((md (make-model :strength-assoc 0.5 :current test-input-3 :stm (list test-input-1 input-nil input-nil))))
  376. (interpret '(rw-cue-percept) md)
  377. (when (equal :left (model-response md)) (setf tally (1+ tally)))))
  378. (push tally tally-50-no)
  379. ;;(setf (model-strength-assoc md) 0.90)
  380. (setf tally 0)
  381. (dotimes (we 100)
  382. (let* ((md (make-model :strength-assoc 0.9 :current test-input-3 :stm (list test-input-1 input-nil input-nil))))
  383. (interpret '(rw-cue-percept) md)
  384. (when (equal :left (model-response md)) (setf tally (1+ tally)))))
  385. (push tally tally-90-no)
  386. (setf (model-strength-assoc md) 0.10)
  387. (setf tally 0)
  388. (dotimes (we 100)
  389. (let* ((md (make-model :strength-assoc 0.1 :current test-input-3 :stm (list test-input-1 input-nil input-nil))))
  390. (interpret '(rw-cue-percept) md)
  391. (when (equal :left (model-response md)) (setf tally (1+ tally)))))
  392. (push tally tally-10-no)
  393. )
  394. (print tally-50-match)
  395. (print (list (avg tally-50-match) 0.975))
  396. ;;(check (AND (< 55 (avg tally-50-match)) (> 95 (avg tally-50-match))) "tally-50-match avg") ;;0.975
  397. (print tally-50-no)
  398. (print (list (avg tally-50-no) 0.925))
  399. ;;(check (AND (< 55 (avg tally-50-no)) (> 95 (avg tally-50-no))) "tally-50-no avg")
  400. (print tally-90-match)
  401. (print (list (avg tally-90-match) 0.995))
  402. ;;(check (AND (< 55 (avg tally-90-match)) (> 95 (avg tally-90-match))) "tally-90-match avg") ;;0.995
  403. (print tally-90-no)
  404. (print (list (avg tally-90-no) 0.905))
  405. ;;(check (AND (< 55 (avg tally-90-no)) (> 95 (avg tally-90-no))) "tally-90-no avg") ;; 0.905
  406. (print tally-10-match)
  407. (print (list (avg tally-10-match) 0.955))
  408. ;;(check (AND (< 55 (avg tally-10-match)) (> 95 (avg tally-10-match))) "tally-10-match avg") ;;0.955
  409. (print tally-90-no)
  410. (print (list (avg tally-10-no) 0.945))
  411. ;;(check (AND (< 55 (avg tally-10-no)) (> 95 (avg tally-10-no))) "tally-10-no avg") ;; 0.945
  412. )
  413. )
  414. ;; WORKS: Aj (requires manual checking of output because i'm lazy)
  415. (defun test-if-sa ()
  416. (let* ((md (make-model :current test-input-1 :strength-assoc 0.5)))
  417. (interpret '(if-strength-assoc) md)
  418. (check (equal nil (model-response md)) "no change because not at threshold")
  419. (let* ((md (make-model :current test-input-1 :strength-assoc 0.71)))
  420. (interpret '(if-strength-assoc) md)
  421. (check (equal :left (model-response md)) "changed in line with cue"))))
  422. ;; WORKS: Aj
  423. (defun test-current-type ()
  424. (let ((md (make-model :salient test-input-2 :current test-input-1)))
  425. (interpret '(if (current-target-p) (respond-left) (respond-right)) md)
  426. (check (equal :right (model-response md)) "check right response as not target")
  427. (interpret '(if (current-cue-p) (respond-left) (respond-right)) md)
  428. (check (equal :left (model-response md)) "check left response as is cue")
  429. (interpret '(prog2 (attend) (if (current-target-p) (respond-left) (respond-right))) md)
  430. (check (equal :left (model-response md)) "check left response as is target")
  431. (interpret '(if (current-cue-p) (respond-left) (respond-right)) md)
  432. (check (equal :right (model-response md)) "check right response as not cue")
  433. ))
  434. ;; works: Aj
  435. (defun test-retrieve ()
  436. (let ((md (make-model :salient test-input-2 :current test-input-1)))
  437. (interpret '(prog3 (put-stm) (prog2 (attend) (put-stm)) (put-stm)) md)
  438. (check (equal (input-location test-input-1) (input-location (third (model-stm md)))) "stm3 is item1")
  439. (check (equal (input-location test-input-2) (input-location (second (model-stm md)))) "stm2 is item2")
  440. (check (equal (input-location test-input-2) (input-location (first (model-stm md)))) "stm1 is item2")
  441. (check (equal (input-location test-input-2) (input-location (model-current md))) "model current is item2")
  442. (interpret '(retrieve-3) md)
  443. (check (equal (input-location test-input-1) (input-location (model-current md))) "model current is now item1, which was in stm3")
  444. (interpret '(retrieve-2) md)
  445. (check (equal (input-location test-input-2) (input-location (model-current md))) "model current is now item2, which was in stm2")
  446. (interpret '(retrieve-3) md)
  447. (check (equal (input-location test-input-1) (input-location (model-current md))) "model current is now item1, which was in stm3")
  448. (interpret '(retrieve-1) md)
  449. (check (equal (input-location test-input-2) (input-location (model-current md))) "model current is now item2, which was in stm1")
  450. (interpret '(retrieve-target-stm) md)
  451. (check (equal (input-type test-input-2) (input-type (model-current md))) "model current is now the target item")
  452. (interpret '(retrieve-cue-stm) md)
  453. (check (equal (input-type test-input-1) (input-type (model-current md))) "model current is now the most recent stimulus item")
  454. ))
  455. ;; WORKS: Aj
  456. (defun test-shift-attn ()
  457. (let ((md (make-model :attfocus :centre)))
  458. (check (equal (model-attfocus md) :centre) "attention focus is centre")
  459. (interpret '(shift-attn-cw) md)
  460. (check (equal (model-attfocus md) :right) "attention focus is right")
  461. (interpret '(shift-attn-cw) md)
  462. (check (equal (model-attfocus md) :left) "attention focus is left (all the way round)")
  463. (interpret '(shift-attn-cw) md)
  464. (check (equal (model-attfocus md) :centre) "attention focus is centre (from left)")
  465. (interpret '(shift-attn-ccw) md)
  466. (check (equal (model-attfocus md) :left) "attention focus is left")
  467. (interpret '(shift-attn-ccw) md)
  468. (check (equal (model-attfocus md) :right) "attention focus is right (from all the way round)")
  469. (interpret '(shift-attn-ccw) md)
  470. (check (equal (model-attfocus md) :centre) "attention focus is centre (from right)")
  471. ))
  472. ;; WORKS: Aj
  473. ;; timings have changed, so that ps have to give a response within time to save the results, rather than in the operator code... maybe change this though?
  474. (defun test-dmts-ops ()
  475. (let ((md (make-model :inputs (list input-1 input-2 input-3))))
  476. (check (equal input-nil (model-current md)) "current starts with input-nil")
  477. (interpret '(detect-attend) md)
  478. (check (equal input-1 (model-current md)) "current changes to input1")
  479. (interpret '(prog2 (move-att-left) (detect-attend)) md)
  480. (check (equal input-nil (model-current md)) "current changes to nil, due to clock")
  481. (setf (model-clock md) 1600)
  482. (interpret '(detect-attend) md)
  483. (check (equal input-2 (model-current md)) "current changes to input2")
  484. (interpret '(prog2 (move-att-right) (detect-attend)) md)
  485. (check (equal input-3 (model-current md)) "current changes to 3")
  486. (check (equal nil (model-response md)) "default response is nil")
  487. (setf (model-clock md) (- (first *response-window*) 200))
  488. (interpret '(respond-left) md)
  489. (check (equal nil (model-response md)) "no response, due to clock (too early)")
  490. (setf (model-clock md) (first *response-window*))
  491. (interpret '(respond-right) md)
  492. (check (equal :right (model-response md)) "responds right")
  493. (interpret '(respond-left) md)
  494. (check (equal :left (model-response md)) "responds left")
  495. (interpret '(respond-current) md)
  496. (check (equal :right (model-response md)) "responds current - input3 (right)")
  497. ))
  498. (defun test-program-depth ()
  499. (check (= 0 (program-depth '())) "empty tree")
  500. (check (= 1 (program-depth '(x))) "single entry")
  501. (check (= 2 (program-depth '(x (a) (b)))) "three items, two levels")
  502. (check (= 1 (program-depth '(x a b))) "three items, one level, terminals")
  503. (check (= 3 (program-depth '(x (a) (b (c))))) "four items, three levels")
  504. )
  505. (defun test-program-size ()
  506. (check (= 0 (program-size '())) "empty tree")
  507. (check (= 1 (program-size '(x))) "single entry")
  508. (check (= 3 (program-size '(x (a) (b)))) "three items, one level")
  509. (check (= 3 (program-size '(x a b))) "three items, one level, terminals")
  510. (check (= 4 (program-size '(x (a) (b (c))))) "four items, two levels")
  511. )
  512. (defun run-tests ()
  513. (format t "~&Testing: ")
  514. (test-nil-op)
  515. (test-if)
  516. (test-prog)
  517. (test-put-stm)
  518. (test-attend)
  519. (test-move-att)
  520. (test-attn-capture)
  521. (test-detect)
  522. (test-respond)
  523. (test-rehearsal)
  524. (test-while)
  525. (test-wait)
  526. (test-dotimes)
  527. (test-compare-current1-Rc)
  528. (test-compare-current1-r1)
  529. (test-compare-1-2-p)
  530. (test-compare-current1-p)
  531. (test-magic-operator)
  532. (test-retrieve)
  533. (test-dmts-ops)
  534. ;;(test-program-depth)
  535. ;;(test-program-size)
  536. (format t "~%-------- Done~&"))