-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7-UNRAVEL.lisp
1528 lines (1385 loc) · 46.8 KB
/
7-UNRAVEL.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Author : Frank Tamborello
;;; Copyright : (c) 2013-5 Frank Tamborello
;;; Availability: Public Domain
;;;
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the Lisp Lesser General Public
;;; License: the GNU Lesser General Public License as published by the
;;; Free Software Foundation (either version 2.1 of the License,
;;; or, at your option, any later version),
;;; and the Franz, Inc Lisp-specific preamble.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the Lisp Lesser General Public
;;; License along with this library; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;;; and see Franz, Inc.'s preamble to the GNU Lesser General Public License,
;;; http://opensource.franz.com/preamble.html.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Filename : UNRAVEL.lisp
;;; Revision : 57
;;;
;;; Description : This is a process model of systematic procedural error in a
;;; continuous task, Altmann & Trafton's UNRAVEL task. Based on Tamborello &
;;; Trafton's (2013a & b) model of postcompletion, anticipation, and perseveration
;;; error in a routine procedural non-continuous task. Developed with ACT-R6
;;; (r1227), boost-chunks module 10 (may be made available upon request),
;;; spacing-effect module (ACT-R extras), & new-threads 2.0a (ACT-R extras).
;;;
;;; Load by placing the model and support files in ACT-R's user-loads folder.
;;; Leave the numbers prepended to the file names as loading order is important.
;;; Your Lisp compiler may print some warnings the first time you load these files,
;;; but the model should execute regardless.
;;;
;;; Bugs: none known
;;;
;;; To do:
;;;
;;; ----- History -----
;;; See prior revisions for earlier history.
;;;
;;; 2014.07.30 fpt 45
;;; Run-model calls print-model-run whether one or all conditions are run.
;;;
;;; 2014.07.31 fpt 46
;;; Moved the trial's time delay from the procedure step retrieval request
;;; production to the two response productions, where it really makes more
;;; sense for them to be, particularly because I'm preparing to use a retrieval
;;; fail try again loop at that point to explain anctipations' longer resumption
;;;
;;; 2014.07.31 fpt 47
;;; Model longer resumption lag of anticipation errors: sometimes (how
;;; often?) the retrieved episodic context gets loaded into the goal buffer chunk
;;; rather than the imaginal buffer chunk. Does this by scheduling an event after
;;; the imaginal module to clear the imaginal buffer chunk step slot and instead
;;; load the context from the retrieved episodic chunk into the step slot of the
;;; goal buffer chunk.
;;;
;;; 2014.08.14 fpt 48
;;; Model longer resumption lag of anticipation errors:
;;; A quick & dirty version saps activation away by
;;; having a couple of dummy chunks occupying slots of the imaginal buffer chunk.
;;;
;;; 2014.08.15 fpt 49
;;; 1. Ditch the random rehearsal failure mechanism. Instead use a high :RT
;;;
;;; 2014.08.15 fpt 50
;;; 1. Ditch dummy chunks
;;;
;;; 2. Use a high :rt, like 3, to make the model occassionally miss rehearsals,
;;; rather than the model-busy-param.
;;;
;;; 2015.04.12 fpt 51
;;; Can the model work without the episodic module?
;;;
;;; 2015.04.17 fpt 52
;;; 1. Forked from r50 as the answer to the question posed by r51 seems to be no:
;;; The model's too unlikely to successfully rehearse the correct ps chunk.
;;; The model can't seem to build up enough difference in BL activation between the
;;; current, recent, and old chunks.
;;; 2. Turn on production compilation
;;;
;;; 2015.04.23 fpt 53
;;; 1. Trying to fix resumption behavior
;;; 2. Run-model now takes a keyword parameter, worker, telling it whether to
;;; return *resp-session-data*.
;;; 3. Workers break when more than one of them tries to write to the same file
;;; at the same time. If run-model's worker keyword paremeter it set to t then
;;; it doesn't write to a file.
;;;
;;; 2015.04.28 fpt 54
;;; Squashed bug: Somewhere along the way, rehearsal broke such that resumption
;;; no longer matches the data.
;;; Resumption perseverations seem to be sort of okay now.
;;;
;;; 2015.05.14 fpt 55
;;; Make concurrent-friendly: Run-model is simplified such that it'll run only
;;; one condition each time it's called, returning a list of the model run data.
;;; It assumes it's being run as a worker and it doesn't collect the timing data.
;;;
;;; 2015.05.22 fpt 56
;;; Replaced a circular list I used for the exp-wind's steps slot since it seemed
;;; problematic for sending over tcp socket streams.
;;;
;;; 2016.08.18 fpt 57
;;; Clean up some things, such as loading of ACT-R & support files.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Load ACT-R & support files
;; Be sure to point to your own copies of an ACT-R installation and this model's
;; support files.
(unless
(member ':act-r-6.0 *features*)
(load "/Users/frank/Documents/NRL/Error/actr6/load-act-r-6.lisp")
(load "/Users/frank/Documents/NRL/Error/actr6/extras/threads/new-threads.lisp")
(load "/Users/frank/Documents/NRL/Error/actr6/extras/spacing-effect/spacing-effect.lisp")
(load "/Users/frank/Documents/NRL/Error/UNRAVEL/UNRAVEL/virtual-experiment-window.lisp")
(load "/Users/frank/Documents/NRL/Error/UNRAVEL/UNRAVEL/seq-math.lisp")
(load "/Users/frank/Documents/NRL/Error/UNRAVEL/UNRAVEL/boost.lisp"))
(defparameter *data-directory*
"/Users/frank/Documents/temp/"
"The path into which you wish to save model data.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; The Task Environment: The Unravel Task
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar *resp-session-data* nil)
(defvar *latency-data* nil)
(setf *print-circle* t)
(defclass exp-window (virtual-experiment-window)
;; Later: two kinds, no-iti and 50% chance 1s iti
((iti :accessor iti :initarg :iti :initform 0)
(m :accessor m :initarg :m :initform nil)
(steps :accessor steps :initarg :steps :initform (list 'u 'n 'r 'a 'v 'e 'l))
(widgets :accessor widgets :initarg :widgets :initform nil)
;; stimulus attributes of the previous trial,
;; a list of symbols in order as they appear in this class definition
(previous :accessor previous :initarg :previous :initform nil)
(last-unravel :accessor last-unravel :initarg :last-unravel :initform nil)
(letter :accessor letter :initarg :letter :initform '(a b u v))
(number :accessor number :initarg :number :initform '(1 2 8 9))
(font :accessor font :initarg :font :initform '(lu li ru ri))
(color :accessor color :initarg :color :initform '(lr ly rr ry))
(height :accessor height :initarg :height :initform '(la lb ra rb))
(print-to-tl :accessor print-to-tl :initarg :print-to-tl :initform t)
(worker :accessor worker :initarg :worker :initform nil)
(offset-table
:accessor offset-table :initarg :offset-table
:initform (make-hash-table :size 7))
(data-int :accessor data-int :initarg :data-int :initform (list 0 0 0 0 0 0 0))
(data-base :accessor data-base :initarg :data-base :initform (list 0 0 0 0 0 0 0))
(r-data :accessor r-data :initarg :r-data :initform nil)
(l-data :accessor l-data :initarg :l-data :initform (make-instance 'latency-data))
(retrieval-tries :accessor retrieval-tries :initarg :retrieval-tries :initform 0))
(:default-initargs
:nblocks 4))
(defclass utrial (trial)
((xcond :accessor xcond :initarg :xcond :initform nil)
(trl-num :accessor trl-num :initarg :trl-num :initform 0)
(response :accessor response :initarg :response :initform nil)
(latency :accessor latency :initarg :latency :initform nil)
(int-nmbr :accessor int-nmbr :initarg :int-nmbr :initform nil)))
(defclass unravel-trial (utrial)
((interrupted :accessor interrupted :initarg :interrupted :initform nil)
(lr-order :accessor lr-order :initarg :lr-order :initform
(if (flip) 'letter-number 'number-letter))
(letter :accessor letter :initarg :letter :initform nil)
(number :accessor number :initarg :number :initform nil)
(font :accessor font :initarg :font :initform nil)
(color :accessor color :initarg :color :initform nil)
(height :accessor height :initarg :height :initform nil)
(offset :accessor offset :initarg :offset :initform nil))
(:default-initargs
:trial-kind 'u))
(defclass interruption-trial (utrial)
((stimulus
:accessor stimulus :initarg :stimulus
:initform
(randomize-list
'(#\u #\n #\r #\a #\v #\e #\l #\i #\f #\y #\b #\c #\o #\m)))
(busy-param :accessor busy-param :initarg :busy-param
:initform (act-r-random 100)))
(:default-initargs
:trial-kind 'interruption))
(defclass latency-data ()
((bsln-correct :accessor bsln-correct :initarg :bsln-correct :initform nil)
(bsln-err :accessor bsln-err :initarg :bsln-correct :initform nil)
(rsmp-correct :accessor rsmp-correct :initarg :rsmp-correct :initform nil)
(rsmp-err :accessor rsmp-err :initarg :rsmp-err :initform nil)
(int :accessor int :initarg :int :initform nil)))
(defun build-basic-trials (wind)
;; loop
;; loop for 10 interruption times
;; make a random number of u-trials:
;; "The number of trials for a given run was computed by adding three
;; to a sample from an exponential distribution with mean three."
;; make cond number of i-trials
(loop
with stim-1 = (loop
for i from 1 to (+ 3 (act-r-random 7))
collect (make-instance 'unravel-trial) into slst
finally (return slst))
for i from 1 to 10
collect (loop
for i from 1 to (xcond wind)
collect
(make-instance 'interruption-trial :int-nmbr i)
into slst
finally (return slst))
into stim-2
collect (loop
for i from 1 to (+ 3 (act-r-random 7))
collect (make-instance 'unravel-trial) into slst
finally (return slst))
into stim-2
finally (return (append stim-1 (flatten stim-2)))))
(defun do-stimgen (wind)
(loop
for i from 1 to (nblocks wind)
collect
(let ((stim-lst (build-basic-trials wind)))
(make-instance 'trial-block
:size (length stim-lst)
:trial-lst stim-lst))
into blk-lst
finally (return blk-lst)))
(defmethod initialize-instance :after ((wind exp-window) &key)
(setf (base-path wind) *data-directory*
(write-type wind) :SS)
(setf
(block-lst wind) (do-stimgen wind))
(loop
for i from 1 to 7
do (setf (gethash (nth (1- i) '(u n r a v e l)) (offset-table wind)) i)))
(defmethod make-data-path ((wind exp-window) type)
(when (base-path wind)
(make-pathname :directory (base-path wind)
:name
(format nil "unravel-data-~a" (m wind))
:type type
:version :newest)))
(defun infer-response-type (rsp)
(case rsp
(#\u 'u)
(#\i 'u)
(#\n 'n)
(#\f 'n)
(#\r 'r)
(#\y 'r)
(#\a 'a)
(#\b 'a)
(#\v 'v)
(#\c 'v)
(#\e 'e)
(#\o 'e)
(#\l 'l)
(#\m 'l)
(t (format t "setup-trial: response processing error"))))
(defun find-next-pseudocircular (itm lst &optional (tst #'eql))
"Takes an item, a list, and an optional test function which defaults to eql.
Returns the next item from the list of steps of the exp-wind. Known limitation:
does not terminate if the item is not in the list."
(if (apply tst itm `(,(car lst)))
(aif (car (cdr lst))
it
(car (steps (current-device))))
(find-next-pseudocircular itm (cdr lst) tst)))
(defmethod setup-trial :after ((wind exp-window) (trl unravel-trial))
;; set some blank slots
(setf (letter trl) (random-item (letter wind))
(number trl) (random-item (number wind))
(font trl) (random-item (font wind))
(color trl) (random-item (color wind))
(height trl) (random-item (height wind))
(xcond trl) (xcond wind)
(start-time trl) (current-time (timer wind)))
(let ((prv (previous wind))
(lu (last-unravel wind)))
;; when the current trial is an unravel-trial and the previous trial was
;; an interruption, set this trial's interrupted slot to t
(when (and (eql (class-name (class-of trl))
'unravel-trial)
(eql (class-name (class-of prv))
'interruption-trial))
(setf (interrupted trl) t))
;; when there's a previous unravel-trial,
;; set this unravel-trial's type to be the appropriate follower to the last
;; unravel-trial's
(when lu
(setf
(trial-kind trl)
(find-next-pseudocircular
(infer-response-type (response lu))
(steps wind)))
;; ...and ensure stim attr do not repeat from last trial
(dolist (attr '(letter number font color height))
(when (eq (slot-value trl attr)
(slot-value lu attr))
(setf (slot-value trl attr)
(random-not-item
(slot-value trl attr)
(slot-value wind attr))))))
;; draw items for act-r
(let*
((vis-locs
(define-chunks-fct
`((isa visual-location
screen-x 50
screen-y 50
kind rectangle
color gray
height 50
width 100)
(isa visual-location
screen-x 50
screen-y ,(case (height trl)
(la 0)
(lb 100)
(t 50))
kind text
color ,(case (color trl)
(lr 'red)
(ly 'yellow)
(t 'white))
height 20
width 10)
(isa visual-location
screen-x 150
screen-y ,(case (height trl)
(ra 0)
(rb 100)
(t 50))
kind text
color ,(case (color trl)
(rr 'red)
(ry 'yellow)
(t 'white))
height 20
width 10))))
(vis-objs
(define-chunks-fct
`((isa visual-object
value rectangle
screen-pos ,(nth 0 vis-locs))
(isa text
screen-pos ,(nth 1 vis-locs)
value ,(if (eq (lr-order trl)
'letter-number)
(letter trl)
(number trl))
color ,(chunk-slot-value-fct (nth 1 vis-locs) 'color)
status ,(case (font trl)
(li 'italic)
(lu 'underline)
(t 'regular)))
(isa text
screen-pos ,(nth 2 vis-locs)
value ,(if (eq (lr-order trl)
'letter-number)
(number trl)
(letter trl))
color ,(chunk-slot-value-fct (nth 2 vis-locs) 'color)
status ,(case (font trl)
(ri 'italic)
(ru 'underline)
(t 'regular)))))))
(let ((wgts nil))
(dotimes (i (length vis-locs) (setf (widgets wind) (nreverse wgts)))
(push
(make-instance 'widget
:vwindow wind
:nick-name (nth i '(box left right))
:vis-loc (nth i vis-locs)
:vis-obj (nth i vis-objs))
wgts))))
;; get act-r started on this trial
(proc-display :clear t)
(start-timing (timer wind))
(model-output "~%Trial kind: ~A~%" (trial-kind trl))))
(defmethod setup-trial :after ((wind exp-window) (trl interruption-trial))
;; set some blank slots
(setf (xcond trl) (xcond wind)
(start-time trl) (current-time (timer wind)))
;; draw items for act-r
(let*
((vis-locs
(define-chunks-fct
`((isa visual-location
screen-x 100
screen-y 100
kind text
color black))))
(vis-objs
(define-chunks-fct
`((isa text
value ,(stimulus trl)
screen-pos ,(nth 0 vis-locs)
color ,(chunk-slot-value-fct (nth 0 vis-locs) 'color))))))
(let ((wgts nil))
(dotimes (i (length vis-locs) (setf (widgets wind) (nreverse wgts)))
(push
(make-instance 'widget
:vwindow wind
:nick-name (nth i '(int-stim))
:vis-loc (nth i vis-locs)
:vis-obj (nth i vis-objs))
wgts))))
;; get act-r started on this trial
(proc-display :clear t)
(start-timing (timer wind))
(model-output "~%Trial kind: ~A~%" (trial-kind trl))
(model-output "Interruption Number: ~A~%" (int-nmbr trl))
(model-output "Time: ~A~%" (mp-time)))
;; Since the experiment has to wait for the model's execution to produce a trial response,
;; finish trials like they're event-based
(defmethod finish-trial ((wind exp-window))
(let ((blk (nth (cblock wind) (block-lst wind)))
(trl (current-trial wind)))
(incf (completed-trials wind))
(setf (trl-num trl) (completed-trials wind))
(model-output "Completed trials: ~A~%" (completed-trials wind))
(incf (current-idx blk))
(setf (previous wind) trl)
(when (eql (class-name (class-of trl))
'unravel-trial)
(setf (last-unravel wind) trl))
(if (eql (size blk) (current-idx blk))
;; if it's the final trial of the block, call finish-block
(finish-block wind blk)
;; else there's more trials in this block, so continue
(progn
(setf (current-trial wind)
(nth (current-idx blk) (trial-lst blk)))
(setup-trial wind (current-trial wind))))))
(defmethod write-trial ((trl trial) stream)
;; Don't print to stream (a file) if this is running on a worker node
(unless (worker (current-device))
;; both trial kinds
(format stream "~A " (snum (current-device)))
(format stream "~A " (xcond trl))
(format stream "~A " (cblock (current-device)))
(format stream "~A " (trl-num trl))
(format stream "~A " (trial-kind trl))
(format stream "~7,1F " (latency trl))
(format stream "~7,1F " (start-time trl))
;; interruptions
(if (eql (trial-kind trl) 'interruption)
(progn
(terpri stream)
(push (latency trl) (int (l-data (current-device)))))
;; unravel trials
(progn
(if (not (interrupted trl))
(if (= 0 (offset trl))
(push (latency trl) (bsln-correct (l-data (current-device))))
(push (latency trl) (bsln-err (l-data (current-device)))))
(if (= 0 (offset trl))
(push (latency trl) (rsmp-correct (l-data (current-device))))
(push (latency trl) (rsmp-err (l-data (current-device))))))
(format stream "~A " (response trl))
(format stream "~A " (offset trl))
(format stream "~A " (interrupted trl))
(format stream "~A " (lr-order trl))
(format stream "~A " (letter trl))
(format stream "~A " (number trl))
(format stream "~A " (font trl))
(format stream "~A " (color trl))
(format stream "~A " (height trl))
(terpri stream)))))
;;;; ---------------------------------------------------------------------- ;;;;
;;;; ACT-R Device Handler Methods
;;;; ---------------------------------------------------------------------- ;;;;
(defmethod build-vis-locs-for ((device exp-window) vismod)
(declare (ignore vismod))
(labels ((wdgt-lst (lst)
(if (null lst)
nil
(cons (vis-loc (car lst)) (wdgt-lst (cdr lst))))))
(wdgt-lst (widgets device))))
(defmethod vis-loc-to-obj ((device exp-window) vl)
"Returns the vis-obj of the widget containing the vis-loc."
(labels ((get-vis-obj (lst)
(cond
((null lst) nil)
((eq (vis-loc (car lst)) vl) (vis-obj (car lst)))
(t (get-vis-obj (cdr lst))))))
(get-vis-obj (widgets device))))
(defmethod device-move-cursor-to ((device exp-window) loc)
(setf (mouse-pos device) loc))
(defmethod get-mouse-coordinates ((device exp-window))
(mouse-pos device))
(defmethod device-handle-click ((device exp-window))
(awhen (current-widget device (get-mouse-coordinates device))
(progn
(model-output "~%Model clicked ~A.~%" (nick-name it))
(state-check device (nick-name it)))))
(defmethod device-handle-keypress ((device exp-window) key)
(let ((trl (current-trial device)))
;; record the data into the trial so that write-trial can write it to the date file later on
(if (eql (trial-kind trl) 'interruption)
;; how do I terminate when key is return?
(progn
(setf (latency trl) (start-stop-timer (timer device)))
(finish-trial device))
(progn
(setf (response trl) key
(latency trl) (start-stop-timer (timer device))
(offset trl)
(let ((exp-nmbr
(gethash
(trial-kind trl)
(offset-table device)))
(rsp-nmbr
(gethash
(infer-response-type (response trl))
(offset-table device))))
(cond
((< (abs (- rsp-nmbr exp-nmbr)) 4) (- rsp-nmbr exp-nmbr))
((> exp-nmbr rsp-nmbr) (- (+ rsp-nmbr 7) exp-nmbr))
((> rsp-nmbr exp-nmbr) (- rsp-nmbr (+ exp-nmbr 7))))))
;; incf the window's data lists
(if (interrupted trl)
(incf
(nth
(+ 3
(offset trl))
(data-int device)))
(incf
(nth
(+ 3
(offset trl))
(data-base device))))
(when (interrupted trl) (model-output "~%Response Offset: ~A~%" (offset trl)))
(finish-trial device)))))
;;;; ---------------------------------------------------------------------- ;;;;
;;;; Testing & Running
;;;; ---------------------------------------------------------------------- ;;;;
(defmethod run-experiment ((wind exp-window))
(unless (worker wind)
(with-open-file
(strm
(data-file wind)
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
;; run#, trial#, trial-type/task-id, the correct procedure step, the model's
;; action, got step# - expected step#, the step was/was not interrupted, the
;; model's action was/was not correct, Inter-Trial Interval, Step Completion
;; Latency
(let ((col-hdings (list "Run" "Cond" "Block" "Trial" "Kind" "RT" "StTime" "Response" "Offset" "Intrpt" "LR_order" "letter" "number" "font" "color" "height")))
(format strm "~{~a~^ ~}~%" col-hdings))))
(setup-experiment wind)
(progn
(goal-focus start-unravel)
(schedule-set-buffer-chunk
'imaginal
(car (define-chunks-fct '((isa task-state step start))))
0 :module 'imaginal))
(run-block wind (car (block-lst wind))))
(defun summarize-cond (data)
(let ((s-data (list (list 0 0 0 0 0 0 0)
(list 0 0 0 0 0 0 0)))
(nulls 0)
(n 0))
(loop for i in data ; iterate through runs
do (if (null i)
(incf nulls)
(loop for j from 0 to 1 ; iterate through trial-types
do (loop for k from 0 to 6 ; iterate through offsets
do (incf (nth k (nth j s-data)) (nth k (nth j i)))))))
(terpri)
(when (> 0 nulls)
(format t "Null runs: ~A~%" nulls))
(setf n (- (length data) nulls))
(if (eq n 0)
(format t "No run finished!~%")
(loop for i from 0 to 1
collect (loop for j from 0 to 6
collect (/ (nth j (nth i s-data)) n) into type-summary
finally (return type-summary)) into summary
finally (return summary)))))
(defun print-model-run (data latencies &optional cond)
(terpri)
(let ((param (list ':mas ':ans ':boosti ':boostq)))
(format t "~{~a: ~a ~}~%" (flatten (pairlis param (no-output (sgp-fct param))))))
(format t " -3 -2 -1 +1 +2 +3~%")
(loop for h from 1 to (length data) ; for however many conditions are run
do (format t "Cond: ~A~%" (aif cond it h))
do (loop for i from 0 to 1
do (format t "~A " (nth i '("Int" "Bsln")))
do (loop for item in (nth i (nth (1- h) data))
with count = 0
do (unless (eq count 3)
(format t "~2,1F " item))
do (incf count))
(terpri))
(format t "Latencies: mean sd~%")
(format t "Baseline, Correct: ~{~2,1F~^ ~}~%"
(multiple-value-list
(seq-mean-stdev
(flatten
(mapcar #'bsln-correct
(nth (1- h) latencies))))))
(format t "Baseline, Error: ~{~2,1F~^ ~}~%"
(multiple-value-list
(seq-mean-stdev
(flatten
(mapcar #'bsln-err
(nth (1- h) latencies))))))
(format t "Resump'n, Correct: ~{~2,1F~^ ~}~%"
(multiple-value-list
(seq-mean-stdev
(flatten
(mapcar #'rsmp-correct
(nth (1- h) latencies))))))
(format t "Resump'n, Error: ~{~2,1F~^ ~}~%"
(multiple-value-list
(seq-mean-stdev
(flatten
(mapcar #'rsmp-err
(nth (1- h) latencies))))))
(format t "Int Duration: ~{~2,1F~^ ~}~%"
(multiple-value-list
(seq-mean-stdev
(flatten
(let (sums
(lats (flatten (mapcar #'int (nth (1- h) latencies)))))
(do ((i 0 (incf i (aif cond it h))))
((eq i (length lats))
sums)
(push (apply #'+ (subseq lats i (+ i (aif cond it h)))) sums)))))))
(terpri))
(terpri))
(defun print-r-friendly ()
(let ((data *resp-session-data*))
(loop for h from 1 to (length data) ; for however many conditions are run
do (loop for i from 0 to 1
do (format t "mm~a~a <- c(" h (nth i '(".int" ".bsln")))
do (loop for item in (nth i (nth (1- h) data))
with count = 0
do (unless (eq count 3)
(if (eq count 6)
(format t "~2,1F)~%" item)
(format t "~2,1F, " item)))
do (incf count))))))
(defun run-model (&key (n 1) (c 1) (m 0) (p t))
(let (data)
(format t "C# ~a, Run:" c)
(dotimes (i n (progn
(format t " complete.~%")
data))
(progn
(reset)
(install-device
(make-instance
'exp-window
:snum i
:m m
:xcond c
:print-to-tl p
:worker t))
(format t " ~A" i)
(run-experiment (current-device))
(run-until-condition (lambda () nil))
(push (r-data (current-device)) data)))))
;; full-featured
(defmethod finish-experiment ((wind virtual-experiment-window))
(progn
(schedule-break-after-all :details "…the end.")
(let ((dlsts `(,(data-int wind) ,(data-base wind)))
(sums `(,(apply #'+ (data-int wind)) ,(apply #'+ (data-base wind)))))
(loop
for i from 0 to 1
collect (loop for j in (nth i dlsts)
collect (* 100 (/ j (nth i sums))) into rates
finally (return rates)) into rates
finally (return (setf (r-data wind) rates))))))
;;;;
;;;; Specialty Functions for the Model
;;;;
(defun unravel-vl (step)
(let ((rqst
(case step
(r (schedule-module-request
'visual-location
(define-chunk-spec-fct
'(isa visual-location
kind text
- color white))
0
:module 'visual))
(a (schedule-module-request
'visual-location
(define-chunk-spec-fct
'(isa visual-location
kind text
- screen-y 50))
0
:module 'visual))
(t (schedule-module-request
'visual-location
(define-chunk-spec-fct
'(isa visual-location
kind text
< screen-x 100))
0
:module 'visual)))))
; (model-output "~A~%" rqst)
rqst))
(defun process-vo (value status step)
(cond
((and (eql step 'u) (not (eql status 'regular)))
(if (eql status 'italic) 'i 'u))
((and (eql step 'n) (or (eql value 'a) (eql value 'b))) 'n)
((and (eql step 'n) (or (eql value 'u) (eql value 'v))) 'f)
((and (eql step 'v) (or (eql value 'a) (eql value 'u))) 'v)
((and (eql step 'v) (or (eql value 'b) (eql value 'v))) 'c)
((numberp value)
(cond
((and (eql step 'e) (evenp value))'e)
((and (eql step 'e) (oddp value)) 'o)
((and (eql step 'l) (< value 5)) 'l)
((and (eql step 'l) (> value 5)) 'm)))))
(defun print-some-cats (tm start-ep &optional other-ep full-back)
(loop for i from start-ep downto (- start-ep (if full-back 6 3))
do (funcall
#'print-chunk-activation-trace-fct
(intern (format nil "~a~a~a" "EPISODIC" i "-0"))
tm)
finally (aif other-ep
(funcall
#'print-chunk-activation-trace-fct
(intern (format nil "~a~a~a" "EPISODIC" it "-0"))
tm))))
;;;; ---------------------------------------------------------------------- ;;;;
;;;; The Model
;;;; ---------------------------------------------------------------------- ;;;;
(progn
(clear-all)
(define-model
unravel
(let ((mas 7))
(sgp-fct
(list
;; model debugging & running
:v nil
:trace-detail 'low
;; declarative
:imaginal-activation 1.1
:ans .3 ;.325
:rt -5 ; 3.03
:bll .5
:mas mas
:ol nil ; spacing effect module needs this to be nil
; :sact 'medium
;; spacing-effect module
:eblse t
:se-intercept 0.177
:se-scale .217
;; episodic
:boostq 4 ; 3
:boosti .5 ; .85
; :boost-power nil
#| ;; productions
:ul t
:egs 1
:epl t ; production compilation
:pct t
|#
;; central parameters
:er t :esc t))
(mapcar
'chunk-type-fct
'((task operator step)
((unravel (:include task)))
((resume (:include task)))
((interruption (:include task)))
(procedure-step place)
(episodic context unique-name)
(task-state step))) ; dummy0 dummy1 dummy2 dummy3)))
(let
((cks
`((start isa chunk)
(start-unravel
isa unravel
step start
operator retrieve-ps)))
(ps-cks)
(sjis))
;; iterate over the list of UNRAVEL steps
(loop
for i from 0 to 6
collecting
`(,(nth i '(u n r a v e l))
isa procedure-step
place ,(nth i '(u n r a v e l)))
into ps
finally (return (setf ps-cks ps)))
;; add chunks & ps-chunks into declarative memory
;; saving the chunk names to feed to add-sji
(setf ps-cks (add-dm-fct (append cks ps-cks)))
;; but exclude start & start-unravel
(let (temp)
(loop
for i in ps-cks
do (unless
(member i '(start start-unravel))
(push i temp))
finally (return (setf ps-cks (nreverse temp)))))
;; set strengths of associations for the procedure-step chunks
;; reciprocal function of distance to succeeding step,
;; modulo number of steps, multiplied by :mas
(push `(start ,(car ps-cks) ,mas) sjis)
(push '(start start 0) sjis)
(loop for j from 1 to (length ps-cks)
do (loop for i from 1 to (length ps-cks)
do (push
`(,(nth (1- j) ps-cks)
,(nth (1- i) ps-cks)
,(if (eq j i)
;; for linear boosting
mas
;; for exponential boosting
; (- mas)
(/
mas
(1+
(if (> j i)
(- (+ i 7) j)
(- i j))))))
sjis)))
(add-sji-fct sjis)))
;;;
;; Productions
;;;
(p retrieve-next-procedure-step
=goal>
isa unravel
operator retrieve-ps
=imaginal>
isa task-state
step =s
?episodic>
buffer empty
state free
?retrieval>
buffer empty
state free
#| !eval! (not
(eq
'interruption
(trial-kind (current-trial (current-device))))) |#
==>
=goal>
operator retrieving-ps
=imaginal>
+retrieval>
isa procedure-step
- place =s
; !eval! (buffer-chunk imaginal)
; !eval! (buffer-chunk goal)
; !eval! (mp-show-queue)
; !eval! (get-m-buffer-chunks 'goal)
)
(p retrieve-next-procedure-step-failed-try-again
=goal>
isa unravel
operator retrieving-ps
?retrieval>
buffer empty
state error
=imaginal>
isa task-state
step =s
==>
=imaginal>
+retrieval>
isa procedure-step
- place =s
=goal>)
;; Find
(p retrieved-ps
=goal>
isa unravel
operator retrieving-ps
=retrieval>
isa procedure-step
place =p
=imaginal>