def example_nixon(): DEFAULT = cop.m_default() W = no.stringListToBasicLogic(['( quaker <- T )', ' ( republican <- T ) ']) #W = no.stringListToBasicLogic([' bird ', ' penguin ']) V = no.stringListToBasicLogic(['quaker', 'republican', 'pacifist']) #dParts = no.stringListToBasicLogic(['( bird <- T )', '( penguin <- F ) ', '( flies <- T )']) dParts = no.stringListToBasicLogic( ['( quaker <- T )', '( pacifist <- T ) ', '( pacifist <- T )']) default1 = basicLogic.operator_tritonic_defaultRule( dParts[0], [dParts[1]], dParts[2]) dParts2 = no.stringListToBasicLogic( ['( republican <- T )', '( pacifist <- F ) ', '( pacifist <- F )']) default2 = basicLogic.operator_tritonic_defaultRule( dParts2[0], [dParts2[1]], dParts2[2]) D = [default1, default2] basePoint = epistemicState.epistemicState('Bird Example') basePoint['D'] = D basePoint['W'] = W basePoint['V'] = V ctm_flight = CTM.CTM() ctm_flight.si = [basePoint] ctm_flight.appendm(DEFAULT) print(ctm_flight) print(ctm_flight.evaluate())
def example_birds(): W = no.stringListToBasicLogic(['( bird <- T )']) V = no.stringListToBasicLogic(['bird', 'flies', 'penguin']) dParts = no.stringListToBasicLogic( ['( bird <- T )', '( flies <- T ) ', '( flies <- T )']) default1 = basicLogic.operator_tritonic_defaultRule( dParts[0], [dParts[1]], dParts[2]) dParts2 = no.stringListToBasicLogic( ['( cold <- T )', '( flies <- F ) ', '( flies <- F )']) default2 = basicLogic.operator_tritonic_defaultRule( dParts2[0], [dParts2[1]], dParts2[2]) D = [default1, default2] basePoint = epistemicState.epistemicState('Bird Example') basePoint['D'] = D basePoint['W'] = W basePoint['V'] = V ctm_flight = CTM.CTM() ctm_flight.si = [basePoint] #ctm_flight.appendm(TH) ctm_flight.appendm(DEFAULT) print(ctm_flight) print(ctm_flight.evaluate())
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 example_suppression(): W = no.stringListToBasicLogic(['( e <- T )']) #W = no.stringListToBasicLogic([' bird ', ' penguin ']) V = no.stringListToBasicLogic(['e', 'l', 'o']) #dParts = no.stringListToBasicLogic(['( bird <- T )', '( penguin <- F ) ', '( flies <- T )']) dParts1 = no.stringListToBasicLogic( ['( e <- T )', '( ab1 <- F ) ', '( l <- T )']) default1 = basicLogic.operator_tritonic_defaultRule( dParts1[0], [dParts1[1]], dParts1[2]) dParts2 = no.stringListToBasicLogic( ['( o <- T )', '( ab2 <- F ) ', '( l <- T )']) default2 = basicLogic.operator_tritonic_defaultRule( dParts2[0], [dParts2[1]], dParts2[2]) dParts3 = no.stringListToBasicLogic( ['( o <- F )', '( ab1 <- T ) ', '( ab1 <- T )']) default3 = basicLogic.operator_tritonic_defaultRule( dParts3[0], [dParts3[1]], dParts3[2]) dParts4 = no.stringListToBasicLogic( ['( e <- F )', '( ab2 <- T ) ', '( ab2 <- T )']) default4 = basicLogic.operator_tritonic_defaultRule( dParts4[0], [dParts4[1]], dParts4[2]) D = [default1, default2, default3, default4] basePoint = epistemicState.epistemicState('Bird Example') basePoint['D'] = D basePoint['W'] = W basePoint['V'] = V ctm_flight = CTM.CTM() ctm_flight.si = [basePoint] #ctm_flight.appendm(TH) ctm_flight.appendm(DEFAULT) print(ctm_flight) print(ctm_flight.evaluate())
def f_turn(pi, observation): finalStructures = pi.evaluate() finalStates = StatePointOperations.flattenStatePoint(finalStructures) if not isinstance(finalStates, list): finalStates = [finalStates] #print("Final states") #print(finalStates) #severe problem using interpetation of conditionals with de-finnetti truth table # @TODO how do we resolve???? # maybe determine if the conditional CAN be falsified? #@TODO parser struggles with ( ( a | b) or ( c | d ) ) 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 print("CONDITIONAL") print(conditional) 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 ("we made it here") #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 Card') #print("2") return turns
basePointNoAbd = epistemicState.epistemicState('') #The possible starting states for the SCP delta_contra = ["( 3 | D )", " ( D' | 7 ) "] #delta_nocontra=["( 3 | D )"] #delta1=["( l | e )", "( l | o )"] #S_nocontra = [""] S_contra = ["( ( D ) <- ( ! D' ) )"] #set to 8 to run all abducibles abducibs = [ '( D <- T )', '( D <- F )', '( K <- T )', '( K <- F )', '( 3 <- T )', '( 3 <- F )', '( 7 <- T )', '( 7 <- F )' ] #abducibs = ['( K <- T )'] #abducibs = [ '( 7 <- T )', '( 7 <- F )'] logAbducibs = scpNotationParser.stringListToBasicLogic(abducibs) delta1AsLogic = scpNotationParser.stringListToBasicLogic(delta_contra) S1AsLogic = scpNotationParser.stringListToBasicLogic(S_contra) print(S1AsLogic) basePointNoAbd['S'] = S1AsLogic basePointNoAbd['Delta'] = delta1AsLogic basePointNoAbd['V'] = [D, K, three, seven, Dprime] basePointNoAbd['R'] = {'abducibles': logAbducibs} #Create the first state point # K case basePointD = copy.deepcopy(basePointNoAbd) basePointD.setName('abducible:D')
print("response(p_bar):", responses[-1]) print("------------------------------") return responses # THE SET OF COGNITIVE OPERATIONS APPROPRIATE TO THE SUPPRESSION TASK ADDAB = CognitiveOperation.m_addAB() WC = CognitiveOperation.m_wc() SEMANTIC = CognitiveOperation.m_semantic() ABDUCIBLES = CognitiveOperation.m_addAbducibles(maxLength=4) DELETE = CognitiveOperation.m_deleteo() 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] basePoint1['R'] = {'delete': ["o", "e"]}