示例#1
0
def measure_ttest_fsl (mean1fname, mean2fname,\
                       var1fname, var2fname,  \
                       std1fname, std2fname,  \
                       numsubjs1, numsubjs2,  \
                       experimentname, outdir, exclude_idx=-1):

   if not os.path.exists (outdir):
      os.mkdir (outdir)

   olddir = os.getcwd()
   os.chdir (outdir)

   #following the equation:
   #t = (m1 - m2) / sqrt( (v1^2)/N1 + (v2^2)/N2 )
   #from:
   #http://en.wikipedia.org/wiki/Student%27s_t-test#Unequal_sample_sizes.2C_unequal_variance
   num1fname = outdir   + os.path.sep + experimentname + '_ttest_num1'
   den1fname = outdir   + os.path.sep + experimentname + '_ttest_den1'
   den2fname = outdir   + os.path.sep + experimentname + '_ttest_den2'
   denfname  = outdir   + os.path.sep + experimentname + '_ttest_denom'
   ttstfname = outdir   + os.path.sep + experimentname + '_ttest'

   au.fslmaths (mean1fname + ' -sub '       + mean2fname     + ' '       + num1fname)
   au.fslmaths (var1fname  + ' -sqr -div '  + str(numsubjs1) + ' '       + den1fname)
   au.fslmaths (var2fname  + ' -sqr -div '  + str(numsubjs2) + ' '       + den2fname)
   au.fslmaths (den1fname  + ' -add '       + den2fname      + ' -sqrt ' + denfname )
   au.fslmaths (num1fname  + ' -div '       + denfname       + ' '       + ttstfname)

#   imrm (num1fname)
#   imrm (den1fname)
#   imrm (den2fname)
#   imrm (denfname)

   os.chdir(olddir)

   return ttstfname
def measure_bhattacharyya_distance_fsl (mean1fname, mean2fname, \
                                        var1fname, var2fname,  \
                                        std1fname, std2fname,  \
                                        numsubjs1, numsubjs2,  \
                                        experimentname, outdir, exclude_idx=-1):

    if not os.path.exists(outdir):
        os.mkdir(outdir)

    olddir = os.getcwd()
    os.chdir(outdir)

    #following the equations:
    #1/4 * ((m1-m2)^2/(var1+var2)) + 1/2 * (log( (var1+var2)/(2*std1*std2) ))
    #from:
    #1
    #Bhattacharyya clustering with applications to mixture simplifications
    #Frank Nielsen, Sylvain Boltz, and Olivier Schwander
    #2010 International Conference on Pattern Recognition
    #2
    #The Divergence and Bhattacharyya Distance Measures in Signal Selection
    #Kailath, T.
    #http://dx.doi.org/10.1109/TCOM.1967.1089532
    num1fname = outdir + os.path.sep + experimentname + '_bhatta_num1'
    den1fname = outdir + os.path.sep + experimentname + '_bhatta_denom1'
    bhatta1 = outdir + os.path.sep + experimentname + '_bhatta_first'
    au.fslmaths(mean1fname + ' -sub ' + mean2fname + ' -sqr ' + num1fname)
    au.fslmaths(var1fname + ' -add ' + var2fname + ' ' + den1fname)
    au.fslmaths(num1fname + ' -div ' + den1fname + ' -div 4 ' + bhatta1)

    num2fname = outdir + os.path.sep + experimentname + '_bhatta_num2'
    au.fslmaths(var1fname + ' -add ' + var2fname + ' ' + num2fname)

    den2fname = outdir + os.path.sep + experimentname + '_bhatta_denom2'
    bhatta2 = outdir + os.path.sep + experimentname + '_bhatta_secnd'
    au.fslmaths(std1fname + ' -mul ' + std2fname + ' -mul 2 ' + den2fname)
    au.fslmaths(num2fname + ' -div ' + den2fname + ' -log -div 2 ' + bhatta2)

    bhatta = outdir + os.path.sep + experimentname + '_' + au.bhattacharyya_str(
    )

    au.fslmaths(bhatta1 + ' -add ' + bhatta2 + ' ' + bhatta)

    #   au.imrm (num1fname)
    #   au.imrm (den1fname)
    #   au.imrm (bhatta1)
    #   au.imrm (num2fname)
    #   au.imrm (den2fname)
    #   au.imrm (bhatta2)

    os.chdir(olddir)

    return bhatta
def measure_bhattacharyya_distance_fsl (mean1fname, mean2fname, \
                                        var1fname, var2fname,  \
                                        std1fname, std2fname,  \
                                        numsubjs1, numsubjs2,  \
                                        experimentname, outdir, exclude_idx=-1):

   if not os.path.exists (outdir):
      os.mkdir (outdir)

   olddir = os.getcwd()
   os.chdir (outdir)

   #following the equations:
   #1/4 * ((m1-m2)^2/(var1+var2)) + 1/2 * (log( (var1+var2)/(2*std1*std2) ))
   #from:
   #1
      #Bhattacharyya clustering with applications to mixture simplifications
      #Frank Nielsen, Sylvain Boltz, and Olivier Schwander
      #2010 International Conference on Pattern Recognition
   #2
      #The Divergence and Bhattacharyya Distance Measures in Signal Selection
      #Kailath, T.
      #http://dx.doi.org/10.1109/TCOM.1967.1089532
   num1fname = outdir   + os.path.sep + experimentname + '_bhatta_num1'
   den1fname = outdir   + os.path.sep + experimentname + '_bhatta_denom1'
   bhatta1   = outdir   + os.path.sep + experimentname + '_bhatta_first'
   au.fslmaths (mean1fname + ' -sub '    + mean2fname + ' -sqr '   + num1fname)
   au.fslmaths (var1fname  + ' -add '    + var2fname  + ' '        + den1fname)
   au.fslmaths (num1fname  + ' -div '    + den1fname  + ' -div 4 ' + bhatta1)

   num2fname = outdir  + os.path.sep + experimentname + '_bhatta_num2'
   au.fslmaths (var1fname + ' -add '    + var2fname + ' ' + num2fname)

   den2fname = outdir + os.path.sep + experimentname + '_bhatta_denom2'
   bhatta2   = outdir + os.path.sep + experimentname + '_bhatta_secnd'
   au.fslmaths (std1fname + ' -mul ' + std2fname + ' -mul 2 ' + den2fname)
   au.fslmaths (num2fname + ' -div ' + den2fname + ' -log -div 2 ' + bhatta2)

   bhatta = outdir + os.path.sep + experimentname + '_' + au.bhattacharyya_str()

   au.fslmaths (bhatta1 + ' -add ' + bhatta2 + ' ' + bhatta)

#   au.imrm (num1fname)
#   au.imrm (den1fname)
#   au.imrm (bhatta1)
#   au.imrm (num2fname)
#   au.imrm (den2fname)
#   au.imrm (bhatta2)

   os.chdir(olddir)

   return bhatta