예제 #1
0
def create_si_contra():
    #define the initial atomic name in the WCS: one for each observed card
    #these atoms have value None
    D = basicLogic.atom('D')
    K = basicLogic.atom('K')
    three = basicLogic.atom('3')
    seven = basicLogic.atom('7')
    #this is the atom which means NOT (D)
    Dprime = basicLogic.atom("D'")

    #create an epistemic state containing the known facts and conditionals
    basePointContra = epistemicState.epistemicState('WST')
    #the set of conditionals with the contraposition rule
    delta_contra = ["( 3 | D )", " ( D' | 7 ) "]
    #the set of conditionals as a set of <basicLogic> clauses
    deltaAsLogic = scpNotationParser.stringListToBasicLogic(delta_contra)
    #the set of facts known, this prevents negative heads in rules
    S_contra = ["( ( D ) <- ( !  D'  ) )"]
    #the set of known facts as <basicLogic>
    SAsLogic = scpNotationParser.stringListToBasicLogic(S_contra)
    #the set of abducibles, any subset of which might be an explanation
    abducibs = [
        '( D <- T )', '( D <- F )', '( K <- T )', '( K <- F )', '( 3 <- T )',
        '( 3 <- F )', '( 7 <- T )', '( 7 <- F )'
    ]
    abducibs = ['( D <- T )', '( K <- T )', '( 3 <- T )', '( 7 <- T )']
    #transform the set of abducibles to a set of <basicLogic> clauses
    logAbducibs = scpNotationParser.stringListToBasicLogic(abducibs)

    #set the structural variables of the only epistemic state in the intial state point
    basePointContra['S'] = SAsLogic
    basePointContra['Delta'] = deltaAsLogic
    basePointContra['V'] = [D, K, three, seven, Dprime]
    basePointContra['R'] = {'abducibles': logAbducibs}
    return [basePointContra]
예제 #2
0
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())
예제 #3
0
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 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)))
예제 #5
0
def createBasePoint_el():
    basePoint_el = epistemicState.epistemicState('el')
    delta1 = ["( l | e )"]
    S1 = ["( e <- T )"]
    delta1AsLogic = scpNotationParser.stringListToBasicLogic(delta1)
    S1AsLogic = scpNotationParser.stringListToBasicLogic(S1)
    basePoint_el['S'] = S1AsLogic
    basePoint_el['Delta'] = delta1AsLogic
    basePoint_el['V'] = [e, l]
    return basePoint_el
예제 #6
0
def scpSearch():
    print(
        "=======================BEGINNING SEARCH==============================="
    )
    basePoint_el = createBasePoint_el()
    basePoint_elo = createBasePoint_elo()

    #abducibs = [ '( l <- T )', '( l <- F )','( o <- T )', '( o <- F )']
    abducibs = ['( o <- T )', '( o <- F )']
    logAbducibs = scpNotationParser.stringListToBasicLogic(abducibs)

    basePoint_el['R'] = {'delete': ["o", "e"]}
    basePoint_elo['R'] = {'delete': ["o", "e"]}
    basePoint_el['R']['abducibles'] = logAbducibs
    basePoint_elo['R']['abducibles'] = logAbducibs

    #Create the first state point
    statePoints = [basePoint_el, basePoint_elo]
    s_i = statePoints
    #The set of possible states
    M = [ADDAB, SEMANTIC, WC]
    #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'
    }

    #The SCP task which states what is required from a solution SCP or realised SCP
    task = SCP_Task.SCP_Task(s_i, M, f, gamma)

    searchResult = task.deNoveSearch()
    print("\nSEARCH RESULTS:")
    print(strSCPLi(searchResult))
예제 #7
0
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())
예제 #8
0
def createBasePoint_elo():
    #The elo case expressed as the addition of information to the el case
    basePoint_el = copy.deepcopy(createBasePoint_el())
    basePoint_elo = copy.deepcopy(basePoint_el)
    basePoint_elo.setName('elo')
    #The possible starting states for the SCP
    extraConditional = ["( l | o )"]
    extraConditionalAsLogic = scpNotationParser.stringListToBasicLogic(
        extraConditional)
    basePoint_elo['Delta'] = basePoint_elo['Delta'] + extraConditionalAsLogic
    basePoint_elo['V'] = basePoint_elo['V'] + [o]
    basePoint_elo['R'] = {'delete': ["o", "e"]}
    basePoint_elo['R'] = {'delete': ["o", "e"]}
    return basePoint_elo
예제 #9
0
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)))
        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"]}
예제 #11
0
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