예제 #1
0
def get_labels(kind, exclude_subjects={}):
    labels = {}
    subjects,tests = bbdp.load(kind)
    exclude_subject_ids = []
    for key,value in exclude_subjects.items():
        exclude_subject_ids += [subject_id for subject_id,subject in subjects.items()\
                                if subject.__dict__[key]==value]
    subjects = {subject_id:subject for subject_id,subject in subjects.items()\
                if subject_id not in exclude_subject_ids}
    tests = [test for test in tests if test.subject.case_id not in exclude_subject_ids]
    n_ctrl = 0
    for test in tests:
        x = []
        if test.subject.label == 'ctrl':
            n_ctrl += 1
        if kind == 'dugger':
            x += [test.subject.label == 'pd']
        #x += [test.subject.expired_age-90]
        #x += [test.subject.gender]
        #if hasattr(test.subject,'dementia'):
        #    x += [test.subject.dementia]
        #x += [test.subject.stint]
        if hasattr(test.subject,'other'):
            x += test.subject.other
        x = [float(_) for _ in x]
        labels[test.subject] = x
    
    labels = [labels[key] for key in \
                       sorted(labels.keys(),key=lambda x:x.case_id)]
    return np.array(labels)
예제 #2
0
def get_labels(kind, exclude_subjects={}):
    labels = {}
    subjects,tests = bbdp.load(kind)
    exclude_subject_ids = []
    for key,value in exclude_subjects.items():
        exclude_subject_ids += [subject_id for subject_id,subject in subjects.items()\
                                if subject.__dict__[key]==value]
    subjects = {subject_id:subject for subject_id,subject in subjects.items()\
                if subject_id not in exclude_subject_ids}
    tests = [test for test in tests if test.subject.case_id not in exclude_subject_ids]
    n_ctrl = 0
    for test in tests:
        x = []
        if test.subject.label == 'ctrl':
            n_ctrl += 1
        if kind == 'dugger':
            x += [test.subject.label == 'pd']
        #x += [test.subject.expired_age-90]
        #x += [test.subject.gender]
        #if hasattr(test.subject,'dementia'):
        #    x += [test.subject.dementia]
        #x += [test.subject.stint]
        if hasattr(test.subject,'other'):
            x += test.subject.other
        x = [float(_) for _ in x]
        labels[test.subject] = x
    
    labels = [labels[key] for key in \
                       sorted(labels.keys(),key=lambda x:x.case_id)]
    return np.array(labels)
예제 #3
0
def get_response_matrix(kind, options=['responses'], exclude_subjects={}):
    responses = {}
    subjects,tests = bbdp.load(kind)
    exclude_subject_ids = []
    for key,value in exclude_subjects.items():
        exclude_subject_ids += [subject_id for subject_id,subject in subjects.items()\
                                if subject.__dict__[key]==value]
    subjects = {subject_id:subject for subject_id,subject in subjects.items()\
                if subject_id not in exclude_subject_ids}
    tests = [test for test in tests if test.subject.case_id not in exclude_subject_ids]
    question_nums = range(1,41)
    possible_responses = [0,1,2,3]
    for test in tests:
        x = []
        for q in question_nums:
            if 'responses' in options:
                response = []
                actual_response = test.response_set.responses[q].choice_num
                for possible_response in possible_responses:
                    if actual_response is possible_response:
                        x += [1]
                    else:
                        x += [0]    
            if 'responded' in options:
                x += [test.response_set.responses[q].choice_num is not None]
            if 'correct' in options:
                x += [int(test.response_set.responses[q].correct)]            
        if 'total_correct' in options:
            x += [sum([int(test.response_set.responses[q].correct) for q in question_nums])]
        if 'fraction_correct' in options:
            x += [sum([int(test.response_set.responses[q].correct) for q in question_nums])/40.0]
        if 'total_responded' in options:
            x += [sum([int(test.response_set.responses[q].choice_num is not None) for q in question_nums])]
        if 'gender' in options:
            x += [test.subject.gender]
        if 'demented' in options:
            try:
                x += [test.subject.demented]
            except:
                x += [test.subject.dementia]
        if 'expired_age' in options:
            x += [test.subject.expired_age]
        responses[test.subject] = x

    ctrl = []
    for key in sorted(responses.keys(),key=lambda x:x.case_id):
        ctrl += [subjects[key.case_id].label == 'ctrl']
    
    responses = np.array(list(responses[key] for key in \
                       sorted(responses.keys(),key=lambda x:x.case_id)),dtype='float')
    
    
    if 'num_each_type' in options:
        n = responses.shape[1]
        for i in range(4):
            responses = np.hstack((responses,responses[:,i:n:4].sum(axis=1).reshape(-1,1)))

    return responses,ctrl
예제 #4
0
파일: __main__.py 프로젝트: rgerkin/upsit
import ppmi
import bbdp

if __name__ == '__main__':
    """PPMI data"""
    '''
    ppmi_data = ppmi.load()
    ppmi.plot_cumul_hist(ppmi_data,booklet=1)
    ppmi.plot_cumul_hist(ppmi_data,booklet=2)
    ppmi.plot_cumul_hist(ppmi_data,booklet=3)
    ppmi.plot_cumul_hist(ppmi_data,booklet=4)
    upsit.plt.show()
    '''
    
    """BBDP data"""
    subjects,tests = bbdp.load()
    ctrl = []; pd = []
    
    scores = {}
    ctrl = []
    pd = []
    if 1:
        for q in range(1,41):
            scores[q] = {'ctrl':[],'pd':[]}
            for test in tests:
                correct = test.response_set.responses[q].correct
                if test.is_control():
                    scores[q]['ctrl'].append(correct)
                else:
                    scores[q]['pd'].append(correct)    
            def print_scores(kind):
예제 #5
0
파일: __main__.py 프로젝트: rgerkin/upsit
import upsit
import ppmi
import bbdp

if __name__ == '__main__':
    """PPMI data"""
    '''
    ppmi_data = ppmi.load()
    ppmi.plot_cumul_hist(ppmi_data,booklet=1)
    ppmi.plot_cumul_hist(ppmi_data,booklet=2)
    ppmi.plot_cumul_hist(ppmi_data,booklet=3)
    ppmi.plot_cumul_hist(ppmi_data,booklet=4)
    upsit.plt.show()
    '''
    """BBDP data"""
    subjects, tests = bbdp.load()
    ctrl = []
    pd = []

    scores = {}
    ctrl = []
    pd = []
    if 1:
        for q in range(1, 41):
            scores[q] = {'ctrl': [], 'pd': []}
            for test in tests:
                correct = test.response_set.responses[q].correct
                if test.is_control():
                    scores[q]['ctrl'].append(correct)
                else:
                    scores[q]['pd'].append(correct)