Example #1
0
def test_bval_predict():
    # Now check to see if the values for individual b values is
    # around a value we want
    actual_vals, predicted_vals = pn.kfold_xval(data_pv, bvals_pv, bvecs_pv, mask_pv,
                                                ad, rd, 20, "multi", mean = "empirical",
                                                solver = "nnls")
    npt.assert_equal(np.mean(predicted_vals[1][predicted_vals[1] >1])>800,1)
    npt.assert_equal(np.mean(actual_vals[1][actual_vals[1] >1])>800,1)

    # Let's see if the RMSE is reasonable.
    this_rmse = np.sqrt(np.mean((actual_vals - predicted_vals)**2))
    npt.assert_equal(this_rmse<350, 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
    }

    actual_single, predicted_single = pn.kfold_xval(data,
                                                    bvals,
                                                    bvecs,
                                                    mask,
                                                    ad,
                                                    rd,
                                                    10,
                                                    "multi",
                                                    mean="mean_model",
                                                    solver="nnls")

    aff = np.eye(4)
    save_path = "/hsgs/nobackup/klchan13/"
    nib.Nifti1Image(predicted_single, aff).to_filename(
        os.path.join(save_path, "multi_mm_single_exp_rs%s.nii.gz" % (i)))

    t2 = time.time()
    print "This program took %4.2f minutes to run." % ((t2 - t1) / 60.)
Example #3
0
    ad_rd = np.loadtxt(os.path.join(data_path, "ad_rd_%s.txt" % sid))
    ad = {1000: ad_rd[0, 0], 2000: ad_rd[0, 1], 3000: ad_rd[0, 2]}
    rd = {1000: ad_rd[1, 0], 2000: ad_rd[1, 1], 3000: ad_rd[1, 2]}

    if im == "bi_exp_rs":
        shorthand_im = "be"
    elif im == "single_exp_rs":
        shorthand_im = "se"

    # Predict 10% (n = 10)
    actual, predicted = pn.kfold_xval(data,
                                      bvals,
                                      bvecs,
                                      mask,
                                      ad,
                                      rd,
                                      10,
                                      fODF,
                                      mean_mod_func=im,
                                      mean="mean_model",
                                      solver="nnls")

    cod = ozu.coeff_of_determination(actual, predicted)
    np.save(
        os.path.join(data_path,
                     "sfm_predict_%s_%s%s.npy" % (fODF, shorthand_im, i)),
        predicted)
    np.save(
        os.path.join(data_path,
                     "sfm_cod_%s_%s%s.npy" % (fODF, shorthand_im, i)), cod)
Example #4
0
    if fODF == "multi":
        precision = "emd_multi_combine"
    else:
        precision = "emd"

    if im == "bi_exp_rs":
        shorthand_im = "be"
    elif im == "single_exp_rs":
        shorthand_im = "se"

    # Predict 10% (n = 10)
    emd = pn.kfold_xval(data,
                        bvals,
                        bvecs,
                        mask,
                        ad,
                        rd,
                        10,
                        fODF,
                        mean="mean_model",
                        precision=precision,
                        solver="nnls",
                        mean_mod_func=im)

    np.save(
        os.path.join(data_save_path,
                     "emd_%s_%s%s.npy" % (fODF, shorthand_im, i)), emd[0].T)

    t2 = time.time()
    print "This program took %4.2f minutes to run." % ((t2 - t1) / 60.)
Example #5
0
    high = np.min([(i+1) * 2000, int(np.sum(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
    
    # Load the AD, RD values for this subject.
    ad_rd = np.loadtxt(os.path.join(data_path, "ad_rd_%s.txt"%sid))
    ad = {1000:ad_rd[0,0], 2000:ad_rd[0,1], 3000:ad_rd[0,2]}
    rd = {1000:ad_rd[1,0], 2000:ad_rd[1,1], 3000:ad_rd[1,2]}
    
    if fODF == "multi":
        precision = "emd_multi_combine"
    else:
        precision = "emd"
    
    if im == "bi_exp_rs":
        shorthand_im = "be"
    elif im == "single_exp_rs":
        shorthand_im = "se"
    
    # Predict 10% (n = 10)
    emd = pn.kfold_xval(data, bvals, bvecs, mask, ad, rd, 10, fODF,
                        mean = "mean_model", precision = precision,
                        solver = "nnls", mean_mod_func = im)
                        
    np.save(os.path.join(data_save_path, "emd_%s_%s%s.npy"%(fODF,shorthand_im,i)), emd[0].T)
    
    t2 = time.time()
    print "This program took %4.2f minutes to run."%((t2 - t1)/60.)
    high = np.min([(i+1) * 2000, int(np.sum(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

    # Load the AD, RD values for this subject.
    ad_rd = np.loadtxt(os.path.join(data_path, "ad_rd_%s.txt"%sid))
    ad = {1000:ad_rd[0,0], 2000:ad_rd[0,1], 3000:ad_rd[0,2]}
    rd = {1000:ad_rd[1,0], 2000:ad_rd[1,1], 3000:ad_rd[1,2]}

    if im == "bi_exp_rs":
        shorthand_im = "be"
    elif im == "single_exp_rs":
        shorthand_im = "se"

    # Predict 10% (n = 10)
    actual, predicted = pn.kfold_xval(data, bvals, bvecs,
                                        mask, ad, rd, 10, fODF,
                                        mean_mod_func = im,
                                        mean = "mean_model", solver = "nnls")

    cod = ozu.coeff_of_determination(actual, predicted)
    np.save(os.path.join(data_path, "sfm_predict_%s_%s%s.npy"%(fODF,
                                                    shorthand_im,i)), predicted)
    np.save(os.path.join(data_path, "sfm_cod_%s_%s%s.npy"%(fODF,
                                                          shorthand_im,i)), cod)

    t2 = time.time()
    print "This program took %4.2f minutes to run."%((t2 - t1)/60.)
    data = data_file.get_data()
    wm_data = wm_data_file.get_data()
    wm_idx = np.where(wm_data==1)
    
    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))])

    # 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}
    
    actual_single, predicted_single = pn.kfold_xval(data, bvals, bvecs,
                                                   mask, ad, rd, 10, "multi",
                                                   mean = "mean_model", solver = "nnls")

    aff = np.eye(4)
    save_path = "/hsgs/nobackup/klchan13/"
    nib.Nifti1Image(predicted_single, aff).to_filename(os.path.join(save_path,
                                     "multi_mm_single_exp_rs%s.nii.gz"%(i)))

    t2 = time.time()
    print "This program took %4.2f minutes to run."%((t2 - t1)/60.)