summaryrefslogtreecommitdiff
path: root/modeling
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
parentd5e763d6e552b7fe60a9e82d5759e671f8c188f3 (diff)
tmp modeling
Diffstat (limited to 'modeling')
-rw-r--r--modeling/addition.py34
-rw-r--r--modeling/pyactr_tut.py512
2 files changed, 546 insertions, 0 deletions
diff --git a/modeling/addition.py b/modeling/addition.py
new file mode 100644
index 0000000..a32adba
--- /dev/null
+++ b/modeling/addition.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+import pyactr as actr
+
+
+addition = actr.ACTRModel()
+actr.chunktype("countOrder", ("first", "second"))
+actr.chunktype("add", ("arg1", "arg2", "sum", "count"))
+
+dm = addition.decmem
+
+for i in range(0, 11):
+ dm.add(actr.makechunk("chunk" + str(i), "countOrder", first=i, second=i + 1))
+
+addition.goal.add(actr.makechunk("", "add", arg1=5, arg2=2))
+
+addition.productionstring(
+ name="init_addition",
+ string="""
+ =g>
+ isa add
+ arg1 =num1
+ arg2 =num2
+ sum None
+ ==>
+ =g>
+ isa add
+ sum =num1
+ count 0
+ +retrieval>
+ isa countOrder
+ first =num1
+""",
+)
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()