algorithm/surf_tools.py
def nfold_magnitude(roidata, magdata, index = 'mean', thr_meth = 'prob', prob_meth = 'part', thr_range = [0,1,0.1], n_fold = 2, n_permutation = 1):
    """
    Using cross validation method to split data into nfold
    compute probabilistic map by first part of data, then extract signals of rest part of data using probabilistic map 

    Parameters:
    ------------
    roidata: roidata used for probabilistic map
    magdata: magnitude data
    index: 'mean', 'std', 'ste', 'vertex', etc.
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    prob_meth: 'all' or 'part'. Subjects to use compute probabilistic map
    thr_range: pre-set threshold range to compute thresholded labeled map
    n_fold: split numbers for cross validation
    n_permutation: permutation times

    Returns:
    --------
    mag_signals: magnitude signals

    Examples:
    ---------
    >>> mag_signals = nfold_magnitude(roidata, magdata)
    """
    roidata = roidata.reshape(roidata.shape[0], roidata.shape[-1])
    magdata = magdata.reshape(magdata.shape[0], magdata.shape[-1])
    assert magdata.shape == roidata.shape, "roidata should have same shape as magdata"
    n_subj = roidata.shape[-1]
    output_overlap = []
    for n in range(n_permutation):
        print('permutation {} starts'.format(n+1))
        test_subj = np.sort(np.random.choice(n_subj, n_subj-n_subj/n_fold, replace = False)).tolist()
        verify_subj = [val for val in range(n_subj) if val not in test_subj]
        test_roidata = roidata[:, test_subj]
        verify_magdata = magdata[:, verify_subj]
        pm = make_pm(test_roidata, prob_meth)
        pm_temp = cv_pm_magnitude(pm, verify_magdata, index = index, thr_meth = thr_meth, thr_range = thr_range)
        output_overlap.append(pm_temp)
    output_array = np.array(output_overlap)
    return output_array

    Using cross validation method to split data into nfold
    compute probabilistic map by first part of data, then extract signals of rest part of data using probabilistic map 

    Parameters:
    ------------
    roidata: roidata used for probabilistic map
    magdata: magnitude data
    index: 'mean', 'std', 'ste', 'vertex', etc.
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    prob_meth: 'all' or 'part'. Subjects to use compute probabilistic map
    thr_range: pre-set threshold range to compute thresholded labeled map
    n_fold: split numbers for cross validation
    n_permutation: permutation times

    Returns:
    --------
    mag_signals: magnitude signals

    Examples:
    ---------
    >>> mag_signals = nfold_magnitude(roidata, magdata)
    
Using cross validation method to split data into nfold
compute probabilistic map by first part of data, then extract signals of rest part of data using probabilistic map







magnitude signals




Using cross validation method to split data into nfold compute probabilistic map by first part of data then extract signals of rest part of data using probabilistic map magnitude signals
def nfold_magnitude(roidata, magdata, index = 'mean', thr_meth = 'prob', prob_meth = 'part', thr_range = [0,1,0.1], n_fold = 2, n_permutation = 1):
    roidata = roidata.reshape(roidata.shape[0], roidata.shape[-1])
    magdata = magdata.reshape(magdata.shape[0], magdata.shape[-1])
    assert magdata.shape == roidata.shape, "roidata should have same shape as magdata"
    n_subj = roidata.shape[-1]
    output_overlap = []
    for n in range(n_permutation):
        print('permutation {} starts'.format(n+1))
        test_subj = np.sort(np.random.choice(n_subj, n_subj-n_subj/n_fold, replace = False)).tolist()
        verify_subj = [val for val in range(n_subj) if val not in test_subj]
        test_roidata = roidata[:, test_subj]
        verify_magdata = magdata[:, verify_subj]
        pm = make_pm(test_roidata, prob_meth)
        pm_temp = cv_pm_magnitude(pm, verify_magdata, index = index, thr_meth = thr_meth, thr_range = thr_range)
        output_overlap.append(pm_temp)
    output_array = np.array(output_overlap)
    return output_array
def nfold_magnitude ( roidata , magdata , index = 'mean' , thr_meth = 'prob' , prob_meth = 'part' , thr_range = [ 0 , 1 , 0.1 ] , n_fold = 2 , n_permutation = 1 ) : roidata = roidata . reshape ( roidata . shape [ 0 ] , roidata . shape [ - 1 ] ) magdata = magdata . reshape ( magdata . shape [ 0 ] , magdata . shape [ - 1 ] ) assert magdata . shape == roidata . shape , "roidata should have same shape as magdata" n_subj = roidata . shape [ - 1 ] output_overlap = [ ] for n in range ( n_permutation ) : print ( 'permutation {} starts' . format ( n + 1 ) ) test_subj = np . sort ( np . random . choice ( n_subj , n_subj - n_subj / n_fold , replace = False ) ) . tolist ( ) verify_subj = [ val for val in range ( n_subj ) if val not in test_subj ] test_roidata = roidata [ : , test_subj ] verify_magdata = magdata [ : , verify_subj ] pm = make_pm ( test_roidata , prob_meth ) pm_temp = cv_pm_magnitude ( pm , verify_magdata , index = index , thr_meth = thr_meth , thr_range = thr_range ) output_overlap . append ( pm_temp ) output_array = np . array ( output_overlap ) return output_array
Using cross validation method to split data into nfold
compute probabilistic map by first part of data, then extract signals of rest part of data using probabilistic map
Using cross validation method to split data into nfold compute probabilistic map by first part of data then extract signals of rest part of data using probabilistic map
"""
    Using cross validation method to split data into nfold
    compute probabilistic map by first part of data, then extract signals of rest part of data using probabilistic map 

    Parameters:
    ------------
    roidata: roidata used for probabilistic map
    magdata: magnitude data
    index: 'mean', 'std', 'ste', 'vertex', etc.
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    prob_meth: 'all' or 'part'. Subjects to use compute probabilistic map
    thr_range: pre-set threshold range to compute thresholded labeled map
    n_fold: split numbers for cross validation
    n_permutation: permutation times

    Returns:
    --------
    mag_signals: magnitude signals

    Examples:
    ---------
    >>> mag_signals = nfold_magnitude(roidata, magdata)
    """
roidata
magdata
index
thr_meth
prob_meth
thr_range
n_fold
n_permutation