; -*- coding: iso-8859-1; mode: Lisp; indent-tabs-mode: nil; -*- ; A model for predicting performance in a simple dynamic task ; 3rd place in the 2009 dynamic stocks and flows challenge ; http://www.hss.cmu.edu/departments/sds/ddmlab/modeldsf/ ; ; (c) 2009 Marc Halbruegge #| @Article{Halbruegge:2010:Keep_it_simple, author = {Marc Halbr{\"u}gge}, title = {Keep it simple - A case study of model development in the context of the Dynamic Stocks and Flows (DSF) task}, journal = {Journal of Artificial General Intelligence}, year = {2010}, volume = {2}, number = {2}, doi = {10.2478/v10229-011-0008-2}, pages = {38--51} } @Unpublished{Halbruegge:2009:DSF, author = {Marc Halbr{\"u}gge}, title = {Taking Occam seriously -- A simple and straightforward model in ACT-R}, note = {Talk at the International Conference on Cognitive Modeling (ICCM'09). 3rd place in the ``Dynamic Stocks and Flows'' modeling challenge}, month = {July 25}, year = {2009} } |# #| This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. 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 GNU 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 |# #+:packaged-actr (in-package :act-r) (clear-all) ; ------------------------------ ; uni-files version (defvar *DSFState* nil) (defvar *Amount* nil) (defvar *Time* nil) (defvar *Goal* nil) (defvar *UI* nil) (defvar *UO* nil) (defvar *EI* nil) (defvar *EO* nil) (defvar *Data* nil) (defvar *DSF-Counter* 0) (defparameter *tcp-sock* nil) (defparameter *initial-string* nil) (defun connsoc(entry-id name version version-type ACTR-name) (setf *initial-string* (format nil "~a ~a ~a ~a ~a" entry-id name version version-type ACTR-name)) (format t "~a" *initial-string*) (setf *tcp-sock* (uni-make-socket "127.0.0.1" 9548)) (format t "connected") (uni-send-string *tcp-sock* *initial-string*)) (defun setting-variables () (setf *data* (uni-socket-read-line *tcp-sock*)) (print *data*) (setf *data* (format nil "(~a)" *data*)) (print *data*) (setf *data* (read-from-string *data*)) (print *data*) (setf *DSFState* (first *data*)) (setf *Time* (third *data*)) (setf *Goal* (fifth *data*)) (setf *Amount* (seventh *data*)) (setf *UI* (nth 12 *data*)) (setf *UO* (nth 14 *data*)) (setf *EI* (nth 8 *data*)) (setf *EO* (nth 10 *data*))) (defclass dsf-device (device-interface) ()) (defmethod get-mouse-coordinates ((hd dsf-device)) (vector 0 0)) ; return a list of instances of Icon-Feature (defmethod build-features-for ((hd dsf-device) (vis-mod vision-module)) (print "build-features-for") (print *ei*) (print *eo*) (print *ui*) (print *uo*) (let ((result nil)) (push (make-instance 'text-feature :value *Amount* :x 900 :y 500 :width 30 :height 10) result) (push (make-instance 'text-feature :value *Goal* :x 900 :y 700 :width 30 :height 10) result) (if (>= *ei* 0.0) (push (make-instance 'text-feature :value *EI* :x 600 :y 700 :width 30 :height 10) result)) (if (>= *eo* 0.0) (push (make-instance 'text-feature :value *EO* :x 600 :y 500 :width 30 :height 10) result)) (if (>= *ui* 0.0) (push (make-instance 'text-feature :value *UI* :x 300 :y 700 :width 30 :height 10) result)) (if (>= *uo* 0.0) (push (make-instance 'text-feature :value *UO* :x 300 :y 500 :width 30 :height 10) result)) result)) (defmethod device-speak-string ((hd dsf-device) string) (uni-send-string *tcp-sock* (format nil "DECISION UI ~d UO ~d EI ~d EO ~d" *ui* *uo* *ei* *eo*)) (setting-variables)) (defun experiment(seconds name version-name ACTR-name) (setf *DSFState* nil) (setf *Amount* nil) (setf *Time* nil) (setf *Goal* nil) (setf *UI* nil) (setf *UO* nil) (setf *EI* nil) (setf *EO* nil) (setf *Data* nil) (setf *DSF-Counter* 0) (connsoc "ENTRY-ID" name "VERSION" version-name ACTR-name) (format t "post connsoc") (setting-variables) (format t "post setting-variables") (let ((adev (make-instance 'dsf-device))) (install-device adev) (run seconds :real-time nil)) T) (defun collect-data(seconds) (experiment seconds "Varun1" "BATCH" "NONACTR")) ; ------------------------------ (define-model dont-drink-the-water (sgp :v t :show-focus nil :esc t :act nil ; :lf 0 ; :iu 0 :ul t ; utility learning :OL 6 ; optimized learning :BLL 0.5 ; base-level learning :EGs 0.2 ; expected gain noise (utility noise) ) (chunk-type bottich ; internal state of the model state ; current state of the outer environment target amount ei eo ui uo ; helpers for the analytical models last-ei last-eo last-ui last-uo ; remember last performance in order to ; decide whether we got better last-diff ) (add-dm (start isa chunk) (attend-uo isa chunk) (encode-uo isa chunk) (attend-ui isa chunk) (encode-ui isa chunk) (attend-eo isa chunk) (encode-eo isa chunk) (attend-ei isa chunk) (encode-ei isa chunk) (attend-amount isa chunk) (encode-amount isa chunk) (attend-target isa chunk) (encode-target isa chunk) (start-decision isa chunk) (goal isa bottich state start) ) (p start-trial =goal> isa bottich state start ; start AFTER last action has been processed ; by the environment ?vocal> state free ==> !eval! (proc-display :clear T) !eval! (print-visicon) +visual-location> isa visual-location screen-x 300 screen-y 500 =goal> state attend-uo ) ; - uo ------------------------------------------- (p attend-1 =goal> isa bottich state attend-uo =visual-location> isa visual-location ?visual> state free ==> +visual> isa move-attention screen-pos =visual-location =goal> state encode-uo ) (p encode-1 =goal> isa bottich state encode-uo =visual> isa text value =val ==> +visual-location> isa visual-location screen-x 300 screen-y 700 =goal> uo =val state attend-ui ) (p no-attend-1 =goal> isa bottich state attend-uo ?visual-location> state error ==> +visual-location> isa visual-location screen-x 300 screen-y 700 =goal> state attend-ui ) ; - ui ------------------------------------------- (p attend-2 =goal> isa bottich state attend-ui =visual-location> isa visual-location ?visual> state free ==> +visual> isa move-attention screen-pos =visual-location =goal> state encode-ui ) (p encode-2 =goal> isa bottich state encode-ui =visual> isa text value =val ==> +visual-location> isa visual-location screen-x 600 screen-y 500 =goal> ui =val state attend-eo ) (p no-attend-2 =goal> isa bottich state attend-ui ?visual-location> state error ==> +visual-location> isa visual-location screen-x 600 screen-y 500 =goal> state attend-eo ) ; - eo ------------------------------------------- (p attend-3 =goal> isa bottich state attend-eo =visual-location> isa visual-location ?visual> state free ==> +visual> isa move-attention screen-pos =visual-location =goal> state encode-eo ) (p encode-3 =goal> isa bottich state encode-eo =visual> isa text value =val ==> +visual-location> isa visual-location screen-x 600 screen-y 700 =goal> eo =val state attend-ei ) (p no-attend-3 =goal> isa bottich state attend-eo ?visual-location> state error ==> +visual-location> isa visual-location screen-x 600 screen-y 700 =goal> state attend-ei ) ; - ei ------------------------------------------- (p attend-4 =goal> isa bottich state attend-ei =visual-location> isa visual-location ?visual> state free ==> +visual> isa move-attention screen-pos =visual-location =goal> state encode-ei ) (p encode-4 =goal> isa bottich state encode-ei =visual> isa text value =val ==> +visual-location> isa visual-location screen-x 900 screen-y 500 =goal> ei =val state attend-amount ) (p no-attend-4 =goal> isa bottich state attend-ei ?visual-location> state error ==> +visual-location> isa visual-location screen-x 900 screen-y 500 =goal> state attend-amount ) ; - amount ------------------------------------------- (p attend-5 =goal> isa bottich state attend-amount =visual-location> isa visual-location ?visual> state free ==> +visual> isa move-attention screen-pos =visual-location =goal> state encode-amount ) (p encode-5 =goal> isa bottich state encode-amount =visual> isa text value =val ==> +visual-location> isa visual-location screen-x 900 screen-y 700 =goal> amount =val state attend-target ) (p no-attend-5 =goal> isa bottich state attend-amount ?visual-location> state error ==> +visual-location> isa visual-location screen-x 900 screen-y 700 =goal> state attend-target ) ; - target ------------------------------------------- (p attend-6 =goal> isa bottich state attend-target =visual-location> isa visual-location ?visual> state free ==> +visual> isa move-attention screen-pos =visual-location =goal> state encode-target ) (p encode-finish-perfect-amount =goal> isa bottich state encode-target amount =theAmount =visual> isa text value =theAmount ==> =goal> target =theAmount state start-decision ) (spp encode-finish-perfect-amount :reward 10.0) (p encode-finish-bad-amount =goal> isa bottich state encode-target amount =theAmount =visual> isa text value =val !safe-eval! (>= (abs (- =val =theAmount)) 1.0) ==> =goal> target =val state start-decision ) (spp encode-finish-bad-amount :reward 0.0) (p encode-finish-very-good-amount =goal> isa bottich state encode-target amount =theAmount =visual> isa text value =val !safe-eval! (< (abs (- =val =theAmount)) 0.05) !safe-eval! (not (eq =val =theAmount)) ==> =goal> target =val state start-decision ) (spp encode-finish-very-good-amount :reward 7.0) (p encode-finish-good-amount =goal> isa bottich state encode-target amount =theAmount =visual> isa text value =val !safe-eval! (> (abs (- =val =theAmount)) 0.05) !safe-eval! (< (abs (- =val =theAmount)) 1.0) ==> =goal> target =val state start-decision ) (spp encode-finish-good-amount :reward 3.0) (p encode-finish-made-progress =goal> isa bottich state encode-target amount =theAmount last-diff =theLastDiff =visual> isa text value =val !safe-eval! (not (< (abs (- =val =theAmount)) 1.0)) ; better than last time !safe-eval! (< (abs (- =val =theAmount)) (abs =theLastDiff)) ==> =goal> target =val state start-decision ) (spp encode-finish-made-progress :reward 1.0) (p encode-finish-no-progress =goal> isa bottich state encode-target amount =theAmount last-diff =theLastDiff =visual> isa text value =val !safe-eval! (not (< (abs (- =val =theAmount)) 1.0)) ; was bad last time !safe-eval! (not (< (abs =theLastDiff) 1.0)) ; worse than last time !safe-eval! (>= (abs (- =val =theAmount)) (abs =theLastDiff)) ==> =goal> target =val state start-decision ) (spp encode-finish-no-progress :reward -5.0) (p encode-finish-became-really-bad =goal> isa bottich state encode-target amount =theAmount last-diff =theLastDiff =visual> isa text value =val !safe-eval! (not (< (abs (- =val =theAmount)) 1.0)) ; was good last time !safe-eval! (< (abs =theLastDiff) 1.0) ; worse than last time !safe-eval! (>= (abs (- =val =theAmount)) (abs =theLastDiff)) ==> =goal> target =val state start-decision ) (spp encode-finish-became-really-bad :reward -10.0) (p no-attend-6 =goal> isa bottich state attend-amount ?visual-location> state error ==> !output! "no visual info" =goal> state start ) ; ---------------------------------------------------- ; decision stuff (p decide-try-around =goal> isa bottich state start-decision amount =theAmount target =theTarget ei nil eo nil !bind! =diff (- =theAmount =theTarget) ?vocal> state free ==> !output! (=theAmount) !output! (=theTarget) !eval! (if (< =diff 0)(setf *ui* (- 0 =diff))(setf *ui* 0.0)) !eval! (if (< =diff 0)(setf *uo* 0.0)(setf *uo* =diff)) !bind! =output (format nil "~A;~A" *ui* *uo*) !output! =output =goal> state start +vocal> isa speak string =output ) (spp decide-try-around :u 5.0) ; ---------------------------------------------------- (p decide-constant-environment-analytical =goal> isa bottich state start-decision ei =ei eo =eo amount =theAmount target =theTarget !bind! =diff (- =theAmount =theTarget) ?vocal> state free ==> !output! (=theAmount) !output! (=theTarget) !eval! (if (< =diff 0)(setf *ui* (- 0 =diff))(setf *ui* 0.0)) !eval! (if (< =diff 0)(setf *uo* 0.0)(setf *uo* =diff)) !bind! =output (format nil "~A;~A" *ui* *uo*) !output! =output =goal> state start last-ei =ei last-eo =eo last-diff =diff +vocal> isa speak string =output ) (spp decide-constant-environment-analytical :u 4.0) ; ---------------------------------------------------- (p decide-constant-environment-practical =goal> isa bottich state start-decision ei =ei eo =eo amount =theAmount target =theTarget !bind! =diff (- (max (min =theAmount 10) 0) =theTarget) ?vocal> state free ==> !output! (max (min =theAmount 10) 0) !output! (=theTarget) !eval! (if (< =diff 0)(setf *ui* (- 0 =diff))(setf *ui* 0.0)) !eval! (if (< =diff 0)(setf *uo* 0.0)(setf *uo* =diff)) !bind! =output (format nil "~A;~A" *ui* *uo*) !output! =output =goal> state start last-ei =ei last-eo =eo last-diff =diff +vocal> isa speak string =output ) (spp decide-constant-environment-practical :u 5.0) ; -------------------------------------------------------------------------- (p decide-constant-change-analytical =goal> isa bottich state start-decision amount =theAmount target =theTarget ei =ei eo =eo last-ei =ei last-eo =eo !bind! =diff (- =theAmount =theTarget) !bind! =expected-diff (- =ei =eo) !bind! =combined-diff (+ =diff =expected-diff) ?vocal> state free ==> !output! (=theAmount) !output! (=theTarget) !eval! (if (< =combined-diff 0)(setf *ui* (- 0 =combined-diff))(setf *ui* 0.0)) !eval! (if (< =combined-diff 0)(setf *uo* 0.0)(setf *uo* =combined-diff)) !bind! =output (format nil "~A;~A" *ui* *uo*) !output! =output =goal> state start last-ei =ei last-eo =eo last-diff =diff +vocal> isa speak string =output ) (spp decide-constant-change-analytical :u 3.0) ; -------------------------------------------------------------------------- (p decide-constant-change-practical =goal> isa bottich state start-decision amount =theAmount target =theTarget ei =ei eo =eo last-ei =ei last-eo =eo !bind! =diff (- (max (min =theAmount 10) 0) =theTarget) !bind! =expected-diff (- =ei =eo) !bind! =combined-diff (+ =diff =expected-diff) ?vocal> state free ==> !output! (max (min =theAmount 10) 0) !output! (=theTarget) !eval! (if (< =combined-diff 0)(setf *ui* (- 0 =combined-diff))(setf *ui* 0.0)) !eval! (if (< =combined-diff 0)(setf *uo* 0.0)(setf *uo* =combined-diff)) !bind! =output (format nil "~A;~A" *ui* *uo*) !output! =output =goal> state start last-ei =ei last-eo =eo last-diff =diff +vocal> isa speak string =output ) (spp decide-constant-change-practical :u 5.0) ; -------------------------------------------------------------------------- (p decide-changing-change-analytical =goal> isa bottich state start-decision amount =theAmount target =theTarget ei =ei eo =eo last-ei =last-ei last-eo =last-eo !bind! =diff (- =theAmount =theTarget) !bind! =last-eio (- =last-ei =last-eo) !bind! =cur-eio (- =ei =eo) !bind! =diff-eio (- =cur-eio =last-eio) !bind! =combined-diff (+ =diff =cur-eio =diff-eio) ?vocal> state free ==> !output! (=theAmount) !output! (=theTarget) !eval! (if (< =combined-diff 0)(setf *ui* (- 0 =combined-diff))(setf *ui* 0.0)) !eval! (if (< =combined-diff 0)(setf *uo* 0.0)(setf *uo* =combined-diff)) !bind! =output (format nil "~A;~A" *ui* *uo*) !output! =output =goal> state start last-ei =ei last-eo =eo last-diff =diff +vocal> isa speak string =output ) (spp decide-changing-change-analytical :u 0.0) ; -------------------------------------------------------------------------- (p decide-changing-change-practical =goal> isa bottich state start-decision amount =theAmount target =theTarget ei =ei eo =eo last-ei =last-ei last-eo =last-eo !bind! =diff (- (max (min =theAmount 10) 0) =theTarget) !bind! =last-eio (- =last-ei =last-eo) !bind! =cur-eio (- =ei =eo) !bind! =diff-eio (- =cur-eio =last-eio) !bind! =combined-diff (+ =diff =cur-eio =diff-eio) ?vocal> state free ==> !output! (max (min =theAmount 10) 0) !output! (=theTarget) !eval! (if (< =combined-diff 0)(setf *ui* (- 0 =combined-diff))(setf *ui* 0.0)) !eval! (if (< =combined-diff 0)(setf *uo* 0.0)(setf *uo* =combined-diff)) !bind! =output (format nil "~A;~A" *ui* *uo*) !output! =output =goal> state start last-ei =ei last-eo =eo last-diff =diff +vocal> isa speak string =output ) (spp decide-changing-change-practical :u 2.0) (goal-focus goal) (setf *actr-enabled-p* t) )