From bf2f74d43a02ef01c794292bf10fa5e5652447f4 Mon Sep 17 00:00:00 2001 From: Niclas Dobbertin Date: Thu, 5 Sep 2024 20:23:08 +0200 Subject: test prod compile --- modeling/test_compilation.py | 51 ------------------ modeling/test_compile.py | 122 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 51 deletions(-) delete mode 100644 modeling/test_compilation.py create mode 100644 modeling/test_compile.py (limited to 'modeling') diff --git a/modeling/test_compilation.py b/modeling/test_compilation.py deleted file mode 100644 index 1312494..0000000 --- a/modeling/test_compilation.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python3 - -""" -Testing a simple case of production compilation. The compilation also allows for utility learning, shown in the model below, as well. -""" - -import warnings - -import pyactr as actr - -class Compilation1: - """ - Model testing compilation -- basic cases. - """ - - def __init__(self, **kwargs): - actr.chunktype("state", "starting ending") - self.m = actr.ACTRModel(**kwargs) - - self.m.goal.add(actr.makechunk(nameofchunk="start", typename="state", starting=1)) - - self.m.productionstring(name="one", string=""" - =g> - isa state - starting =x - ending ~=x - ==> - =g> - isa state - ending =x""", utility=2) - - self.m.productionstring(name="two", string=""" - =g> - isa state - starting =x - ending =x - ==> - =g> - isa state - starting =x - ending 4""") - -if __name__ == "__main__": - warnings.simplefilter("ignore") - mm = Compilation1(production_compilation=True, utility_learning=True) - - model = mm.m - - sim = model.simulation(realtime=True) - sim.run(0.5) - print(model.productions["one and two"]) diff --git a/modeling/test_compile.py b/modeling/test_compile.py new file mode 100644 index 0000000..b1e825f --- /dev/null +++ b/modeling/test_compile.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python3 + +import pyactr as actr +import prod_numbers + +Model = actr.ACTRModel() +DM = Model.decmem +goal = Model.goal +imaginal = Model.set_goal(name="imaginal", delay=0.2) + +_ = prod_numbers.number(Model) + +def get_digit(number, n): + return number // 10**n % 10 + +actr.chunktype("number", ("number", "next", "ones", "tens", "hundreds")) +actr.chunktype( + "math_goal", + ( + "task", + "result1", + "result2", + "op", + "nextop", + "nextnextop", + "arg1", + "arg1_idx", + "arg2", + "arg2_idx", + "result", + "expand_slot", + "hundreds1", + "tens1", + "ones1", + "hundreds2", + "tens2", + "ones2", + ), +) +actr.chunktype( + "math_op", + ( + "op", + "arg1", + "arg2", + "result", + ), +) + +# Add numbers 0-999 to decmem +for i in range(0, 1000): + DM.add( + actr.makechunk( + f"number{str(i)}", + "number", + number=i, + next=i + 1, + ones=get_digit(i, 0), + tens=get_digit(i, 1), + hundreds=get_digit(i, 2), + ) + ) + + +Model.productionstring( + name="continue_with_next_op", + string=""" + =g> + isa math_goal + op done + nextop ~None + nextop =nextop + nextnextop =nextnextop + ==> + =g> + isa math_goal + op =nextop + nextop =nextnextop + nextnextop None + """, +) + +Model.productionstring( + name="reset", + string=""" + =g> + isa math_goal + op reset + ==> + =g> + isa math_goal + op expand + nextop reset + """ +) + +goal.add( + actr.makechunk( + "", + "math_goal", + op="expand", + nextop="reset", + expand_slot=None, + ones1=1, + tens1=2, + hundreds1=3, + ones2=4, + tens2=5, + hundreds2=6, + ) +) +Model.model_parameters["activation_trace"] = True +Model.model_parameters["instantaneous_noise"] = .2 +Model.model_parameters["utility_alpha"] = 0.5 +Model.model_parameters["utility_noise"] = 0.5 +Model.model_parameters["production_compilation"] = True +Model.model_parameters["utility_learning"] = True + +sim = Model.simulation( + gui=False, +) +sim.run(max_time=2) -- cgit v1.2.3