diff options
Diffstat (limited to 'modeling')
-rw-r--r-- | modeling/model_env.py | 22 | ||||
-rw-r--r-- | modeling/prod_motor.py | 1 | ||||
-rw-r--r-- | modeling/prod_multi.py | 25 | ||||
-rw-r--r-- | modeling/prod_numbers.py | 81 | ||||
-rw-r--r-- | modeling/prod_subtraction.py | 24 | ||||
-rw-r--r-- | modeling/productions_math.py | 59 |
6 files changed, 138 insertions, 74 deletions
diff --git a/modeling/model_env.py b/modeling/model_env.py index 433b2da..45b3207 100644 --- a/modeling/model_env.py +++ b/modeling/model_env.py @@ -13,6 +13,9 @@ class Stimuli: training_order_list = [] test_order_list = [] + current_proc_id = 1 + current_phase = "train" + def __init__(self, condition, training_N=75, test_N=50): self.condition = condition self.training_N = training_N @@ -44,15 +47,21 @@ class Stimuli: ) if self.condition == "random": - self.training_order_list = self.order_list[:self.training_N] - self.test_order_list = self.order_list[self.training_N:] + self.training_order_list = self.order_list[: self.training_N] + self.test_order_list = self.order_list[self.training_N :] def next_stimulus(self): self.current_stimulus_id += 1 - if self.current_stimulus_id < self.training_N: - return self.training_stimuli[self.current_stimulus_id] - else: - return self.test_stimuli[self.current_stimulus_id - self.training_N] + if self.condition != "blocked": + if self.current_stimulus_id < self.training_N: + return self.training_stimuli[self.current_stimulus_id] + else: + return self.test_stimuli[self.current_stimulus_id - self.training_N] + elif self.condition == "blocked": + if self.current_stimulus_id > 6 * self.training_N: + return self.test_stimuli[self.current_stimulus_id % 6 - self.training_N] + else: + return self.training_stimuli[self.current_stimulus_id % 6] def update_current_stimulus(self, key, value): if self.current_stimulus_id < self.training_N: @@ -64,7 +73,6 @@ class Stimuli: ] = value return self.test_stimuli[self.current_stimulus_id - self.training_N] - def generate_environments(self, water_samples, order): envs = [] diff --git a/modeling/prod_motor.py b/modeling/prod_motor.py index a13e64a..1c6237a 100644 --- a/modeling/prod_motor.py +++ b/modeling/prod_motor.py @@ -17,6 +17,7 @@ def procedures(Model): op expand nextop press_tens arg2 =result + ones1 None ones2 None tens2 None """ diff --git a/modeling/prod_multi.py b/modeling/prod_multi.py index e93eda0..69e29b2 100644 --- a/modeling/prod_multi.py +++ b/modeling/prod_multi.py @@ -36,6 +36,7 @@ def multiplication(Model): arg1 =arg1 arg2 =arg2 result =arg2 + ~retrieval> """ ) mul_arg2_1 = Model.productionstring( @@ -58,6 +59,7 @@ def multiplication(Model): arg1 =arg1 arg2 =arg2 result =arg1 + ~retrieval> """ ) mul_arg1_0 = Model.productionstring( @@ -80,6 +82,7 @@ def multiplication(Model): arg1 =arg1 arg2 =arg2 result 0 + ~retrieval> """ ) mul_arg2_0 = Model.productionstring( @@ -102,6 +105,7 @@ def multiplication(Model): arg1 =arg1 arg2 =arg2 result 0 + ~retrieval> """ ) @@ -123,6 +127,7 @@ def multiplication(Model): ==> =g> isa math_goal + op mul_try_retrieve +retrieval> isa math_op op mul @@ -132,12 +137,27 @@ def multiplication(Model): ) prods.append(mul_start) + # mul_start_failure = Model.productionstring( + # name="mul_start_failure", + # string=""" + # =g> + # isa math_goal + # op mul_try_retrieve + # arg1 =arg1 + # arg2 =arg2 + # ?retrieval> + # state error + # ==> + # isa math_goal + # op mul_step + # """ + mul_start_success = Model.productionstring( name="mul_start_success", string=""" =g> isa math_goal - op mul + op mul_try_retrieve arg1 =arg1 arg2 =arg2 =retrieval> @@ -166,7 +186,7 @@ def multiplication(Model): string=""" =g> isa math_goal - op mul + op mul_try_retrieve arg1 ~0 arg1 ~1 arg2 ~0 @@ -182,6 +202,7 @@ def multiplication(Model): ==> =g> isa math_goal + op mul mul_counter 1 result =arg +retrieval> diff --git a/modeling/prod_numbers.py b/modeling/prod_numbers.py index 773768d..43cd769 100644 --- a/modeling/prod_numbers.py +++ b/modeling/prod_numbers.py @@ -44,7 +44,7 @@ def number(Model): ==> =g> isa math_goal - expand_slot None + expand_slot arg2 ones1 =one tens1 =ten hundreds1 =hun @@ -53,25 +53,25 @@ def number(Model): ) prods.append(number_expand_arg1_done) - number_expand_arg1_fail = Model.productionstring( - name="number_expand_arg1_fail", - # reward=-100, - string=""" - =g> - isa math_goal - op expand - ones1 None - expand_slot arg1 - ?retrieval> - state error - ==> - =g> - isa math_goal - expand_slot None - ~retrieval> - """ - ) - prods.append(number_expand_arg1_fail) + # number_expand_arg1_fail = Model.productionstring( + # name="number_expand_arg1_fail", + # # reward=-100, + # string=""" + # =g> + # isa math_goal + # op expand + # ones1 None + # expand_slot arg1 + # ?retrieval> + # state error + # ==> + # =g> + # isa math_goal + # expand_slot None + # ~retrieval> + # """ + # ) + # prods.append(number_expand_arg1_fail) number_expand_arg2 = Model.productionstring( @@ -82,7 +82,7 @@ def number(Model): op expand arg2 =num ones2 None - expand_slot None + expand_slot arg2 ?retrieval> state free buffer empty @@ -97,25 +97,25 @@ def number(Model): ) prods.append(number_expand_arg2) - number_expand_arg2_fail = Model.productionstring( - name="number_expand_arg2_fail", - # reward=-100, - string=""" - =g> - isa math_goal - op expand - ones2 None - expand_slot arg2 - ?retrieval> - state error - ==> - =g> - isa math_goal - expand_slot None - ~retrieval> - """ - ) - prods.append(number_expand_arg2_fail) + # number_expand_arg2_fail = Model.productionstring( + # name="number_expand_arg2_fail", + # # reward=-100, + # string=""" + # =g> + # isa math_goal + # op expand + # ones2 None + # expand_slot arg2 + # ?retrieval> + # state error + # ==> + # =g> + # isa math_goal + # expand_slot None + # ~retrieval> + # """ + # ) + # prods.append(number_expand_arg2_fail) number_expand_arg2_done = Model.productionstring( name="number_expand_arg2_done", @@ -135,6 +135,7 @@ def number(Model): ==> =g> isa math_goal + op done expand_slot None ones2 =one tens2 =ten diff --git a/modeling/prod_subtraction.py b/modeling/prod_subtraction.py index b952dd9..dd60496 100644 --- a/modeling/prod_subtraction.py +++ b/modeling/prod_subtraction.py @@ -395,6 +395,25 @@ def subtraction(Model): """, ) + sub_hundreds_with_carry_0 = Model.productionstring( + name="sub_hundreds_with_carry_0", + string=""" + =g> + isa math_goal + op sub_hundreds + hundreds1 =num1 + hundreds2 0 + hundreds2 =num2 + tens_carry 1 + ==> + =g> + isa math_goal + op sub_done + hundreds_ans 0 + ~retrieval> + """, + ) + sub_hundreds_with_carry = Model.productionstring( name="sub_hundreds_with_carry", string=""" @@ -402,6 +421,7 @@ def subtraction(Model): isa math_goal op sub_hundreds hundreds1 =num1 + hundreds2 ~0 hundreds2 =num2 tens_carry 1 ?retrieval> @@ -563,7 +583,7 @@ def subtraction(Model): ==> =g> isa math_goal - op sub_hundreds + op sub_hundreds_done +retrieval> isa math_op op add @@ -577,7 +597,7 @@ def subtraction(Model): string=""" =g> isa math_goal - op sub_hundreds + op sub_hundreds_done hundreds1 =num1 hundreds2 =num2 =retrieval> diff --git a/modeling/productions_math.py b/modeling/productions_math.py index 542f2e3..b6302bd 100644 --- a/modeling/productions_math.py +++ b/modeling/productions_math.py @@ -53,12 +53,12 @@ def start(): Model, DM, goal, imaginal, env = init() # Model.model_parameters["subsymbolic"] = True # Model.model_parameters["partial_matching"] = True - 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 + # 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 # add_goal(goal, op, arg1, arg2) add_proc(goal, "next_proc") @@ -107,7 +107,11 @@ def start(): userinput[phase][stimuli.current_stimulus_id][str(i)].append( sim.current_event.action.split(":")[1].strip() ) - if "RULE FIRED:" in sim.current_event.action and "number_expand_done and continue_with_next_op" in sim.current_event.action: + if ( + "RULE FIRED:" in sim.current_event.action + and "number_expand_done and continue_with_next_op" + in sim.current_event.action + ): print("FIRED COMPILED RULE!!!!") # print(Model.productions[sim.current_event.action[12:]]) # break @@ -116,26 +120,34 @@ def start(): if sim.current_event.action == "KEY PRESSED: SPACE": sim._Simulation__env.stimulus = stimuli.update_current_stimulus( f"Answer{i}", - int("".join(userinput[phase][stimuli.current_stimulus_id][str(i)][:-1])), + int( + "".join(userinput[phase][stimuli.current_stimulus_id][str(i)][:-1]) + ), ) i += 1 pprint(userinput) pprint("NEW PROC") - if i <= 6: - goal.add( - actr.makechunk("", "math_goal", proc="next_proc", ones_carry="") - ) - elif i >= 7 and j < training_N+test_N: - print("Stimulus Done, next stimulus") + if condition != "blocked": + if i <= 6: + goal.add( + actr.makechunk("", "math_goal", proc="next_proc", ones_carry="") + ) + elif i >= 7 and j < training_N + test_N: + print("Stimulus Done, next stimulus") + sim._Simulation__env.stimulus = stimuli.next_stimulus() + goal.add( + actr.makechunk("", "math_goal", proc="next_proc", ones_carry="") + ) + i = 1 + j += 1 + elif i >= 7 and j >= training_N + test_N: + print("DONE") + break + elif condition == "blocked": + if i >= 6 * (training_N + test_N): + print("DONE") + break sim._Simulation__env.stimulus = stimuli.next_stimulus() - goal.add( - actr.makechunk("", "math_goal", proc="next_proc", ones_carry="") - ) - i = 1 - j += 1 - elif i >= 7 and j >= training_N+test_N: - print("DONE") - break # sim.run(max_time=25) print("training order: ", stimuli.training_order_list) @@ -160,9 +172,10 @@ def start(): # print("\n") # print("#######used prods########") # print(sim.ordered_rulenames) - + # pprint(sim._Simulation__pr.rules) # pprint(sim._Simulation__pr.ordered_rulenames) + if __name__ == "__main__": start() |