Пример #1
0
def trial_split_half_RMs(trials, image_property, response_property, rng):
    if rng is None:
        rng = np.random.RandomState(0)
    inds = rng.permutation(trials.shape[0])
    half = inds.shape[0]/2
    inds1, inds2 = inds[:half], inds[half:]
    trials1 = trials[inds1]
    trials2 = trials[inds2]
    RM1 = CM.get_response_matrix(trials1, image_property, response_property, group_by_worker=True)
    RM2 = CM.get_response_matrix(trials2, image_property, response_property, group_by_worker=True)
    return RM1, RM2
def get_rms(data, split_field, image_property, response_property, split_field_vals=None):
    RMs = []
    if split_field is None:
        RMs.append(cm.get_response_matrix(data, image_property, response_property, group_by_worker=True))
    else:
        if split_field_vals is None:
            split_field_vals = np.unique(data[split_field])
        for fval in split_field_vals:
            rel_data = data[data[split_field] == fval]
            RMs.append(cm.get_response_matrix(rel_data, image_property=image_property,
                                              response_property=response_property, group_by_worker=True)[0])
    return RMs
def composite_individual_self_consistency_all_metrics(trials, image_property, response_property):
    # Get response matrices
    RMs = []
    trials_hash = hashlib.sha1(str(trials)).hexdigest()
    for trial_array in trials:
        response_matrix, _, _ = CM.get_response_matrix(trial_array, image_property,
                                                 response_property, condition=None,
                                                 group_by_worker=True)
        RMs.append(response_matrix)

    # What metrics can we apply to these response matrices?

    if image_property == 'task_category' and  response_property == 'Response':
        metrics = small_cm_metrics+rm_metrics
        if min([response_matrix.shape[0] for response_matrix in RMs]) > 2:
            metrics += large_cm_metrics
    else:
        metrics = rm_metrics

    metrics_results = {}

    for metric in metrics:
        #filename = image_property+response_property+metric
        #if os.path.exists(filename):
        #    return cPickle.load(open(filename, 'rb'))
        #else:
        m, sc, me, sce = metrics_from_confusion_mat(RMs, metric)
        metrics_results[metric] = {'metric_values': m, 'self_consistency': sc,
                                   'metric_error': me, 'self_consistency_error': sce}

    return {'trials_hash': trials_hash, 'response_property': response_property, 'image_property': image_property,
            'metrics_results': metrics_results, 'consistency_type': 'composite_individual'}
Пример #4
0
def trial_split_half_RMs(trials, image_property, response_property, rng):
    if rng is None:
        rng = np.random.RandomState(0)
    inds = rng.permutation(trials.shape[0])
    half = inds.shape[0] / 2
    inds1, inds2 = inds[:half], inds[half:]
    trials1 = trials[inds1]
    trials2 = trials[inds2]
    RM1 = CM.get_response_matrix(trials1,
                                 image_property,
                                 response_property,
                                 group_by_worker=True)
    RM2 = CM.get_response_matrix(trials2,
                                 image_property,
                                 response_property,
                                 group_by_worker=True)
    return RM1, RM2
def get_rms(data,
            split_field,
            image_property,
            response_property,
            split_field_vals=None):
    RMs = []
    if split_field is None:
        RMs.append(
            cm.get_response_matrix(data,
                                   image_property,
                                   response_property,
                                   group_by_worker=True))
    else:
        if split_field_vals is None:
            split_field_vals = np.unique(data[split_field])
        for fval in split_field_vals:
            rel_data = data[data[split_field] == fval]
            RMs.append(
                cm.get_response_matrix(rel_data,
                                       image_property=image_property,
                                       response_property=response_property,
                                       group_by_worker=True)[0])
    return RMs
def composite_individual_self_consistency_all_metrics(trials, image_property,
                                                      response_property):
    # Get response matrices
    RMs = []
    trials_hash = hashlib.sha1(str(trials)).hexdigest()
    for trial_array in trials:
        response_matrix, _, _ = CM.get_response_matrix(trial_array,
                                                       image_property,
                                                       response_property,
                                                       condition=None,
                                                       group_by_worker=True)
        RMs.append(response_matrix)

    # What metrics can we apply to these response matrices?

    if image_property == 'task_category' and response_property == 'Response':
        metrics = small_cm_metrics + rm_metrics
        if min([response_matrix.shape[0] for response_matrix in RMs]) > 2:
            metrics += large_cm_metrics
    else:
        metrics = rm_metrics

    metrics_results = {}

    for metric in metrics:
        #filename = image_property+response_property+metric
        #if os.path.exists(filename):
        #    return cPickle.load(open(filename, 'rb'))
        #else:
        m, sc, me, sce = metrics_from_confusion_mat(RMs, metric)
        metrics_results[metric] = {
            'metric_values': m,
            'self_consistency': sc,
            'metric_error': me,
            'self_consistency_error': sce
        }

    return {
        'trials_hash': trials_hash,
        'response_property': response_property,
        'image_property': image_property,
        'metrics_results': metrics_results,
        'consistency_type': 'composite_individual'
    }
Пример #7
0
def test_off_diagonal():
    RM, _, _ = CM.get_response_matrix(
        CM.get_data('hvm_basic_categorization_new', 'category'),
        'task_category', 'Response')
    print u.symmetrize_confusion_matrix(RM, take='off_diagonal')
Пример #8
0
def test_off_diagonal():
    RM, _, _ = CM.get_response_matrix(CM.get_data('hvm_basic_categorization_new', 'category'),
                                     'task_category', 'Response')
    print u.symmetrize_confusion_matrix(RM, take='off_diagonal')