From 9d6dbdfd2349ba1443015c654cc1bbfdcce4542d Mon Sep 17 00:00:00 2001 From: Patrick Hammer Date: Mon, 15 Jan 2024 21:56:28 +0100 Subject: [PATCH] Update: print certainty values properly --- main.py | 6 +++--- nace.py | 15 +++++++++++---- prettyprint.py | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 44bbc13..164155c 100644 --- a/main.py +++ b/main.py @@ -37,7 +37,7 @@ if __name__ == "__main__": for Time in range(300): start_time = time.time() - usedRules, FocusSet, RuleEvidence, loc, observed_world, rules, negrules, world, debuginput = NACE_Cycle(Time, FocusSet, RuleEvidence, loc, observed_world, rules, negrules, deepcopy(world)) + usedRules, FocusSet, RuleEvidence, loc, observed_world, rules, negrules, world, debuginput, values = NACE_Cycle(Time, FocusSet, RuleEvidence, loc, observed_world, rules, negrules, deepcopy(world)) end_time = time.time() print("VALUES", world[VALUES], "FOCUS SET", FocusSet) elapsed_time = end_time - start_time @@ -46,13 +46,13 @@ if "debug" in sys.argv and debuginput != "" and debuginput not in ["w", "a", "s", "d", "l", "p"]: predworld = deepcopy(observed_world) score = 0.0 - values = [] while True: print("\033[1;1H\033[2J") print("\033[0mImagined map:\033[97;43m") World_Print(predworld) print("\033[0m") - print("score:", -score, "values", values) + NACE_PrintScore(score) + print("values:", values) d = input() score = 0.0 if d == 'q': diff --git a/nace.py b/nace.py index dbbc1f7..b7084e6 100644 --- a/nace.py +++ b/nace.py @@ -60,10 +60,10 @@ def NACE_Cycle(Time, FocusSet, RuleEvidence, loc, observed_world, rulesin, negru action = favoured_actions_for_revisit[0] plan = favoured_actions_for_revisit else: - print("BABBLE", "score:", airis_score) + print("BABBLE") action = random.choice(actions) #motorbabbling else: - print("ACHIEVE" if airis_score == float("-inf") else "CURIOUS", Prettyprint_Plan(favoured_actions), "score:", -airis_score)#, rules) + print("ACHIEVE" if airis_score == float("-inf") else "CURIOUS", Prettyprint_Plan(favoured_actions), end=" "); NACE_PrintScore(airis_score) action = favoured_actions[0] plan = favoured_actions else: @@ -84,7 +84,7 @@ def NACE_Cycle(Time, FocusSet, RuleEvidence, loc, observed_world, rulesin, negru loc, newworld = World_Move(loc, deepcopy(oldworld), action) observed_world_old = deepcopy(observed_world) observed_world = World_FieldOfView(Time, loc, observed_world, newworld) - predicted_world, _, __, ___ = NACE_Predict(Time, FocusSet, deepcopy(observed_world_old), action, rules) + predicted_world, _, __, values = NACE_Predict(Time, FocusSet, deepcopy(observed_world_old), action, rules) if "manual" not in sys.argv: print(f"\033[0mWorld t={Time} beliefs={len(rules)}:\033[97;40m") World_Print(newworld) @@ -109,7 +109,7 @@ def NACE_Cycle(Time, FocusSet, RuleEvidence, loc, observed_world, rulesin, negru newrules.add(rule) else: usedRules = newrules = newnegrules = rules - return usedRules, FocusSet, RuleEvidence, loc, observed_world, newrules, newnegrules, newworld, debuginput + return usedRules, FocusSet, RuleEvidence, loc, observed_world, newrules, newnegrules, newworld, debuginput, values # Apply move to the predicted world model whereby we use the learned tules to decide how grid elements might change most likely def NACE_Predict(Time, FocusSet, oldworld, action, rules, customGoal = None): @@ -370,3 +370,10 @@ def _RuleApplicable(scores, highscore, highesthighscore, rule): if highscore > 0.0 and scores.get(rule, 0.0) == highesthighscore: return True return False + +#Print score value taking its semantics regarding its value range semantics for planning into account +def NACE_PrintScore(score): + if score >= 0.0 and score <= 1.0: + print("certainty:", score) + else: + print("desired: True") diff --git a/prettyprint.py b/prettyprint.py index 518fb52..d4f63ae 100644 --- a/prettyprint.py +++ b/prettyprint.py @@ -31,7 +31,7 @@ def Prettyprint_rule(RuleEvidence, Hypothesis_TruthValue, rule): precons = actions_values_preconditions[2:] print("<(", end="") for i, x in enumerate(actions_values_preconditions[1]): - name = "keys" + name = "var" + str(i) print(f"{_prettyVarValue(name, x)}", end="") print(f" &| ", end="") for i, x in enumerate(precons): @@ -39,7 +39,7 @@ def Prettyprint_rule(RuleEvidence, Hypothesis_TruthValue, rule): if i != len(precons)-1: print(f" &| ", end="") scoreInc = f" scorePlus>" - keys = f" keys>" + keys = f" var0>" print(") &/", action, "=/> (" + _prettyTriplet(rule[1]) + " &| " + scoreInc + " &| " + keys + ")>.", Hypothesis_TruthValue(RuleEvidence[rule])) def _prettyVarValue(name, value):