Skip to content

Commit

Permalink
Reward termlinks for #75
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrock4t committed Jan 31, 2024
1 parent 2a15f53 commit f252578
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 5 additions & 6 deletions pynars/NARS/DataStructures/_py/Link.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,6 @@ def get_index(cls, main_term: Union[Term, Statement, Compound], sub_term: Union[

return indices

@classmethod
def update_budget(cls, budget: Budget, q: float, p_belief: float):
budget.priority = min(1.0, Or(budget.priority, Or(q, p_belief)))
budget.durability = min(1.0-Config.budget_epsilon, Or(budget.durability, q))



@property
def is_valid(self):
Expand All @@ -211,6 +205,11 @@ def set_type(self, source_is_component=True, type: LinkType=None):
Link.set_type(self, source_is_component, type)
if not self.is_valid: self.type = None


def reward_budget(self, reward: float):
self.budget.quality = Or(self.budget.quality, reward)


@property
def is_valid(self):
return self.type in (
Expand Down
11 changes: 7 additions & 4 deletions pynars/NARS/InferenceEngine/GeneralEngine/GeneralEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,13 @@ def step(self, concept: Concept):
if is_valid:
Global.States.record_premises(task, belief)
Global.States.record_rules(rules)
tasks = self.inference(task, belief, term_belief, task_link_valid, term_link_valid, rules)
if term_link_valid is not None: # TODO: Check here whether the budget updating is the same as OpenNARS 3.0.4.
for task in tasks: TermLink.update_budget(term_link_valid.budget, task.budget.quality, belief.budget.priority if belief is not None else concept_target.budget.priority)

derived_tasks = self.inference(task, belief, term_belief, task_link_valid, term_link_valid, rules)
if term_link_valid is not None:
# reward the termlink
for derived_task in derived_tasks:
reward: float = max(derived_task.budget.priority, task.achieving_level())
TermLink.reward_budget(reward)

tasks_derived.extend(tasks)

for term_link in term_links: concept.term_links.put_back(term_link)
Expand Down

0 comments on commit f252578

Please sign in to comment.