def test_predict_bvals(): [actual1, actual2, predicted11, predicted12, predicted22, predicted21] = pn.predict_bvals(data_pv, bvals_pv, bvecs_pv, mask_pv, ad, rd, 0, 2, n = 10, solver = "nnls", mode = "kfold_xval") rmse00 = np.sqrt(np.mean((actual1 - predicted11)**2)) rmse02 = np.sqrt(np.mean((actual2 - predicted12)**2)) rmse22 = np.sqrt(np.mean((actual2 - predicted22)**2)) rmse20 = np.sqrt(np.mean((actual1 - predicted21)**2)) npt.assert_(rmse00<300) npt.assert_(rmse02<300) npt.assert_(rmse22<300) npt.assert_(rmse20<300)
bvals = np.loadtxt(os.path.join(data_path, "bvals")) bvecs = np.loadtxt(os.path.join(data_path, "bvecs")) low = i*2000 # Make sure not to go over the edge of the mask: high = np.min([(i+1) * 2000, int(np.sum(wm_data))]) # Preserve memory by getting rid of this data: del wm_data # Now set the mask: mask = np.zeros(wm_data_file.shape) mask[wm_idx[0][low:high], wm_idx[1][low:high], wm_idx[2][low:high]] = 1 # Predict 10% (n = 10) ad = {1000:1.6386920952169737, 2000:1.2919249903637751, 3000:0.99962593218241236} rd = {1000:0.33450124887561905, 2000:0.28377379537043729, 3000:0.24611723207420028} [actual1, actual2, predicted11, predicted13, predicted33, predicted31] = pn.predict_bvals(data, bvals, bvecs, mask, ad, rd, b_idx1, b_idx2, n = 10, mode = "kfold_xval") np.save("/hsgs/nobackup/klchan13/predict_bvals11_%d.npy"%i, predicted11) np.save("/hsgs/nobackup/klchan13/predict_bvals13_%d.npy"%i, predicted13) np.save("/hsgs/nobackup/klchan13/predict_bvals33_%d.npy"%i, predicted33) np.save("/hsgs/nobackup/klchan13/predict_bvals31_%d.npy"%i, predicted31) t2 = time.time() print "This program took %4.2f minutes to run."%((t2 - t1)/60.)
# Predict 10% (n = 10) ad = { 1000: 1.6386920952169737, 2000: 1.2919249903637751, 3000: 0.99962593218241236 } rd = { 1000: 0.33450124887561905, 2000: 0.28377379537043729, 3000: 0.24611723207420028 } [actual1, actual2, predicted11, predicted13, predicted33, predicted31] = pn.predict_bvals(data, bvals, bvecs, mask, ad, rd, b_idx1, b_idx2, n=10, mode="kfold_xval") np.save("/hsgs/nobackup/klchan13/predict_bvals11_%d.npy" % i, predicted11) np.save("/hsgs/nobackup/klchan13/predict_bvals13_%d.npy" % i, predicted13) np.save("/hsgs/nobackup/klchan13/predict_bvals33_%d.npy" % i, predicted33) np.save("/hsgs/nobackup/klchan13/predict_bvals31_%d.npy" % i, predicted31) t2 = time.time() print "This program took %4.2f minutes to run." % ((t2 - t1) / 60.)