summaryrefslogtreecommitdiff
path: root/modeling/pyactr_tut.py
diff options
context:
space:
mode:
authorNiclas Dobbertin <niclas.dobbertin@mailbox.org>2024-03-12 14:36:17 +0100
committerNiclas Dobbertin <niclas.dobbertin@mailbox.org>2024-03-12 14:36:17 +0100
commit944bbb93c39d8a3ee186dacfa50ba4ec514ad160 (patch)
tree2e0f18651550b30a4686abf1eedfb0fc1f90bcd9 /modeling/pyactr_tut.py
parentd5e763d6e552b7fe60a9e82d5759e671f8c188f3 (diff)
tmp modeling
Diffstat (limited to 'modeling/pyactr_tut.py')
-rw-r--r--modeling/pyactr_tut.py512
1 files changed, 512 insertions, 0 deletions
diff --git a/modeling/pyactr_tut.py b/modeling/pyactr_tut.py
new file mode 100644
index 0000000..a44209e
--- /dev/null
+++ b/modeling/pyactr_tut.py
@@ -0,0 +1,512 @@
+#!/usr/bin/env python3
+
+import pyactr as actr
+
+
+def memory_motor():
+ playing_memory = actr.ACTRModel()
+
+ actr.chunktype("playgame", "game, activity")
+
+ initial_chunk = actr.makechunk(typename="playgame", game="memory")
+
+ goal = playing_memory.set_goal("goal")
+
+ playing_memory.productionstring(
+ name="startplaying",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity None
+ ?manual>
+ state free
+ ==>
+ =goal>
+ isa playgame
+ activity presskey
+ """,
+ )
+
+ playing_memory.productionstring(
+ name="presskey",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity presskey
+ ==>
+ +manual>
+ isa _manual
+ cmd press_key
+ key 1
+ =goal>
+ isa playgame
+ activity None
+ """,
+ )
+
+ simulation_game = playing_memory.simulation()
+ simulation_game.run()
+
+
+def memory_vision():
+ environment = actr.Environment()
+ playing_memory = actr.ACTRModel(environment=environment)
+
+ memory = [{}, {"A": {"text": "A", "position": (100, 100)}}]
+
+ goal = playing_memory.set_goal("goal")
+ actr.chunktype("playgame", "game, activity, key, object")
+ initial_chunk = actr.makechunk(typename="playgame", game="memory", key="1")
+ goal.add(initial_chunk)
+
+ playing_memory.productionstring(
+ name="startplaying",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity None
+ ==>
+ =goal>
+ isa playgame
+ activity presskey""",
+ )
+
+ playing_memory.productionstring(
+ name="presskey",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity presskey
+ key =k
+ ==>
+ +manual>
+ isa _manual
+ cmd press_key
+ key =k
+ =goal>
+ isa playgame
+ activity attend""",
+ )
+
+ playing_memory.productionstring(
+ name="attendobject",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity attend
+ =visual_location>
+ isa _visuallocation
+ ?manual>
+ state free
+ ==>
+ =goal>
+ isa playgame
+ activity storeobject
+ +visual>
+ isa _visual
+ cmd move_attention
+ screen_pos =visual_location""",
+ )
+
+ playing_memory.productionstring(
+ name="storeobject",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity storeobject
+ =visual>
+ isa _visual
+ value =v
+ ==>
+ =goal>
+ isa playgame
+ activity None
+ object =v""",
+ )
+
+ simulation = playing_memory.simulation(
+ gui=False,
+ environment_process=environment.environment_process,
+ stimuli=memory,
+ triggers="1",
+ )
+ simulation.run()
+
+ print(goal)
+
+
+def memory_memory():
+ environment = actr.Environment()
+ playing_memory = actr.ACTRModel(environment=environment)
+
+ memory = [
+ {},
+ {"A": {"text": "A", "position": (100, 100)}},
+ {"A": {"text": "A", "position": (100, 100)}},
+ ]
+
+ goal = playing_memory.set_goal("goal")
+ actr.chunktype("playgame", "game, activity, key, object")
+ initial_chunk = actr.makechunk(typename="playgame", game="memory", key="1")
+ goal.add(initial_chunk)
+
+ playing_memory.productionstring(
+ name="startplaying",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity None
+ object None
+ ==>
+ =goal>
+ isa playgame
+ activity presskey""",
+ )
+
+ playing_memory.productionstring(
+ name="continueplaying",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity None
+ object ~None
+ ==>
+ =goal>
+ isa playgame
+ game memory
+ activity recall""",
+ )
+
+ playing_memory.productionstring(
+ name="recallvalue",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity recall
+ object =val
+ ==>
+ =goal>
+ isa playgame
+ game memory
+ activity checkrecalled
+ +retrieval>
+ isa playgame
+ object =val""",
+ )
+
+ playing_memory.productionstring(
+ name="recallsuccessful",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity checkrecalled
+ object =val
+ ?retrieval>
+ buffer full
+ =retrieval>
+ isa playgame
+ key =k
+ ==>
+ =goal>
+ isa playgame
+ key =k
+ activity done""",
+ )
+
+ playing_memory.productionstring(
+ name="recallfailed",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity checkrecalled
+ key 1
+ object =val
+ ?retrieval>
+ state error
+ ==>
+ ~goal>
+ +goal>
+ isa playgame
+ game memory
+ activity presskey
+ key 2""",
+ )
+
+ playing_memory.productionstring(
+ name="presskey",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity presskey
+ key =k
+ ==>
+ +manual>
+ isa _manual
+ cmd press_key
+ key =k
+ =goal>
+ isa playgame
+ activity attend""",
+ )
+
+ playing_memory.productionstring(
+ name="attendobject",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity attend
+ =visual_location>
+ isa _visuallocation
+ ?manual>
+ state free
+ ==>
+ =goal>
+ isa playgame
+ activity storeobject
+ +visual>
+ isa _visual
+ cmd move_attention
+ screen_pos =visual_location""",
+ )
+
+ playing_memory.productionstring(
+ name="storeobject",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity storeobject
+ =visual>
+ isa _visual
+ value =v
+ ==>
+ =goal>
+ isa playgame
+ activity None
+ object =v""",
+ )
+
+ simulation = playing_memory.simulation(
+ gui=False,
+ environment_process=environment.environment_process,
+ stimuli=memory,
+ triggers="1",
+ )
+ simulation.run(max_time=2)
+
+ print(goal)
+ print(playing_memory.decmem)
+
+
+def memory_memory_loop():
+ environment = actr.Environment()
+ playing_memory = actr.ACTRModel(environment=environment)
+
+ goal = playing_memory.set_goal("goal")
+ actr.chunktype("playgame", "game, activity, key, object")
+ initial_chunk = actr.makechunk(typename="playgame", game="memory", key="1")
+
+ memory = [{}] + [{i: {"text": i, "position": (100, 100)}} for i in "BCDEFGHDIJ"]
+ goal.add(initial_chunk)
+
+ playing_memory.productionstring(
+ name="startplaying",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity None
+ object None
+ ==>
+ =goal>
+ isa playgame
+ activity presskey""",
+ )
+
+ playing_memory.productionstring(
+ name="continueplaying",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity None
+ object ~None
+ ==>
+ =goal>
+ isa playgame
+ game memory
+ activity recall""",
+ )
+
+ playing_memory.productionstring(
+ name="recallvalue",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity recall
+ object =val
+ ==>
+ =goal>
+ isa playgame
+ game memory
+ activity checkrecalled
+ +retrieval>
+ isa playgame
+ object =val""",
+ )
+
+ playing_memory.productionstring(
+ name="recallsuccessful",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity checkrecalled
+ object =val
+ ?retrieval>
+ buffer full
+ =retrieval>
+ isa playgame
+ key =k
+ ==>
+ =goal>
+ isa playgame
+ key =k
+ activity done""",
+ )
+
+ for i in range(1, 9):
+ playing_memory.productionstring(
+ name="recallfailed" + str(i),
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity checkrecalled
+ key """
+ + str(i)
+ + """
+ object =val
+ ?retrieval>
+ state error
+ ==>
+ ~goal>
+ +goal>
+ isa playgame
+ game memory
+ activity presskey
+ key """
+ + str((i + 1) % 10),
+ )
+
+ playing_memory.productionstring(
+ name="recallfailed9",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity checkrecalled
+ key 0
+ object =val
+ ?retrieval>
+ state error
+ ==>
+ ~goal>""",
+ )
+
+ playing_memory.productionstring(
+ name="presskey",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity presskey
+ key =k
+ ==>
+ +manual>
+ isa _manual
+ cmd press_key
+ key =k
+ =goal>
+ isa playgame
+ activity attend""",
+ )
+
+ playing_memory.productionstring(
+ name="attendobject",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity attend
+ =visual_location>
+ isa _visuallocation
+ ?manual>
+ state free
+ ==>
+ =goal>
+ isa playgame
+ activity storeobject
+ +visual>
+ isa _visual
+ cmd move_attention
+ screen_pos =visual_location""",
+ )
+
+ playing_memory.productionstring(
+ name="storeobject",
+ string="""
+ =goal>
+ isa playgame
+ game memory
+ activity storeobject
+ =visual>
+ isa _visual
+ value =v
+ ==>
+ =goal>
+ isa playgame
+ activity None
+ object =v""",
+ )
+ playing_memory.model_parameters["subsymbolic"] = True
+
+ goal.add(initial_chunk)
+ # playing_memory.retrieval.pop()
+ # for i in playing_memory.decmem.copy():
+ # playing_memory.decmem.pop(i)
+ simulation = playing_memory.simulation(
+ gui=False,
+ environment_process=environment.environment_process,
+ stimuli=memory,
+ triggers=[str(i % 10) for i in range(1, 11)] + ["0"],
+ )
+
+ while True:
+ simulation.step()
+ if simulation.current_event.action == "RULE FIRED: recallsuccessful":
+ break
+ if simulation.show_time() > 10:
+ print("Nothing found, breaking")
+ break
+
+ print(goal)
+ print(simulation.show_time())
+ print(playing_memory.decmem)
+
+
+memory_memory_loop()