示例#1
0
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 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
示例#3
0
 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))
示例#4
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