Example #1
0
def compare_trial(trial_id, move_probability):
    # get the trial
    trial = db.get_trial(trial_id)

    # list of the images initially currently grouped
    initial_images = [x for x in trial['init_state'] if x['group'] != -1]

    # a dict of the currently partitioned objects.  The key is the image_id, and
    # the value is the group
    current_partition = {}
    for image in initial_images:
        image_id = str(image['_id'])
        current_partition[image_id] = image['group']

    moveNum = -1
    totalMoveNum = len(trial['moves']);
    # iterate over each move in the trial
    for move in trial['moves']:
        moveNum += 1
        print "\tRunning move", moveNum, "of", totalMoveNum

        # calculate the normalized log probability of each potential move according to the particle filter
        if moveNum > 0:
            probs = move_probability(current_partition, move)

            # augment the move object
            move['move_results'] = probs
            move['partition'] = copy(current_partition)
            move['likelihood'] = probs[move['new_group']];
        else:
            move['move_results'] = {0:0.0}
            move['partition'] = copy(current_partition)
            move['likelihood'] = 0.0;

        print "\tFound likelihood:", move['likelihood'];
        # update the current partition
        current_partition[move['image_id']] = move['new_group']

    return trial
Example #2
0
def run_trial_for_params(trial_id):
    trial = db.get_trial(trial_id);
    print "Starting...";
    trial = compare_trial(trial['_id'], find_params_for_move);
    print "Done!"