#getting output prefix prefix = prefixes[m] m += 1 #saving the feature matrix and labels in a binary file #setting output file name ofname = features_str() if prefix: ofname = prefix + '_' + ofname if scale: ofname = ofname + '.' + scaled_str() if excluf: excl_ofname = au.excluded_str() + au.feats_str() if prefix: excl_ofname = prefix + '_' + excl_ofname if scale: excl_ofname = excl_ofname + '.' + au.scaled_str() filename = get_filepath(outdir, ofname, otype) if os.path.exists(filename): print(filename + ' already exists. Jumping to the next.') else: print('Creating ' + filename) #reading mask volume if not os.path.exists(maskf): err = 'Mask file not found: ' + maskf raise IOError(err)
def save_data (outdir, prefix, dataname, otype, excluding, leave, feats, labels, exclfeats, exclulabels, dmin, dmax, scale, scale_min, scale_max, lthr, uthr, thrp, absolute): #setting output file name ofname = au.feats_str() if leave > -1: ofname += '.' + au.excluded_str() + str(leave) if absolute: ofname += '.' + au.abs_str() if lthr: ofname += '.lthr_' + str(lthr) if uthr: ofname += '.uthr_' + str(uthr) if thrp: ofname += '.thrP_' + str(thrp) if scale: ofname += '.' + au.scaled_str() if excluding: excl_ofname = au.excluded_str() + '_' + ofname exclfilename = get_filepath (outdir, excl_ofname , otype) if prefix: ofname = prefix + '_' + ofname excl_ofname = prefix + '_' + excl_ofname filename = get_filepath (outdir, ofname, otype) #writing in a text file the scaling values of this training set if scale: write_scalingrange_file (outdir + os.path.sep + ofname + '.scaling_range', dmin, dmax, scale_min, scale_max) #saving binary file depending on output type if otype == 'numpybin': np.save (filename, feats) if excluding: np.save (exclfilename, exclfeats) elif otype == 'octave': sio.savemat (filename, {au.feats_str(): feats, au.labels_str(): labels}) if excluding: exclulabels[exclulabels == 0] = -1 sio.savemat (exclfilename, {au.feats_str(): exclfeats, au.labels_str(): exclulabels}) elif otype == 'svmperf': labels[labels == 0] = -1 ae.write_svmperf_dat(filename, dataname, feats, labels) if excluding: exclulabels[exclulabels == 0] = -1 ae.write_svmperf_dat(exclfilename, dataname, exclfeats, exclulabels) elif otype == 'arff': featnames = np.arange(nfeats) + 1 ae.write_arff (filename, dataname, featnames, feats, labels) if excluding: ae.write_arff (exclfilename, dataname, featnames, exclfeats, exclulabels) else: err = 'Output method not recognised!' au.log.error(err) sys.exit(-1) return [filename, exclfilename]
fmt='%s') np.savetxt(outdir + os.path.sep + au.excluded_subjlabels_str(), exclulabels, fmt='%i') #saving the feature matrix and labels in a binary file filename = set_filename(outdir, prefix + '_' + au.features_str(), otype) print('Creating ' + filename) if otype == 'numpybin': np.save(filename, feats) elif otype == 'octave': sio.savemat(filename, {au.feats_str(): feats, au.labels_str(): labels}) elif otype == 'svmperf': labels[labels == 0] = -1 ae.write_svmperf_dat(filename, dataname, feats, labels) if excluf: exclulabels[exclulabels == 0] = -1 exclfilename = set_filename( outdir, prefix + '_' + au.excluded_str() + au.feats_str(), otype) ae.write_svmperf_dat(exclfilename, dataname, exclfeats, exclulabels) elif otype == 'arff': featnames = np.arange(nfeats) + 1 ae.write_arff(filename, dataname, featnames, feats, labels)
# getting output prefix prefix = prefixes[m] m += 1 # saving the feature matrix and labels in a binary file # setting output file name ofname = features_str() if prefix: ofname = prefix + "_" + ofname if scale: ofname = ofname + "." + scaled_str() if excluf: excl_ofname = au.excluded_str() + au.feats_str() if prefix: excl_ofname = prefix + "_" + excl_ofname if scale: excl_ofname = excl_ofname + "." + au.scaled_str() filename = get_filepath(outdir, ofname, otype) if os.path.exists(filename): print(filename + " already exists. Jumping to the next.") else: print("Creating " + filename) # reading mask volume if not os.path.exists(maskf): err = "Mask file not found: " + maskf raise IOError(err)
if excluf: np.savetxt(outdir + os.path.sep + au.excluded_subjects_str(), exclusubjs, fmt='%s') np.savetxt(outdir + os.path.sep + au.excluded_subjlabels_str(), exclulabels, fmt='%i') #saving the feature matrix and labels in a binary file filename = set_filename (outdir, prefix + '_' + au.features_str(), otype) print ('Creating ' + filename) if otype == 'numpybin': np.save (filename, feats) elif otype == 'octave': sio.savemat (filename, {au.feats_str(): feats, au.labels_str(): labels}) elif otype == 'svmperf': labels[labels == 0] = -1 ae.write_svmperf_dat(filename, dataname, feats, labels) if excluf: exclulabels[exclulabels == 0] = -1 exclfilename = set_filename(outdir, prefix + '_' + au.excluded_str() + au.feats_str(), otype) ae.write_svmperf_dat(exclfilename, dataname, exclfeats, exclulabels) elif otype == 'arff': featnames = np.arange(nfeats) + 1 ae.write_arff (filename, dataname, featnames, feats, labels) else: err = 'Output method not recognised!'