def standardSuppression(): print("===========================================================") print("================STANDARD SUPPRESSION========================") print("===========================================================") basePoint_el = createBasePoint_el() basePoint_elo = createBasePoint_elo() statePoints = [basePoint_el, basePoint_elo] s_i = statePoints f = f_suppression_studyLate #The desired output of the external evaluation function gamma = { 'el': 'She will study late in the library', 'elo': 'We are uncertain if she will study late in the library' } #test ctm c = CTM.CTM() c.setSi(s_i) c.appendm(ADDAB) c.appendm(WC) c.appendm(SEMANTIC) predictions = f(c) print('predictions: ', predictions) print("Lenient Interp") print( StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma)) print("Strict Interp") print( StatePointOperations.predictionsModelsGamma_strict(predictions, gamma)) print("f(pi) models gamma_Sup? : ", (StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma)))
def f_suppression_studyLate(pi): finalStructures = pi.evaluate() finalStates = StatePointOperations.flattenStatePoint(finalStructures) #print (finalStates) #get all realised epis with 'el' name statesForCaseEL = StatePointOperations.extractBasePointsFromFlattenedStatePoint( finalStates, name="el") #get all realised epis with 'elo' name statesForCaseELO = StatePointOperations.extractBasePointsFromFlattenedStatePoint( finalStates, name="elo") # find the set of responses that that the realised SCPs of 'el' could reach responsesEL = f_studyLateSingle(statesForCaseEL) # find the set of responses that that the realised SCPs of 'elo' could reach responsesELO = f_studyLateSingle(statesForCaseELO) #suppression has occured if there is a response in responsesEL which is NOT # in responsesELO """ for r1 in responsesEL: if r1 not in responsesELO: print ("The response '{}' occurs for 'el', but not for 'elo'".format(r1)) return "Suppression observed" return "Suppression not observed" """ return {'el': responsesEL, 'elo': responsesELO}
def abducibleSuppression(): print("===========================================================") print("=================ABDUCIBLE SUPPRESSION=====================") print("===========================================================") basePoint1 = epistemicState.epistemicState('el') delta1 = ["( l | e )"] S1 = ["( e <- T )"] delta1AsLogic = scpNotationParser.stringListToBasicLogic(delta1) S1AsLogic = scpNotationParser.stringListToBasicLogic(S1) basePoint1['S'] = S1AsLogic basePoint1['Delta'] = delta1AsLogic basePoint1['V'] = [e, l] #The elo case expressed as the addition of information to the el case basePoint2 = copy.deepcopy(basePoint1) basePoint2.setName('elo') #The possible starting states for the SCP extraConditional = ["( l | o )"] extraConditionalAsLogic = scpNotationParser.stringListToBasicLogic( extraConditional) basePoint2['Delta'] = basePoint2['Delta'] + extraConditionalAsLogic basePoint2['V'] = basePoint2['V'] + [o] #abducibs = [ '( l <- T )', '( l <- F )','( o <- T )', '( o <- F )'] abducibs = ['( o <- T )', '( o <- F )'] logAbducibs = scpNotationParser.stringListToBasicLogic(abducibs) basePoint1['R'] = {'abducibles': logAbducibs} basePoint2['R'] = {'abducibles': logAbducibs} #Create the first state point statePoints = [basePoint1, basePoint2] s_i = statePoints f = f_suppression_studyLate #The desired output of the external evaluation function gamma = { 'el': 'She will study late in the library', 'elo': 'We are uncertain if she will study late in the library' } #test ctm c = CTM.CTM() c.setSi(s_i) c.appendm(ADDAB) c.appendm(ABDUCIBLES) c.appendm(WC) c.appendm(SEMANTIC) predictions = f(c) print('predictions: ', predictions) print("Lenient Interp") print( StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma)) print("Strict Interp") print( StatePointOperations.predictionsModelsGamma_strict(predictions, gamma)) print("f(pi) models gamma_noSup? : ", (StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma)))
def s_satisfying(self, results): satisfyingResults = [] for result in results: #print ("result is ",result) #print (self.f(result)) predModelsGamma = StatePointOperations.predictionsModelsGamma_lenient( self.f(result), self.gamma) if predModelsGamma: satisfyingResults.append(result) return StatePointOperations.CTMtoSCP(satisfyingResults, self.f)
def mu_D7_example(): print("\n>>Example for SCP that turns the cards: D, 7...") #create initial base point which has only a single epistemic state in it s_i = create_si_contra() #The final state dependent external evaluation function f = f_turnFunction_prefDoNoTurn #the turn responses which would we would like to achieve gamma_D7 = { 'D': 'Turn Card', 'K': 'Do Not Turn', '3': 'Do Not Turn', '7': 'Turn Card' } #This is a test SCP mu=(c,f()) which is known to work c = CTM.CTM() c.setSi(s_i) c.appendm(ADDAB) c.appendm(ABDUCIBLES) c.appendm(WC) c.appendm(SEMANTIC) #the set of possible observations which might need to be explained to see if we should # turn a card observations = ['D', 'K', '3', '7'] #use the turn function to evaluate the ctm and see if the card should be turned # we prefer the 'Do Not Turn' response in this case predictions = f(c, observations) print("First state point is ", s_i) print("Example SCP is ", c.__repr__()) #to print all final states uncomment the next line #print("Final State point is : ", c.evaluate()) #the decisions made by f() for the SCP (c,f()) print("Responses: ", predictions) #print True if mu|=gamma_D3 print( "Lenient: mu|=gamma_D7 :", StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma_D7)) print( "Strict: mu|=gamma_D7 :", StatePointOperations.predictionsModelsGamma_strict( predictions, gamma_D7))
def getTh(epi): tempCTM = CTM.CTM() tempCTM.si = [epi] tempCTM.appendm(m_th_simplified(target='W')) #guaranteed to be monotonic epi = StatePointOperations.flattenStatePoint(tempCTM.evaluate())[0] # 2) generateProcesses return epi
def getSiStructure(self): structure = [] flattenedSi = StatePointOperations.flattenStatePoint(self.si) if not isinstance(flattenedSi, list): flattenedSi = [flattenedSi] #print ("FLATTENED si IS ", flattenedSi) for epi in flattenedSi: structure = structure + epi.getStructuralVariables() return list(dict.fromkeys(structure))
def abducibleSuppression(): print("===========================================================") print("=================ABDUCIBLE SUPPRESSION=====================") print("===========================================================") basePoint_el = createBasePoint_el() basePoint_elo = createBasePoint_elo() statePoints = [basePoint_el, basePoint_elo] #abducibs = [ '( l <- T )', '( l <- F )','( o <- T )', '( o <- F )'] abducibs = ['( o <- T )', '( o <- F )'] logAbducibs = scpNotationParser.stringListToBasicLogic(abducibs) basePoint_el['R'] = {'abducibles': logAbducibs} basePoint_elo['R'] = {'abducibles': logAbducibs} #Create the first state point statePoints = [basePoint_el, basePoint_elo] s_i = statePoints f = f_suppression_studyLate #The desired output of the external evaluation function gamma = { 'el': 'She will study late in the library', 'elo': 'We are uncertain if she will study late in the library' } #test ctm c = CTM.CTM() c.setSi(s_i) c.appendm(ADDAB) c.appendm(ABDUCIBLES) c.appendm(WC) c.appendm(SEMANTIC) predictions = f(c) print('predictions: ', predictions) print("Lenient Interp") print( StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma)) print("Strict Interp") print( StatePointOperations.predictionsModelsGamma_strict(predictions, gamma)) print("f(pi) models gamma_noSup? : ", (StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma)))
def deletionSuppression(): print("===========================================================") print("================DELETION SUPPRESSION=======================") print("===========================================================") print("===========================================================") basePoint_el = createBasePoint_el() basePoint_elo = createBasePoint_elo() statePoints = [basePoint_el, basePoint_elo] basePoint_el['R'] = {'delete': ["o", "e"]} basePoint_elo['R'] = {'delete': ["o", "e"]} #Create the first state point statePoints = [basePoint_el, basePoint_elo] s_i = statePoints #The external evaluation function f = f_suppression_studyLate #The desired output of the external evaluation function gamma = { 'el': 'She will study late in the library', 'elo': 'We are uncertain if she will study late in the library' } #test ctm c = CTM.CTM() c.setSi(s_i) c.appendm(ADDAB) c.appendm(DELETE) c.appendm(WC) c.appendm(SEMANTIC) predictions = f(c) print('predictions: ', predictions) print("Lenient Interp") print( StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma)) print("Strict Interp") print( StatePointOperations.predictionsModelsGamma_strict(predictions, gamma))
def mu_D_example(): #create initial base point which has only a single epistemic state in it s_i = create_si_noContra() #The final state dependent external evaluation function f = f_turnFunction_prefDoNoTurn #the turn responses which would we would like to achieve gamma_D = { 'D': 'Turn Card', 'K': 'Do Not Turn', '3': 'Do Not Turn', '7': 'Do Not Turn' } #This is a test SCP mu=(c,f()) which is known to work c = CTM.CTM() c.setSi(s_i) c.appendm(ADDAB) c.appendm(ABDUCIBLES) c.appendm(WC) c.appendm(SEMANTIC) #the set of possible observations which might need to be explained to see if we should # turn a card observations = ['D', 'K', '3', '7'] #use the turn function to evaluate the ctm and see if the card should be turned # we prefer the 'Do Not Turn' response in this case predictions = f(c, observations) #print True if mu|=gamma_D3 print("Responses: ", predictions) print( "Lenient: mu|=gamma_D :", StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma_D)) print( "Strict: mu|=gamma_D :", StatePointOperations.predictionsModelsGamma_strict( predictions, gamma_D))
#print (deletionSuppression()) #test ctm c = CTM.CTM() c.setSi(s_i) c.appendm(ADDAB) #c.appendm(ABDUCIBLES) c.appendm(DELETE) c.appendm(WC) c.appendm(SEMANTIC) predictions = f(c) print('predictions: ', predictions) print("Lenient Interp") print(StatePointOperations.predictionsModelsGamma_lenient(predictions, gamma)) print("Strict Interp") print(StatePointOperations.predictionsModelsGamma_strict(predictions, gamma)) #print (c.evaluate()) searchResult = task.deNoveSearch() print("\nSEARCH RESULTS:") print(searchResult) print("\n") result1 = searchResult[0] print("RESULT 1: IS\n", result1)
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
def s_exhaustive(self, results): return StatePointOperations.CTMtoSCP(results, self.f)