algorithm/surf_tools.py
def cv_pm_overlap(pm, test_data, labels_template, labels_testdata, index = 'dice', thr_meth = 'prob', thr_range = [0, 1, 0.1], cmpalllbl = True, controlsize = False, actdata = None):
    """
    Compute overlap(dice) between probabilistic map and test data
    
    Parameters:
    -----------
    pm: probabilistic map
    test_data: subject specific label data used as test data
    labels_template: list, label number of template (pm) used to extract overlap values 
    label_testdata: list, label number of test data used to extract overlap values
    index: 'dice' or 'percent'
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    thr_range: pre-set threshold range to find the best maximum probabilistic threshold
    cmpalllbl: compute all overlap label one to one or not.
               e.g. labels_template = [2,4], labels_testdata = [2,4]
                    if True, get dice coefficient of (2,2), (2,4), (4,2), (4,4)
                    else, get dice coefficient of (2,2), (4,4)
    controlsize: whether control label data size with template mpm label size or not, by default is False.
    actdata: if controlsize is True, please input actdata as a parameter. By default is None.

    Return:
    -------
    output_overlap: dice coefficient/percentage
                    outputdice consists of a 3 dimension array
                    subjects x thr_range x regions
                    the first dimension means the values of each leave one out (leave one subject out)
                    the second dimension means the results of pre-set threshold
                    the third dimension means the results of each region
                 
    Example:
    --------
    >>> output_overlap = cv_pm_overlap(pm, test_data, [2,4], [2,4])
    """
    if cmpalllbl is False:
        assert len(labels_template) == len(labels_testdata), "Notice that labels_template should have same length of labels_testdata if cmpalllbl is False"
    if test_data.ndim == 4:
        test_data = test_data.reshape(test_data.shape[0], test_data.shape[-1])
    if actdata is not None:
        if actdata.ndim == 4:
            actdata = actdata.reshape(actdata.shape[0], actdata.shape[-1])
    output_overlap = []
    for i in range(test_data.shape[-1]):
        thrmp_temp = []
        if actdata is not None:
            verify_actdata = actdata[:,i]
        else:
            verify_actdata = None
        for j,e in enumerate(np.arange(thr_range[0], thr_range[1], thr_range[2])):
            print("threshold {} is verifing".format(e))
            if thr_meth == 'prob':    
                thrmp = make_mpm(pm, e)
            elif thr_meth == 'number':
                if pm.shape[-1] > 1:
                    raise Exception('only support 1 label for this situation')
                thrmp = tools.threshold_by_number(pm, e)
                thrmp[thrmp!=0] = 1
            if cmpalllbl is True:
                thrmp_temp.append([tools.calc_overlap(thrmp.flatten(), test_data[:,i], lbltmp, lbltst, index, controlsize = controlsize, actdata = verify_actdata) for lbltmp in labels_template for lbltst in labels_testdata])
            else:
                thrmp_temp.append([tools.calc_overlap(thrmp.flatten(), test_data[:,i], labels_template[idx], lbld, index, controlsize = controlsize, actdata = verify_actdata) for idx, lbld in enumerate(labels_testdata)])
        output_overlap.append(thrmp_temp)
    return np.array(output_overlap)

    Compute overlap(dice) between probabilistic map and test data
    
    Parameters:
    -----------
    pm: probabilistic map
    test_data: subject specific label data used as test data
    labels_template: list, label number of template (pm) used to extract overlap values 
    label_testdata: list, label number of test data used to extract overlap values
    index: 'dice' or 'percent'
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    thr_range: pre-set threshold range to find the best maximum probabilistic threshold
    cmpalllbl: compute all overlap label one to one or not.
               e.g. labels_template = [2,4], labels_testdata = [2,4]
                    if True, get dice coefficient of (2,2), (2,4), (4,2), (4,4)
                    else, get dice coefficient of (2,2), (4,4)
    controlsize: whether control label data size with template mpm label size or not, by default is False.
    actdata: if controlsize is True, please input actdata as a parameter. By default is None.

    Return:
    -------
    output_overlap: dice coefficient/percentage
                    outputdice consists of a 3 dimension array
                    subjects x thr_range x regions
                    the first dimension means the values of each leave one out (leave one subject out)
                    the second dimension means the results of pre-set threshold
                    the third dimension means the results of each region
                 
    Example:
    --------
    >>> output_overlap = cv_pm_overlap(pm, test_data, [2,4], [2,4])
    
Compute overlap(dice) between probabilistic map and test data
Parameters.





dice coefficient/percentage
outputdice consists of a 3 dimension array
subjects x thr_range x regions
the first dimension means the values of each leave one out (leave one subject out)
the second dimension means the results of pre-set threshold
the third dimension means the results of each region




