def modus_ponens_formula(B, AB, A): sA = get_value(A, tv=True).mean cA = get_value(A, tv=True).confidence sAB = get_value(AB, tv=True).mean cAB = get_value(AB, tv=True).confidence snotAB = 0.2 # Huge hack cnotAB = 1 new_tv = TTruthValue(precise_modus_ponens_strength_formula(sA, sAB, snotAB), min(cAB, cnotAB, cA)) cog_merge_hi_conf_tv(B, new_tv) return B
def extract(self, result): tmp = [get_value(x) for x in result.out] results = [] for item in tmp: name = tbd_helpers.filter_reg.match(item['name']).group(2) results.append((item['attention'].sum().numpy(), name)) return results
def gt_zero_confidence(atom): tensor_tv = get_value(atom, tv=True) result = TruthValue(0 < tensor_tv.confidence, 1) return result
def cog_merge_hi_conf_tv(atom, tv): old_tv = get_value(atom, tv=True) if old_tv.confidence < tv.confidence: set_value(atom, tv, tv=True) atom.tv = TruthValue(float(tv.mean), float(tv.confidence))
atomspace = AtomSpace() initialize_opencog(atomspace) inp = InputModule(ConceptNode("image"), torch.tensor(1.)) InheritanceLink(ConceptNode("red"), ConceptNode("color")) InheritanceLink(ConceptNode("green"), ConceptNode("color")) net1 = AttentionModule(ConceptNode("red")) net2 = AttentionModule(ConceptNode("green")) # direct execution proceeds as usual print(net1(inp())) # execution from Atomese prog1 = net1.execute(inp.execute()) print(prog1) print(get_value(execute_atom(atomspace, prog1))) prog2 = net2.execute(inp.execute()) print(get_value(execute_atom(atomspace, prog2))) bl = BindLink( TypedVariableLink(VariableNode("$X"), TypeNode("ConceptNode")), #VariableNode("$X"), AndLink( InheritanceLink(VariableNode("$X"), ConceptNode("color")), evaluate( VariableNode("$X"), inp.execute()) #inp.execution() == execute(ConceptNode("image")) ), VariableNode("$X")) print(execute_atom(atomspace, bl))