def evaluateEpistemicState(self, epi): kb = epi[self.target] v = epi['V'] basicLogic.setkbfromv(kb, v) # we are allowed to assume a monotonic logic base for this for rule in kb: if isinstance(rule, basicLogic.atom): v = m_th_simplified.addVarAssignmentToV( v, rule.getName(), True) elif isinstance(rule, basicLogic.operator_monotonic_negation): if isinstance(rule.clause, basicLogic.atom): v = m_th_simplified.addVarAssignmentToV( v, rule.clause.getName(), False) elif isinstance(rule, basicLogic.operator_bitonic): head = rule.clause1 body = rule.clause2 bodyVal = body.evaluate() if isinstance(rule, basicLogic.operator_bitonic_implication): if isinstance(head, basicLogic.atom): if bodyVal != None: v = m_th_simplified.addVarAssignmentToV( v, head.getName(), bodyVal) else: print("unknown bitonic") else: print("unknown operation") epi['V'] = v epi[self.target] = kb #remove all v assignments from this epi, th is not an evaluation function for v in epi['V']: for rule in epi[self.target]: rule.deepSet(v.getName(), None) return epi
def setTruth(epi): S = epi['S'] V = epi['V'] ats = epi.getAtomNamesInStructuralVariables(['S']) #Assign TRUTH in possible world for rule in S: #clear the interpretation basicLogic.setkbfromv(epi['S'], V) left = rule.clause1 right = rule.clause2 if left.getName() in ats: evaluation = right.evaluate() if evaluation == True: m_semantic.changeAssignmentInV(left.getName(), evaluation, V) left = rule.clause2 right = rule.clause1 if left.getName() in ats: evaluation = right.evaluate() if evaluation == True: m_semantic.changeAssignmentInV(left.getName(), evaluation, V) return epi
def setFalse(epi): #I_V(S) S = epi['S'] V = epi['V'] ats = epi.getAtomNamesInStructuralVariables(['S']) #Assign TRUTH in possible world for rule in S: #clear the interpretation epi['S'] = basicLogic.setkbfromv(epi['S'], V) left = rule.clause1 right = rule.clause2 if left.getName() in ats: evaluation = right.evaluate() if evaluation == False: shared = CognitiveOperation.getBodiesWhichShareHead( left, epi['S']) allFalse = True for body in shared: if body.evaluate() != False: allFalse = False if allFalse: m_semantic.changeAssignmentInV(left.getName(), evaluation, V) left = rule.clause2 right = rule.clause1 if left.getName() in ats: evaluation = right.evaluate() if evaluation == False: shared = CognitiveOperation.getBodiesWhichShareHead( left, epi['S']) allFalse = True for body in shared: if body.evaluate() != False: allFalse = False if allFalse: m_semantic.changeAssignmentInV(left.getName(), evaluation, V) return epi
def f_turn(pi, observation): finalStructures = pi.evaluate() finalStates = StatePointOperations.flattenStatePoint(finalStructures) if not isinstance(finalStates, list): finalStates = [finalStates] conditional = scpNotationParser.stringListToBasicLogic( ["( ( 3 | D ) or ( D' | 7 ) )"]) # we are willing to turn the card if either the (3 | D) or the contrapositive case ( D' | 7 ) holds obs = scpNotationParser.stringListToBasicLogic( ['( {} <- T )'.format(observation)]) responses = [] for epi in finalStates: #print ("\n") #print (epi) basicLogic.setkbfromv(obs, epi['V']) #the conditional must be verified or falsified #the observation must be True allObsTrue = True for o in obs: if o.evaluate() != True: allObsTrue = False #allCondApplicable = True if allObsTrue: responses.append('observations hold') else: responses.append('observations do not') #now we need to find the minimal set of abducibles to turn the cards turnResponses = [] #WE PREFER MINIMAL EXPLANATIONS for i in range(0, len(responses)): if responses[i] == 'observations hold': turnResponses.append(finalStates[i]) minimalSubset = [] for epi in turnResponses: #print ("epi is ", epi) #print (epi['R']['abducibles']) #print ("and then here") x = [ StatePointOperations.properSubset(ot['R']['abducibles'], epi['R']['abducibles']) for ot in turnResponses ] #another least model is a subset of this one if True in x: pass else: minimalSubsetAsVariables = epi['V'] minimalSubsetAsList = StatePointOperations.VtoTupleList( minimalSubsetAsVariables, ignoreNone=True) if minimalSubsetAsList not in minimalSubset: minimalSubset.append(minimalSubsetAsVariables) turns = [] for mini in minimalSubset: allCondApplicable = True #this is done later basicLogic.setkbfromv(conditional, mini) #print ("mini is : ", mini) for cond in conditional: #print (cond, "Evaluates to ", cond.evaluate()) if cond.evaluate() == None: #print ("evaluation was ", cond.evaluate()) allCondApplicable = False #print ("cond is ",cond) if allCondApplicable: turns.append('Turn Card') #print ("1") else: turns.append('Do Not Turn') #print("2") return turns