Compute overlap ( dice ) between probabilistic map and test data Parameters . dice coefficient / percentage outputdice consists of a 3 dimension array subjects x thr_range x regions the first dimension means the values of each leave one out ( leave one subject out ) the second dimension means the results of pre - set threshold the third dimension means the results of each region
def cv_pm_overlap(pm, test_data, labels_template, labels_testdata, index = 'dice', thr_meth = 'prob', thr_range = [0, 1, 0.1], cmpalllbl = True, controlsize = False, actdata = None):
    if cmpalllbl is False:
        assert len(labels_template) == len(labels_testdata), "Notice that labels_template should have same length of labels_testdata if cmpalllbl is False"
    if test_data.ndim == 4:
        test_data = test_data.reshape(test_data.shape[0], test_data.shape[-1])
    if actdata is not None:
        if actdata.ndim == 4:
            actdata = actdata.reshape(actdata.shape[0], actdata.shape[-1])
    output_overlap = []
    for i in range(test_data.shape[-1]):
        thrmp_temp = []
        if actdata is not None:
            verify_actdata = actdata[:,i]
        else:
            verify_actdata = None
        for j,e in enumerate(np.arange(thr_range[0], thr_range[1], thr_range[2])):
            print("threshold {} is verifing".format(e))
            if thr_meth == 'prob':    
                thrmp = make_mpm(pm, e)
            elif thr_meth == 'number':
                if pm.shape[-1] > 1:
                    raise Exception('only support 1 label for this situation')
                thrmp = tools.threshold_by_number(pm, e)
                thrmp[thrmp!=0] = 1
            if cmpalllbl is True:
                thrmp_temp.append([tools.calc_overlap(thrmp.flatten(), test_data[:,i], lbltmp, lbltst, index, controlsize = controlsize, actdata = verify_actdata) for lbltmp in labels_template for lbltst in labels_testdata])
            else:
                thrmp_temp.append([tools.calc_overlap(thrmp.flatten(), test_data[:,i], labels_template[idx], lbld, index, controlsize = controlsize, actdata = verify_actdata) for idx, lbld in enumerate(labels_testdata)])
        output_overlap.append(thrmp_temp)
    return np.array(output_overlap)
def cv_pm_overlap ( pm , test_data , labels_template , labels_testdata , index = 'dice' , thr_meth = 'prob' , thr_range = [ 0 , 1 , 0.1 ] , cmpalllbl = True , controlsize = False , actdata = None ) : if cmpalllbl is False : assert len ( labels_template ) == len ( labels_testdata ) , "Notice that labels_template should have same length of labels_testdata if cmpalllbl is False" if test_data . ndim == 4 : test_data = test_data . reshape ( test_data . shape [ 0 ] , test_data . shape [ - 1 ] ) if actdata is not None : if actdata . ndim == 4 : actdata = actdata . reshape ( actdata . shape [ 0 ] , actdata . shape [ - 1 ] ) output_overlap = [ ] for i in range ( test_data . shape [ - 1 ] ) : thrmp_temp = [ ] if actdata is not None : verify_actdata = actdata [ : , i ] else : verify_actdata = None for j , e in enumerate ( np . arange ( thr_range [ 0 ] , thr_range [ 1 ] , thr_range [ 2 ] ) ) : print ( "threshold {} is verifing" . format ( e ) ) if thr_meth == 'prob' : thrmp = make_mpm ( pm , e ) elif thr_meth == 'number' : if pm . shape [ - 1 ] > 1 : raise Exception ( 'only support 1 label for this situation' ) thrmp = tools . threshold_by_number ( pm , e ) thrmp [ thrmp != 0 ] = 1 if cmpalllbl is True : thrmp_temp . append ( [ tools . calc_overlap ( thrmp . flatten ( ) , test_data [ : , i ] , lbltmp , lbltst , index , controlsize = controlsize , actdata = verify_actdata ) for lbltmp in labels_template for lbltst in labels_testdata ] ) else : thrmp_temp . append ( [ tools . calc_overlap ( thrmp . flatten ( ) , test_data [ : , i ] , labels_template [ idx ] , lbld , index , controlsize = controlsize , actdata = verify_actdata ) for idx , lbld in enumerate ( labels_testdata ) ] ) output_overlap . append ( thrmp_temp ) return np . array ( output_overlap )
Compute overlap(dice) between probabilistic map and test data
Parameters:
Compute overlap ( dice ) between probabilistic map and test data Parameters :
"""
    Compute overlap(dice) between probabilistic map and test data
    
    Parameters:
    -----------
    pm: probabilistic map
    test_data: subject specific label data used as test data
    labels_template: list, label number of template (pm) used to extract overlap values 
    label_testdata: list, label number of test data used to extract overlap values
    index: 'dice' or 'percent'
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    thr_range: pre-set threshold range to find the best maximum probabilistic threshold
    cmpalllbl: compute all overlap label one to one or not.
               e.g. labels_template = [2,4], labels_testdata = [2,4]
                    if True, get dice coefficient of (2,2), (2,4), (4,2), (4,4)
                    else, get dice coefficient of (2,2), (4,4)
    controlsize: whether control label data size with template mpm label size or not, by default is False.
    actdata: if controlsize is True, please input actdata as a parameter. By default is None.

    Return:
    -------
    output_overlap: dice coefficient/percentage
                    outputdice consists of a 3 dimension array
                    subjects x thr_range x regions
                    the first dimension means the values of each leave one out (leave one subject out)
                    the second dimension means the results of pre-set threshold
                    the third dimension means the results of each region
                 
    Example:
    --------
    >>> output_overlap = cv_pm_overlap(pm, test_data, [2,4], [2,4])
    """
pm
test_data
labels_template
labels_testdata
index
thr_meth
thr_range
cmpalllbl
controlsize
actdata