Ejemplo n.º 1
0
def process_result( pomdp, observation, machine_action, Q, param_dict, \
                        use_confidence_scores=False, \
                        high_confidence_histogram = None, \
                        low_confidence_histogram = None, \
                        confidence_score = 1 ):

    action_code_list = \
        tbh_pomdp_action_code_manager.get_pomdp_action_code_number_list()
    observation_list = \
        tbh_action_code_manager.get_action_code_number_list()

    if use_confidence_scores:

        # determine the observation number in question
        observation_number = \
            tbh_action_code_manager.get_number_action_code( \
            observation_list, observation )

        # determine the confidence value
        confidence_in_hypothesis = confidence_score

        # We now have the machine_action_number, 
        # the observation_number, and the current belief
        # We can do a belief update!
        belief_for_policy = \
            tbh_pomdp_util.belief_update( \
            pomdp, pomdp.belief, \
                machine_action_number, \
                observation_number, \
                confidence_in_hypothesis, \
                use_confidence_scores=True, \
                high_confidence_model=high_confidence_histogram, \
                low_confidence_model=low_confidence_histogram )

        pomdp_dict = pomdp_choose_action( pomdp, Q, \
                                              belief_for_policy, action_code_list )

        pomdp_dict['confidence_in_hypothesis'] = confidence_in_hypothesis

    else:
        observation_number = tbh_action_code_manager.get_number_action_code( \
            observation_list, observation )

        # We now have the machine_action_number, the observation_number
        # and the current belief
        # We can do a belief update!
        belief_for_policy = tbh_pomdp_util.belief_update( pomdp, pomdp.belief, \
                                                       machine_action_number, \
                                                       observation_number )

        pomdp_dict = pomdp_choose_action( pomdp, Q, \
                                              belief_for_policy, action_code_list )

    return pomdp_dict
Ejemplo n.º 2
0
def process_result( pomdp, observation, machine_action, Q, param_dict, use_confidence_scores=False, skype_contacts_dict=None ):
    '''
    # Take the action_code and translate it into an observation
    ( observation_code, machine_action_code ) = \
        translate_into_pomdp_codes( observation, machine_action )

        # Run the belief update
    '''
    # Determine the desired action from the policy (perhaps solve the QMDP \
    # for this particular belief)

    # Return data structure   

    # Sandbox: The POMDP does not do anything
    #( new_belief, action_code ) = sandbox_result( belief, observation )
    
    # More sophisticated result


    action_code_list = tbh_pomdp_action_code_manager.get_pomdp_action_code_number_list()
    observation_list = tbh_action_code_manager.get_action_code_number_list()


    if machine_action is None:
        machine_action = [ 'null', ['yes_record']]

    machine_action_number = tbh_pomdp_action_code_manager.get_number_action_code( \
        action_code_list, machine_action )

    '''
    # Confidence scores using n-best lists
    if use_confidence_scores:

        # simplified confidence scoring method
        # 0.5 for top result
        # 0.2 for second result
        # 0.1 for third result

        observation_number_list = []
        probability_list = [ 0.55, 0.25, 0.1 ]

        for i in range(0,3):
            observation_number = tbh_action_code_manager.get_number_action_code( \
                observation_list, observation[i] )

            observation_number_list.append( { observation_number : \
                                                  probability_list[i] } )


        # We now have the machine_action_numbeor, the observation_number, and the current belief
        # We can do a belief update!

        

        belief_for_policy = tbh_pomdp_util.belief_update_with_confidence_scores( pomdp, pomdp.belief, \
                                                       machine_action_number, \
                                                       observation_number_list )

        #print pomdp.belief.shape
        #print belief_for_policy.shape

        pomdp_dict = pomdp_choose_action( pomdp, Q, \
                                              belief_for_policy, action_code_list )

    '''                                              

    if use_confidence_scores:

        # determine the observation number in question
        observation_number = tbh_action_code_manager.get_number_action_code( \
            observation_list, observation )

        # determine the confidence value
        confidence_in_hypothesis = determine_confidence_in_hypothesis( \
            param_dict['adaboost_score'], LOGISTIC_PARAMETERS )

        # using the confidence in the hypothesis

        # We now have the machine_action_number, 
        # the observation_number, and the current belief
        # We can do a belief update!
        belief_for_policy = \
            tbh_pomdp_util.belief_update( \
            pomdp, pomdp.belief, \
                machine_action_number, \
                observation_number, \
                confidence_in_hypothesis )



        #print pomdp.belief.shape
        #print belief_for_policy.shape

        pomdp_dict = pomdp_choose_action( pomdp, Q, \
                                              belief_for_policy, action_code_list )

        pomdp_dict['confidence_in_hypothesis'] = confidence_in_hypothesis

    else:
        observation_number = tbh_action_code_manager.get_number_action_code( \
            observation_list, observation )

        # We now have the machine_action_number, the observation_number
        # and the current belief
        # We can do a belief update!
        belief_for_policy = tbh_pomdp_util.belief_update( pomdp, pomdp.belief, \
                                                       machine_action_number, \
                                                       observation_number )

        pomdp_dict = pomdp_choose_action( pomdp, Q, \
                                              belief_for_policy, action_code_list )

    return pomdp_dict