Пример #1
0
def pre_featsel (X, y, method, thr=95):

    #pre feature selection, measuring distances
    #Pearson correlation
    if method == 'pearson':
        au.log.info ('Calculating Pearson correlation')
        m = np.abs(pearson_correlation (X, y))

    #Bhattacharyya distance
    elif method == 'bhattacharyya':
        au.log.info ('Calculating Bhattacharyya distance')
        m = bhattacharyya_dist (X, y)

    #Welch's t-test
    elif method == 'welcht':
        au.log.info ("Calculating Welch's t-test")
        m = welch_ttest (X, y)

    #threshold data
    if method != 'none':
        mt = au.threshold_robust_range (m, thr)

    return mt
Пример #2
0
def pre_featsel (X, y, method, thr=95):

    #pre feature selection, measuring distances
    #Pearson correlation
    if method == 'pearson':
        au.log.info ('Calculating Pearson correlation')
        m = np.abs(pearson_correlation (X, y))

    #Bhattacharyya distance
    elif method == 'bhattacharyya':
        au.log.info ('Calculating Bhattacharyya distance')
        m = bhattacharyya_dist (X, y)

    #Welch's t-test
    elif method == 'welcht':
        au.log.info ("Calculating Welch's t-test")
        m = welch_ttest (X, y)

    #threshold data
    if method != 'none':
        mt = au.threshold_robust_range (m, thr)

    return mt
Пример #3
0
    #mask process
    au.log.info('Processing ' + maskf)

    #loading mask and masking it with globalmask
    mask   = nib.load(maskf).get_data()

    #thresholding
    if absolute:  mask = np.abs(mask)
    if lthr:      mask[mask < lthr] = 0
    if uthr:      mask[mask > uthr] = 0

    if thrps:
        for t in thrps:
            au.log.info ("Thresholding " + maskf + " with robust range below " + str(t) + " percent.")
            thrm = au.threshold_robust_range (mask, t)

            au.log.info ("Extracting features.")
            [feats, exclfeats, dmin, dmax] = extract_features (subjs, exclusubjs, thrm, maskf, scale, scale_min, scale_max)

            au.log.info ("Saving data files.")
            [filename, exclfilename] = save_data (outdir, prefix, dataname, otype, excluding, leave, feats, labels, exclfeats, exclulabels, dmin, dmax, scale, scale_min, scale_max, lthr, uthr, t, absolute)

    else:
        au.log.info ("Extracting features.")
        [feats, exclfeats, dmin, dmax] = extract_features (subjs, exclusubjs, mask, maskf, scale, scale_min, scale_max)

        au.log.info ("Saving data files.")
        [filename, exclfilename] = save_data (outdir, prefix, dataname, otype, excluding, leave, feats, labels, exclfeats, exclulabels, dmin, dmax, scale, scale_min, scale_max, lthr, uthr, thrps, absolute)

    au.log.info ("Saved " + filename)
   au.setup_logger(args.verbosity)

   mask = nib.load(maskf).get_data()

   for i in ilst:
      im    = nib.load(i)
      ivol  = im.get_data()
      ifnom = au.remove_ext(os.path.basename(imf))

      if mask.shape != ivol.shape:
         au.log.error ("Mask file " + maskf + " and input " + i + " do not have the same shape. Skipping...")
         continue

      for t in threshs:
         au.log.info ("Thresholding " + i + " with " + str(t) + " robust lower bound.")
         out = au.threshold_robust_range (ivol, t)

         if odir:
            of = odir
         else:
            of = os.path.dirname(i)

         of += os.path.sep + ifnom + "_" + str(t) + "thrP" + ext

         om = nib.Nifti1Image(out, im.get_affine(), im.get_header(), im.extra, im.file_map)
         om.to_filename(of)

#-------------------------------------------------------------------------------
## END ROBUST THRESHOLDS
#-------------------------------------------------------------------------------