diff options
Diffstat (limited to 'modeling')
-rw-r--r-- | modeling/frensch_procedures.py | 155 | ||||
-rw-r--r-- | modeling/model_env.py | 117 | ||||
-rw-r--r-- | modeling/model_init.py | 17 | ||||
-rw-r--r-- | modeling/productions_math.py | 165 |
4 files changed, 314 insertions, 140 deletions
diff --git a/modeling/frensch_procedures.py b/modeling/frensch_procedures.py new file mode 100644 index 0000000..9dcbf36 --- /dev/null +++ b/modeling/frensch_procedures.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python3 + +from __future__ import annotations +import random + + +class WaterSample: + def __init__( + self, + solid: int, + algae: int, + lime: tuple[int, int, int, int], + toxin: tuple[int, int, int, int], + ): + self.solid = solid + self.algae = algae + self.lime = lime + self.toxin = toxin + + def procedure_dict(self): + procedures = { + "1": (self.index1(), self.index1_str()), + "2": (self.index2(), self.index2_str()), + "3": (self.index3(), self.index3_str()), + "4": (self.index4(), self.index4_str()), + "5": (self.index5(), self.index5_str()), + "6": (self.index6(), self.index6_str()), + "overall": (self.overall(), self.overall_str()), + } + + return procedures + + def water_sample_dict(self): + sample = { + "1": (self.index1(), self.index1_str()), + "2": (self.index2(), self.index2_str()), + "3": (self.index3(), self.index3_str()), + "4": (self.index4(), self.index4_str()), + "5": (self.index5(), self.index5_str()), + "6": (self.index6(), self.index6_str()), + "overall": (self.overall(), self.overall_str()), + "solid": self.solid, + "algae": self.algae, + "lime": self.lime, + "toxin": self.toxin, + } + return sample + + def select_procedures(self): + procedures = [ + (self.index1, self.index1_str), + (self.index2, self.index2_str), + (self.index3, self.index3_str), + (self.index4, self.index4_str), + (self.index5, self.index5_str), + (self.index6, self.index6_str), + ] + random.shuffle(procedures) + training_procedures = procedures[:-1] + training_procedures.append((self.overall, self.overall_str)) + + return training_procedures, procedures[-1] + + def index1(self): + return (self.lime[3] - self.lime[1]) * self.solid + + def index1_str(self): + return "(Sandstein_4 - Sandstein_2) * Mineralien" + + def index2(self): + return (2 * self.algae) + min(self.lime) + + def index2_str(self): + return "(2 * Algen) + Sandstein_min" + + def index3(self): + return max(self.toxin) + min(self.toxin) + + def index3_str(self): + return "Gifte_max + Gifte_min" + + def index4(self): + return (self.solid * 2) - self.toxin[3] + + def index4_str(self): + return "(Mineralien * 2) - Gifte_4" + + def index5(self): + return max(self.lime[2], (self.toxin[2] - self.toxin[1])) + + def index5_str(self): + return "Das Höhere von (Gifte_3 - Gifte_2), (Sandstein_3)" + + def index6(self): + return min(self.algae, (self.lime[0] + self.toxin[0])) + + def index6_str(self): + return "Das Kleinere von (Sandstein_1 + Gifte_1), (Algen)" + + def overall(self): + return 100 - max( + self.index1(), self.index2(), self.index3(), self.index4(), self.index5() + ) + + def overall_str(self): + return "100 - dem Höchstem aller Ergebnisse" + + def print_all(self): + print(f"Solid: {self.solid}") + print(f"Algae: {self.algae}") + print(f"Lime: {self.lime}") + print(f"Toxin: {self.toxin}") + print(f"Index 1: {self.index1_str()} = {self.index1()}") + print(f"Index 2: {self.index2_str()} = {self.index2()}") + print(f"Index 3: {self.index3_str()} = {self.index3()}") + print(f"Index 4: {self.index4_str()} = {self.index4()}") + print(f"Index 5: {self.index5_str()} = {self.index5()}") + print(f"Index 6: {self.index6_str()} = {self.index6()}") + print(f"Overall Quality: {self.overall_str()} = {self.overall()}") + + +# No step should produce a negative number, greater/lesser of comparisons should not +# use equal numbers +def constrained_WaterSample(): + water_sample = random_WaterSample() + resample = True + while resample: + water_sample = random_WaterSample() + resample = False + # check for negative results + for proc in water_sample.procedure_dict().keys(): + if water_sample.procedure_dict()[proc][0] < 0: + resample = True + # check for negative intermediate result + if (water_sample.lime[3] - water_sample.lime[1]) < 0: + resample = True + if (water_sample.toxin[2] - water_sample.toxin[1]) < 0: + resample = True + # check for greater/lesser equality + # procedure 5 + if (water_sample.toxin[2] - water_sample.toxin[1]) == water_sample.lime[2]: + resample = True + # procedure 6 + if (water_sample.lime[0] + water_sample.toxin[0]) == water_sample.algae: + resample = True + return water_sample + + +def random_WaterSample(): + solid = random.randint(1, 9) + algae = random.randint(1, 9) + lime = tuple(random.randint(1, 9) for _ in range(4)) + toxin = tuple(random.randint(1, 9) for _ in range(4)) + + return WaterSample(solid, algae, lime, toxin) diff --git a/modeling/model_env.py b/modeling/model_env.py index 7dcad3e..1ad9495 100644 --- a/modeling/model_env.py +++ b/modeling/model_env.py @@ -1,54 +1,79 @@ #!/usr/bin/env python3 +import random -def generate_environments(): - envs = [] +from modeling import frensch_procedures + + +class Stimuli: + current_stimulus_id = 0 + + def __init__(self, condition, training_N=75, test_N=50): + self.condition = condition + self.training_N = training_N + self.test_N = test_N + + def generate_stimuli(self): + self.training_stimuli = frensch_procedures.constrained_WaterSample() + self.test_stimuli = frensch_procedures.constrained_WaterSample() + + 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] + + + def update_current_stimulus(self, ): + pass + + def generate_environments(self): + envs = [] - for i in range(3): screen = {} - screen["id"] = {"text": i, "position":(0,0)} - generate_variables(screen) - generate_procedures(screen) + self.generate_variables(screen) + self.generate_procedures(screen) envs.append(screen) - return envs - - -def generate_procedures(screen): - procs = ["procs1", "procs2", "procs3", "procs4", "procs5", "procs6"] - screen["Procedure1"] = {"text": procs[0], "position": (0, 100)} - screen["Procedure2"] = {"text": procs[1], "position": (0, 200)} - screen["Procedure3"] = {"text": procs[2], "position": (0, 300)} - screen["Procedure4"] = {"text": procs[3], "position": (0, 400)} - screen["Procedure5"] = {"text": procs[4], "position": (0, 500)} - - screen["ProcedureOverall"] = {"text": "proc_overall", "position": (0, 600)} - - screen["Answers"] = {"text": "Answers", "position": (100, 100)} - screen["Answer1"] = {"text": 1, "position": (100, 200)} - screen["Answer2"] = {"text": 2, "position": (100, 300)} - screen["Answer3"] = {"text": 3, "position": (100, 400)} - screen["Answer4"] = {"text": 4, "position": (100, 500)} - screen["Answer5"] = {"text": 5, "position": (100, 600)} - - screen["AnswerOverall"] = {"text": "proc_overall", "position": (100, 700)} - -def generate_variables(screen): - # Variables - screen["Algen"] = {"text": "Algen", "position": (400, 100)} - screen["AlgenVar"] = {"text": "3", "position": (400, 200)} - screen["Mineralien"] = {"text": "Mineralien", "position": (500, 100)} - screen["MineralienVar"] = {"text": "9", "position": (500, 200)} - - screen["Gifte"] = {"text": "Gifte", "position": (600, 100)} - screen["GifteVar1"] = {"text": "3", "position": (600, 200)} - screen["GifteVar2"] = {"text": "1", "position": (600, 300)} - screen["GifteVar3"] = {"text": "8", "position": (600, 400)} - screen["GifteVar4"] = {"text": "6", "position": (600, 500)} - - screen["Sandstein"] = {"text": "Sandstein", "position": (700, 100)} - screen["SandsteinVar1"] = {"text": "3", "position": (700, 200)} - screen["SandsteinVar2"] = {"text": "4", "position": (700, 300)} - screen["SandsteinVar3"] = {"text": "5", "position": (700, 400)} - screen["SandsteinVar4"] = {"text": "6", "position": (700, 500)} + return envs + + def generate_procedures(self, screen): + procs = ["procs1", "procs2", "procs3", "procs4", "procs5", "procs6"] + screen["Procedure1"] = {"text": procs[0], "position": (0, 100)} + screen["Procedure2"] = {"text": procs[1], "position": (0, 200)} + screen["Procedure3"] = {"text": procs[2], "position": (0, 300)} + screen["Procedure4"] = {"text": procs[3], "position": (0, 400)} + screen["Procedure5"] = {"text": procs[4], "position": (0, 500)} + + screen["ProcedureOverall"] = {"text": "proc_overall", "position": (0, 600)} + + screen["Answers"] = {"text": "Answers", "position": (100, 100)} + screen["Answer1"] = {"text": 1, "position": (100, 200)} + screen["Answer2"] = {"text": 2, "position": (100, 300)} + screen["Answer3"] = {"text": 3, "position": (100, 400)} + screen["Answer4"] = {"text": 4, "position": (100, 500)} + screen["Answer5"] = {"text": 5, "position": (100, 600)} + + screen["AnswerOverall"] = {"text": "proc_overall", "position": (100, 700)} + + def generate_variables(self, screen): + # Variables + screen["Algen"] = {"text": "Algen", "position": (400, 100)} + screen["AlgenVar"] = {"text": "3", "position": (400, 200)} + screen["Mineralien"] = {"text": "Mineralien", "position": (500, 100)} + screen["MineralienVar"] = {"text": "9", "position": (500, 200)} + + screen["Gifte"] = {"text": "Gifte", "position": (600, 100)} + screen["GifteVar1"] = {"text": "3", "position": (600, 200)} + screen["GifteVar2"] = {"text": "1", "position": (600, 300)} + screen["GifteVar3"] = {"text": "8", "position": (600, 400)} + screen["GifteVar4"] = {"text": "6", "position": (600, 500)} + + screen["Sandstein"] = {"text": "Sandstein", "position": (700, 100)} + screen["SandsteinVar1"] = {"text": "3", "position": (700, 200)} + screen["SandsteinVar2"] = {"text": "4", "position": (700, 300)} + screen["SandsteinVar3"] = {"text": "5", "position": (700, 400)} + screen["SandsteinVar4"] = {"text": "6", "position": (700, 500)} + diff --git a/modeling/model_init.py b/modeling/model_init.py index a6ca3ac..7fb1c84 100644 --- a/modeling/model_init.py +++ b/modeling/model_init.py @@ -241,4 +241,21 @@ def init(): f"plus{i}{j}", "math_op", op="add", arg1=i, arg2=j, result=i + j ) ) + + Model.productionstring( + name="continue_with_next_op", + string=""" + =g> + isa math_goal + op done + nextop ~None + nextop =nextop + ==> + =g> + isa math_goal + op =nextop + nextop None + """, + ) + return Model, DM, goal, imaginal, env diff --git a/modeling/productions_math.py b/modeling/productions_math.py index 7ac1257..f824466 100644 --- a/modeling/productions_math.py +++ b/modeling/productions_math.py @@ -20,23 +20,6 @@ def add_goal(goal, op, arg1, arg2): goal.add(actr.makechunk("", "math_goal", op=op, task=op, arg1=arg1, arg2=arg2)) -def general_prod(Model): - - Model.productionstring( - name="continue_with_next_op", - string=""" - =g> - isa math_goal - op done - nextop ~None - nextop =nextop - ==> - =g> - isa math_goal - op =nextop - nextop None - """, - ) def wait_input(): @@ -48,88 +31,82 @@ def wait_input(): def add_proc(goal, proc): # input() - goal.add(actr.makechunk("", "math_goal", proc=proc, ones_carry="hello")) + goal.add(actr.makechunk("", "math_goal", proc=proc, ones_carry="")) def start(): - loop = True - while loop: - loop = False - # op, arg1, arg2 = wait_input() - Model, DM, goal, imaginal, env = init() - # add_goal(goal, op, arg1, arg2) - add_proc(goal, "proc1") - envs = model_env.generate_environments() - - general_prod(Model) - prod_procedure.procedures(Model) - number_prods = prod_numbers.number(Model) - add_prods = prod_addition.addition(Model) - sub_prods = prod_subtraction.subtraction(Model) - greater_prods = prod_comp.greater_than(Model) - less_prods = prod_comp.lesser_than(Model) - multi_prods = prod_multi.multiplication(Model) - motor_prods = prod_motor.procedures(Model) - visual_prods = prod_vis.procedures(Model) - - # for prod in multi_prods: - # print(prod) - # print("\n") - - print("goal: ", goal) - # print("imaginal: ", imaginal) - sim = Model.simulation( - gui=False, - environment_process=env.environment_process, - stimuli=envs, - # triggers="space", - triggers="b", - ) - i = 1 - userinput = "" - while True: - sim.step() - if sim.current_event.time >= 50: - print(sim.current_event) - break - if "KEY PRESSED" in sim.current_event.action: - userinput = userinput + sim.current_event.action.split(":")[1] - # if sim.current_event.action == "NO RULE FOUND": - # print(goal) - if sim.current_event.action == "KEY PRESSED: SPACE": - sim._Simulation__env.stimulus["Answer5"]["text"] = "99" - i += 1 - print(userinput) - print("NEW PROC") - if i <= 6: - goal.add( - actr.makechunk( - "", "math_goal", proc=f"proc{i}", ones_carry="hello" - ) + condition = "fixed" + + # op, arg1, arg2 = wait_input() + Model, DM, goal, imaginal, env = init() + # add_goal(goal, op, arg1, arg2) + add_proc(goal, "proc1") + envs = model_env.generate_environments() + + prod_procedure.procedures(Model) + number_prods = prod_numbers.number(Model) + add_prods = prod_addition.addition(Model) + sub_prods = prod_subtraction.subtraction(Model) + greater_prods = prod_comp.greater_than(Model) + less_prods = prod_comp.lesser_than(Model) + multi_prods = prod_multi.multiplication(Model) + motor_prods = prod_motor.procedures(Model) + visual_prods = prod_vis.procedures(Model) + + print("goal: ", goal) + # print("imaginal: ", imaginal) + sim = Model.simulation( + gui=False, + environment_process=env.environment_process, + stimuli=envs, + # triggers="space", + triggers="b", + ) + i = 1 + userinput = "" + while True: + sim.step() + if sim.current_event.time >= 50: + print(sim.current_event) + break + if "KEY PRESSED" in sim.current_event.action: + userinput = userinput + sim.current_event.action.split(":")[1] + # if sim.current_event.action == "NO RULE FOUND": + # print(goal) + if sim.current_event.action == "KEY PRESSED: SPACE": + sim._Simulation__env.stimulus["Answer5"]["text"] = "99" + i += 1 + print(userinput) + print("NEW PROC") + if i <= 6: + goal.add( + actr.makechunk( + "", "math_goal", proc=f"proc{i}", ones_carry="hello" ) - elif i == 7: - goal.add( - actr.makechunk( - "", "math_goal", proc="proc_overall", ones_carry="hello" - ) + ) + elif i == 7: + goal.add( + actr.makechunk( + "", "math_goal", proc="proc_overall", ones_carry="hello" ) - elif i > 7: - print("DONE") - break - - # sim.run(max_time=25) - print(userinput) - print("Simulation time: ", sim.show_time()) - print("goal: ", goal) - print(sim.current_event) - pprint(vars(sim)) - pprint(vars(sim._Simulation__env)) - # print(sim.__env) - # sim.__printenv__() - # print(envs.stimulus) - # print("imaginal: ", imaginal) - math_goals = [sim for sim in list(DM) if sim.typename == "procedure"] - # print(math_goals) + ) + elif i > 7: + print("DONE") + break + + # sim.run(max_time=25) + print(userinput) + print("Simulation time: ", sim.show_time()) + print("goal: ", goal) + print(sim.current_event) + pprint(vars(sim)) + pprint(vars(sim._Simulation__env)) + # print(sim.__env) + # sim.__printenv__() + # print(envs.stimulus) + # print("imaginal: ", imaginal) + math_goals = [sim for sim in list(DM) if sim.typename == "procedure"] + # print(math_goals) if __name__ == "__main__": |