def do_matlab_svm_bdopt (temporal_filtering=True, global_nuis_correction=True): wd, xd, dd, labelsf, phenof, dataf, masks, dilmasks, templates, pipe = get_filepaths(temporal_filtering, global_nuis_correction) au.setup_logger(2, logfname=None) for fi in range(len(dataf)): myfile = au.remove_ext(subjsf) + '.mat'
au.log.error(exc.message + '\n' + exc.argument) parser.error(str(msg)) return 0 outdir = args.outdir.strip() svmdir = args.svmdir.strip() expname = args.expname.strip() featsf = args.feats.strip() testf = args.testf.strip() cvalue = args.cvalue lossf = args.lossf svmargs = args.svmargs.strip() redoing = args.redoing verbose = args.verbosity au.setup_logger(verbose) #setting command paths svm_class = 'svm_perf_classify' svm_learn = 'svm_perf_learn' if svmdir: svm_class = svmdir + os.path.sep + svm_class svm_learn = svmdir + os.path.sep + svm_learn train_fname = featsf test_fname = testf #creating output filename if expname: ofname = os.path.basename(expname) else:
return -1 labelsf = args.labelsf.strip() dataf = args.dataf.strip() outdir = args.outdir.strip() clfmethod = args.estimator.strip() fsname = args.fsmethod.strip() prefsmethod = args.prefsmethod.strip() prefsthr = args.prefsthr cvfold = args.cvfold.strip() n_folds = args.nfolds n_cpus = args.ncpus verbose = args.verbosity au.setup_logger(verbose, logfname=None) scale = True #label values n_class = 2 #labels y = np.loadtxt(labelsf).astype(int) n_subjs = len(y) #data data = np.load(dataf) n_feats = data.shape[1] if n_subjs != data.shape[0]:
except argparse.ArgumentError, exc: print(exc.message + '\n' + exc.argument) parser.error(str(msg)) return -1 subjlstf = args.subjlstf.strip() datadir = args.datadir.strip() feats = args.feats.strip() outdir = args.outdir.strip() clfmethod = args.estimator.strip() fsname = args.fsmethod.strip() cvfold = args.cvfold.strip() n_cpus = args.ncpus verbose = args.verbosity au.setup_logger(verbose, logfname=None) scale = True #label values n_class = 2 #labels y, subjs = parse_subjects_list(subjlstf) scores = np.array(y) y = np.array(y) y[scores > 0] = 1 y = y.astype(int) n_subjs = len(subjs)
maskf = args.mask.strip() prefix = args.prefix.strip() leave = args.leave scale = args.scale scale_min = args.scale_min scale_max = args.scale_max thrps = args.thresholdP.strip().split() lthr = args.lthreshold.strip() uthr = args.uthreshold.strip() absolute = args.absolute au.setup_logger(args.verbosity) #checking number of files processed if not os.path.exists(maskf): err = 'Mask file not found: ' + maskf au.log.error(err) sys.exit(-1) #number of subjects subjsnum = au.file_len(subjsf) #reading subjects list subjlabels = np.zeros(subjsnum, dtype=int) subjslist = {} subjfile = open(subjsf, 'r') c = 0
from sklearn.lda import LDA from sklearn.grid_search import GridSearchCV from sklearn.cross_validation import LeaveOneOut, StratifiedKFold from sklearn.feature_selection import RFECV from sklearn.pipeline import Pipeline, FeatureUnion from IPython.core.debugger import Tracer debug_here = Tracer() sys.path.append("/home/alexandre/Dropbox/Documents/phd/work/aizkolari") import aizkolari_utils as au """ import os import sys sys.path.append('/home/alexandre/Dropbox/Documents/phd/work/aizkolari') import aizkolari_utils as au sys.path.append('/home/alexandre/Dropbox/Documents/phd/work/oasis_aal') from do_aal_featsets import * hn = au.get_hostname() if hn == 'azteca': wd = '/media/data/oasis_aal' roisdir = '' outd = '/media/data/oasis_aal' elif hn == 'corsair':
#!/usr/bin/python from IPython.core.debugger import Tracer debug_here = Tracer() import os, subprocess, re, sys import numpy as np import pickle sys.path.append('/home/alexandre/Dropbox/Documents/phd/work/aizkolari') import aizkolari_utils as au au.setup_logger(verbosity=2) measures = ['jacs', 'modulatedgm', 'norms', 'trace', 'geodan'] dists = ['pearson', 'bhattacharyya', 'ttest'] study1 = [ '0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009', '0010' ] #studies = {'cv':study1, 'dd':study2} thrs = [80, 90, 95, 99, 99.5, 99.9, 100] perfmeas = [ 'Accuracy', 'Precision', 'Recall', 'F1', 'PRBEP', 'ROCArea', 'AvgPrec', 'Specificity', 'Brier-score' ]
def do_darya_localizations (): import scipy.io as sio sys.path.append('/home/alexandre/Dropbox/Documents/work/visualize_volume') import visualize_volume as vis import aizkolari_utils as au au.setup_logger() locd = '/home/alexandre/Dropbox/ELM 2013/ELM-2013-Darya/localization' wd, xd, dd, labelsf, phenof, dataf, masks, dilmasks, templates, pipe = get_filepaths() maskf = dilmasks[0] mask, hdr, aff = au.get_nii_data(maskf) indices = np.array(np.where(mask > 0)) tmpltf = templates[0] tmplt, _, _ = au.get_nii_data(tmpltf) flist = os.listdir(locd) flist = au.find(flist, '.mat') flist.sort() for f in flist: data = sio.loadmat(os.path.join(locd, f)) name = au.remove_ext(f) if f.find('cobre') >= 0: p = data['pearson'].squeeze() locs = p > 0 lidx = indices[:, locs].squeeze() if f.find('reho') >= 0: preho = p.copy() elif f.find('alff') >= 0: palff = p.copy() else: locs = data[name].squeeze() locs -= 1 if f.find('pearson') >= 0: if f.find('reho') >= 0: lidx = indices[:, preho > 0] elif f.find('alff') >= 0: lidx = indices[:, palff > 0] lidx = lidx[:, locs] else: lidx = indices[:, locs].squeeze() locvol = np.zeros_like(mask, dtype=np.float) locvol[tuple(lidx)] = 1 #save nifti volume au.save_nibabel (os.path.join(locd, name + '.nii.gz'), locvol, aff, hdr) #save image fig = vis.show_many_slices(tmplt, locvol, volaxis=1, vol2_colormap=plt.cm.autumn, figtitle=name) aizc.save_fig_to_png(fig, os.path.join(locd, name + '.png')) if os.access (os.path.join(xd,'innercrop'), os.X_OK): au.exec_command (os.path.join(xd,'innercrop') + ' -o white ' + fig2name + ' ' + fig2name)
#!/usr/bin/python from IPython.core.debugger import Tracer debug_here = Tracer() import os, subprocess, re, sys import numpy as np import pickle sys.path.append("/home/alexandre/Dropbox/Documents/phd/work/aizkolari") import aizkolari_utils as au au.setup_logger(verbosity=2) measures = ["jacs", "modulatedgm", "norms", "trace", "geodan"] dists = ["pearson", "bhattacharyya", "ttest"] study1 = ["0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008", "0009", "0010"] # studies = {'cv':study1, 'dd':study2} thrs = [80, 90, 95, 99, 99.5, 99.9, 100] perfmeas = ["Accuracy", "Precision", "Recall", "F1", "PRBEP", "ROCArea", "AvgPrec", "Specificity", "Brier-score"] cgrid = [10 ** -3, 10 ** -2, 10 ** -1, 10 ** 0, 10 ** 1, 10 ** 2] scaled = True # kernel kernels = ["linear", "rbf"]
def do_oasis_visualize_pca(args): subjsf = args.infile.strip() outfile = args.outfile.strip() datadir = args.datadir.strip() maskf = args.mask.strip() fsmethod = args.fsmethod.strip() # scale = args.scale # scale_min = args.scale_min # scale_max = args.scale_max verbose = args.verbosity # logging config au.setup_logger(verbose) # loading mask msk = nib.load(maskf).get_data() nvox = np.sum(msk > 0) indices = np.where(msk > 0) # reading subjects list [scores, subjs] = parse_subjects_list(subjsf, datadir) scores = np.array(scores) imgsiz = nib.load(subjs[0]).shape nsubjs = len(subjs) # checking mask and first subject dimensions match if imgsiz != msk.shape: au.log.error("Subject image and mask dimensions should coincide.") exit(1) # relabeling scores to integers, if needed if not np.all(scores.astype(np.int) == scores): unis = np.unique(scores) scs = np.zeros(scores.shape, dtype=int) for k in np.arange(len(unis)): scs[scores == unis[k]] = k y = scs.copy() else: y = scores.copy() # loading data au.log.info("Loading data...") X = np.zeros((nsubjs, nvox), dtype="float32") for f in np.arange(nsubjs): imf = subjs[f] au.log.info("Reading " + imf) img = nib.load(imf).get_data() X[f, :] = img[msk > 0] # demo """ from sklearn.datasets import fetch_mldata mnist = fetch_mldata("MNIST original") X, y = mnist.data[:60000] / 255., mnist.target[:60000] X, y = shuffle(X, y) X, y = X[:5000], y[:5000] # lets subsample a bit for a first impression """ # lets start plotting au.log.info("Preparing plots...") X, y = shuffle(X, y) X = X / X.max() # reducing training and test data if fsmethod != "none": au.log.info("Feature selecion : " + fsmethod) selector = select_features(X, y, fsmethod) X = selector.transform(X) # au.log.info ('Randomized PCA') # pca = RandomizedPCA(n_components=2) au.log.info("Linear Discriminant analysis") lda = LDA(n_components=2) fig, plots = plt.subplots(4, 4) fig.set_size_inches(50, 50) plt.prism() for i, j in product(xrange(4), repeat=2): if i > j: continue if i == j: continue X_ = X[(y == i) + (y == j)] y_ = y[(y == i) + (y == j)] # marks # marks = y_.astype(str) # marks[y_ == 0] = 'x' # marks[y_ == 1] = 'o' # marks[y_ == 2] = 'D' # marks[y_ == 3] = '1' # colors colors = y_.copy() colors[y_ == 0] = 0 colors[y_ == 1] = 1 colors[y_ == 2] = 2 colors[y_ == 3] = 3 # transform # X_trans = pca.fit_transform(X_) X_trans = lda.fit(X_, y_).transform(X_) # plots plots[i, j].scatter(X_trans[:, 0], X_trans[:, 1], c=colors, marker="o") plots[i, j].set_xticks(()) plots[i, j].set_yticks(()) plots[j, i].scatter(X_trans[:, 0], X_trans[:, 1], c=colors, marker="o") plots[j, i].set_xticks(()) plots[j, i].set_yticks(()) if i == 0: plots[i, j].set_title(j) plots[j, i].set_ylabel(j) # plt.scatter(X_trans[:, 0], X_trans[:, 1], c=y_) plt.tight_layout() plt.savefig(outfile)