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 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 evaluateEpistemicState(self, epi): tempCTM = CTM.CTM() tempCTM.si = [epi] tempCTM.appendm(m_wc()) tempCTM.appendm(m_semantic()) p = tempCTM.evaluate() return p
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_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 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 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 deNoveSearch(self, depth=3, searchType="satisfying"): searchTypes = { "exhaustive": self.s_exhaustive, "satisfying": self.s_satisfying } firstCTM = CTM.CTM() firstCTM.si = self.si ctms = firstCTM results = self.dns(ctms, depth) results = searchTypes[searchType](results) return results
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 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('predictions: ', predictions) print("Lenient Interp") print( StatePointOperations.predictionsModelsGamma_lenient( predictions, gamma)) print("Strict Interp") print( StatePointOperations.predictionsModelsGamma_strict(predictions, gamma)) #print (standardSuppression()) abducibleSuppression() #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))
def needleman_wunsch(seq1, seq2): # Store length of two sequences n = len(seq1) m = len(seq2) # Generate matrix of zeros to store scores score = zeros(m + 1, n + 1) # Calculate score table # Fill out first column score[0][0] = 0 for i in range(1, m + 1): score[i][0] = score[i - 1][0] + insertionCosts[type(seq2[i - 1])] #score[i][0] = insertionCosts # Fill out first row for j in range(1, n + 1): score[0][j] = score[0][j - 1] + insertionCosts[type(seq1[j - 1])] # Fill out all other values in the score matrix for i in range(1, m + 1): for j in range(1, n + 1): # Calculate the score by checking the top, left, and diagonal cells match = score[i - 1][j - 1] + match_score(seq1[j - 1], seq2[i - 1]) delete = score[i - 1][j] + insertionCosts[type(seq2[i - 1])] insert = score[i][j - 1] + insertionCosts[type(seq1[j - 1])] # Record the maximum score from the three possible scores calculated above score[i][j] = max(match, delete, insert) # Traceback and compute the alignment #THIS IS WHERE WE MAKE BIG CHANGES! # Create variables to store alignment al1 = CTM.CTM() al2 = CTM.CTM() al1.si == None al2.si == None # Start from the bottom right cell in matrix i = m j = n # We'll use i and j to keep track of where we are in the matrix, just like above while i > 0 and j > 0: # end touching the top or the left edge score_current = score[i][j] score_diagonal = score[i - 1][j - 1] score_up = score[i][j - 1] score_left = score[i - 1][j] # Check to figure out which cell the current score was calculated from, # then update i and j to correspond to that cell. if score_current == score_diagonal + match_score( seq1[j - 1], seq2[i - 1]): al1.appendm(seq1[j - 1]) al2.appendm(seq2[i - 1]) i -= 1 j -= 1 elif score_current == score_up + insertionCosts[type(seq1[j - 1])]: al1.appendm(seq1[j - 1]) al2.appendm(NONE) j -= 1 elif score_current == score_left + insertionCosts[type(seq2[i - 1])]: al1.appendm(NONE) al2.appendm(seq2[i - 1]) i -= 1 # Finish tracing up to the top left cell while j > 0: al1.appendm(seq1[j - 1]) al2.appendm(NONE) j -= 1 while i > 0: al1.appendm(seq2[i - 1]) al2.appendm(NONE) i -= 1 # Since we traversed the score matrix from the bottom right, our two sequences will be reversed. # These two lines reverse the order of the characters in each sequence. al1.NMTransformation() al2.NMTransformation() return (al1, al2, score)
import os os.chdir("../") from SCPFramework import CTM from SCPFramework import CognitiveOperation #the insertion operation. Only used in scoring and alignment NONE = CognitiveOperation.m_insertionOperation() # 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() s_i = ['$s_\text{WST}$'] c = CTM.CTM() c.setSi(s_i) c.appendm(ADDAB) c.appendm(WC) c.appendm(SEMANTIC) d = CTM.CTM() d.setSi(s_i) d.appendm(ADDAB) d.appendm(ABDUCIBLES) d.appendm(WC) d.appendm(SEMANTIC) TH = CognitiveOperation.m_dummyOperation('th') e = CTM.CTM()