Skip to content

Commit

Permalink
Update: print certainty values properly
Browse files Browse the repository at this point in the history
  • Loading branch information
patham9 committed Jan 15, 2024
1 parent 0427283 commit 9d6dbdf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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':
Expand Down
15 changes: 11 additions & 4 deletions nace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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")
4 changes: 2 additions & 2 deletions prettyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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):
print(f"{_prettyTriplet(x)}", end="")
if i != len(precons)-1:
print(f" &| ", end="")
scoreInc = f"<s_{rule[1][3][0]} --> scorePlus>"
keys = f"<k_{rule[1][3][1]} --> keys>"
keys = f"<k_{rule[1][3][1]} --> var0>"
print(") &/", action, "=/> (" + _prettyTriplet(rule[1]) + " &| " + scoreInc + " &| " + keys + ")>.", Hypothesis_TruthValue(RuleEvidence[rule]))

def _prettyVarValue(name, value):
Expand Down

0 comments on commit 9d6dbdf

Please sign in to comment.