def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m', '--method', choices=DataHandler.get_method_choices(), default='all', help='the method to collect data for')
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default='mciad', choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('-e', '--extrapolator', type=str, choices=['lin', 'sqrt', 'exp'], default='exp', help='the type of extrapolator')
    parser.add_argument('--xlim', type=float, nargs=2, default=None, help='force certain x limits for plotting')
    parser.add_argument('--ylim', type=float, nargs=2, default=None, help='force certain y limits for plotting')
    parser.add_argument('--no_model', action='store_true', default=False, help='do not plot the fitted model')
    parser.add_argument('--no_points', action='store_true', default=False, help='do not plot points')
    parser.add_argument('--points_alpha', type=float, default=0.25, help='alpha value of the plotted points')
    parser.add_argument('--no_densities', action='store_true', default=False, help='do not plot densities')
    parser.add_argument('--no_sample_lines', action='store_true', default=False, help='do not plot the sample lines')
    parser.add_argument('--only_densities', action='store_true', default=False, help='only plot densities')
    parser.add_argument('--no_extrapolation', action='store_true', default=False, help='do not extrapolate the model')
    parser.add_argument('--plot_eta', type=str, choices=['lambda', 'mu', 'sigma'], default=None, help='plot a predictor function')
    parser.add_argument('--plot_errors', action='store_true', default=False, help='plot the errors')
    parser.add_argument('--plot_synth_model', action='store_true', default=False, help='plot density distributions for synthetic data')
    parser.add_argument('--plot_quantile_label', action='store_true', default=False, help='plot labels on the quantile curces')
    parser.add_argument('--plot_donohue', action='store_true', default=False, help='plot the trajectory estimated with Donohue et al.')
    parser.add_argument('--save_plots', action='store_true', default=False, help='save the plots with a default filename')
    parser.add_argument('--plot_file', type=str, default=None, help='filename of the output file')
    args = parser.parse_args()

    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)
    for biomarker in data_handler.get_biomarker_names():
        plot_model(args, data_handler, biomarker)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('visits', nargs='+', type=str, help='the viscodes to be sampled')
    parser.add_argument('-m', '--method', choices=DataHandler.get_method_choices(), default='all',
                        help='the method to collect data for')
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default=None, choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('--estimate_dprs', action='store_true', help='recompute the dpis estimations')
    parser.add_argument('--recompute_estimates', action='store_true', help='recompute the dpis estimations')
    parser.add_argument('--consistent_data', action='store_true', help='us only subjects with bl, m12 and m24 visits')
    parser.add_argument('--no_plot', action='store_true', help='do not plot the results')
    parser.add_argument('--plot_lines', action='store_true', help='plot graphs instead of matrix')
    parser.add_argument('--plot_steps', type=int, default=15, help='number of steps for the DPI scale')
    parser.add_argument('--plot_file', type=str, default=None, help='filename of the output file')
    parser.add_argument('--plot_cmap_jet', action='store_true', help='use the colour map jet')
    args = parser.parse_args()

    # Get estimates
    _, diagnoses, dpis, dprs, mean_min, mean_max = et.get_progress_estimates(
        args.visits,
        method=args.method,
        biomarkers=args.biomarkers,
        phase=args.phase,
        estimate_dprs=args.estimate_dprs,
        recompute_estimates=args.recompute_estimates,
        select_test_set=True,
        consistent_data=args.consistent_data)

    # Plot results
    if not args.no_plot:
        plot_dpi_estimates(args, dpis, diagnoses, mean_min, mean_max)
        if args.estimate_dprs:
            plot_dpi_dpr_distribution(args, dpis, dprs, diagnoses)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('visits', nargs='+', type=str, help='the viscodes of the visits that are available')
    parser.add_argument('-m', '--method', choices=DataHandler.get_method_choices(), default='all', help='the method to collect data for')
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default=None, choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('--predict_biomarker', type=str, default='MMSE', help='the biomarker to predict')
    parser.add_argument('--recompute_estimates', action='store_true', help='recompute the dpi / dpr estimations')
    parser.add_argument('--recompute_predictions', action='store_true', help='recompute the biomarker predictions')
    parser.add_argument('--estimate_dprs', action='store_true', help='estimate dpis and dprs')
    parser.add_argument('--consistent_data', action='store_true', help='use only subjects with bl, m12 and m24 visits')
    parser.add_argument('--exclude_cn', action='store_true', help='exclude healthy subjects from analysis')
    parser.add_argument('--use_last_visit', action='store_true', help='use only the last visit for prediction')
    parser.add_argument('--naive_use_diagnosis', action='store_true', help='use the specific mean change for the diagnosis')
    parser.add_argument('--no_plot', action='store_true', help='do not plot the results')
    parser.add_argument('--plot_file', type=str, default=None, help='filename of the output file')
    parser.add_argument('--latex_file', type=str, default=None, help='add output to a LaTeX file')
    args = parser.parse_args()

    _, diagnoses, values_observed, values_naive, values_model = \
        et.get_biomarker_predictions(args.visits, args.predict_biomarker,
                                     method=args.method,
                                     biomarkers=args.biomarkers,
                                     phase=args.phase,
                                     recompute_estimates=args.recompute_estimates,
                                     recompute_predictions=args.recompute_predictions,
                                     estimate_dprs=args.estimate_dprs,
                                     select_test_set=True,
                                     consistent_data=args.consistent_data,
                                     exclude_cn=args.exclude_cn,
                                     use_last_visit=args.use_last_visit,
                                     naive_use_diagnosis=args.naive_use_diagnosis)
    if not args.no_plot:
        plot_biomarker_predictions(args, diagnoses, values_observed, values_model)
    analyse_biomarker_predictions(args, diagnoses, values_observed, values_naive, values_model)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('visits', nargs='+', type=str, help='the viscodes to be sampled')
    parser.add_argument('-m', '--method', choices=DataHandler.get_method_choices(), default='all', help='the method to collect data for')
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default=None, choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('-c', '--classifier', default='svm', choices=['lda', 'svm', 'lsvm', 'rf'], help='the approach used to classify the subjects')
    parser.add_argument('--estimate_dprs', action='store_true', help='recompute the dpis estimations')
    parser.add_argument('--recompute_estimates', action='store_true', help='recompute the dpis estimations')
    parser.add_argument('--consistent_data', action='store_true', help='us only subjects with bl, m12 and m24 visits')
    parser.add_argument('--num_folds', type=int, default=10, help='number of folds for the n-fold cross validation')
    parser.add_argument('--latex_file', type=str, default=None, help='add output to a LaTeX file')
    args = parser.parse_args()

    # Get estimates
    rids, diagnoses, dpis, dprs, _, _ = et.get_progress_estimates(
        args.visits,
        method=args.method,
        biomarkers=args.biomarkers,
        phase=args.phase,
        estimate_dprs=args.estimate_dprs,
        recompute_estimates=args.recompute_estimates,
        consistent_data=args.consistent_data)

    # Select converters and non-converters sets
    rcds, non_rcds = get_rcds(args, rids, diagnoses, dpis, dprs)
    rfds, non_rfds = get_rfds(args, rids, diagnoses, dpis, dprs)

    # Analyse output
    analyse_decline(args, rids, dpis, dprs, rcds, non_rcds)
    analyse_decline(args, rids, dpis, dprs, rfds, non_rfds)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-b',
                        '--biomarkers',
                        nargs='+',
                        default=None,
                        help='name of the biomarker to be plotted')
    parser.add_argument('-p',
                        '--phase',
                        default=None,
                        choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('--predict_biomarker',
                        type=str,
                        default='MMSE',
                        help='the biomarker to predict')
    parser.add_argument('--recompute_estimates',
                        action='store_true',
                        help='recompute the dpi / dpr estimations')
    parser.add_argument('--recompute_predictions',
                        action='store_true',
                        help='recompute the biomarker predictions')
    parser.add_argument('--plot_file',
                        type=str,
                        default=None,
                        help='filename of the output file')
    args = parser.parse_args()

    visits = ['bl', 'm12', 'm24']
    methods = ['cog', 'vol', 'ml', 'img', 'all']
    values = {}
    for method in methods:
        values.update({method: {}})
        _, _, values_observed, values_naive, values_model = \
            et.get_biomarker_predictions(visits, args.predict_biomarker,
                                         method=method,
                                         phase=args.phase,
                                         recompute_estimates=args.recompute_estimates,
                                         recompute_predictions=args.recompute_predictions,
                                         estimate_dprs=False,
                                         exclude_cn=True,
                                         select_test_set=True,
                                         consistent_data=True)
        values[method].update({'observed': values_observed})
        values[method].update({'naive': values_naive})
        values[method].update({'model_dpi': values_model})

        _, _, values_observed, values_naive, values_model = \
            et.get_biomarker_predictions(visits, args.predict_biomarker,
                                         method=method,
                                         phase=args.phase,
                                         recompute_estimates=args.recompute_estimates,
                                         recompute_predictions=args.recompute_predictions,
                                         estimate_dprs=True,
                                         exclude_cn=True,
                                         select_test_set=True,
                                         consistent_data=True)
        values[method].update({'model_dpi_dpr': values_model})

    plot_errors(args, values, methods)
Esempio n. 6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m',
                        '--method',
                        choices=DataHandler.get_method_choices(),
                        default='all',
                        help='the method to collect data for')
    parser.add_argument('-b',
                        '--biomarkers',
                        nargs='+',
                        default=None,
                        help='name of the biomarker to be plotted')
    parser.add_argument('-p',
                        '--phase',
                        default='mciad',
                        choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('-e',
                        '--extrapolator',
                        type=str,
                        choices=['lin', 'sqrt', 'exp'],
                        default='exp',
                        help='the type of extrapolator')
    args = parser.parse_args()

    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)

    biomarkers = data_handler.get_biomarker_names()
    if args.method == 'joint':
        offsets = np.linspace(500, 3000, 26)
    else:
        offsets = np.linspace(-1000, 1000, 21)
    all_diffs = np.zeros((len(offsets), len(biomarkers)))

    for i, biomarker in enumerate(biomarkers):
        diffs = get_model_differences(args, data_handler, biomarker, offsets)
        all_diffs[:, i] = diffs
        print biomarker, offsets[np.argmin(diffs)]

    optimum_index = np.argmin(np.mean(all_diffs, axis=1))

    print 'all', offsets[optimum_index]

    mins = all_diffs[optimum_index, :]  # np.min(all_diffs, axis=0)
    indices = np.argsort(mins)
    for i in indices:
        print biomarkers[i], mins[i]

    fig = plt.figure()
    ax1 = plt.subplot(1, 1, 1)
    ax1.plot(offsets, all_diffs, color='r')
    ax1.plot(offsets, np.mean(all_diffs, axis=1), color='b')
    plt.show()
    plt.close(fig)
def main():
    parser = argparse.ArgumentParser(
        description='Estimate model curves for biomarkers using VGAM.')
    parser.add_argument('-m',
                        '--method',
                        choices=DataHandler.get_method_choices(),
                        default='all',
                        help='the method to collect data for')
    parser.add_argument('-b',
                        '--biomarkers',
                        nargs='+',
                        default=None,
                        help='name of the biomarker to be plotted')
    parser.add_argument('-p',
                        '--phase',
                        default=None,
                        choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('-n',
                        '--nr_threads',
                        type=int,
                        default=1,
                        help='number of threads')
    parser.add_argument('--min_visits',
                        type=int,
                        default=0,
                        help='the minimal number of visits')
    parser.add_argument(
        '--no_regression',
        action='store_true',
        default=False,
        help='do not perform age regression of biomarker values')
    parser.add_argument('--recompute_models',
                        action='store_true',
                        help='recompute the models with new samples')
    args = parser.parse_args()

    # Get the data files and biomarkers
    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)

    # Estimate curves
    # generate_csv_file(args, data_handler)
    # print_gender_statistics(args, data_handler)
    print_terminal_decline_statistics(args, data_handler)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default=None, choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('--predict_biomarker', type=str, default='MMSE', help='the biomarker to predict')
    parser.add_argument('--recompute_estimates', action='store_true', help='recompute the dpi / dpr estimations')
    parser.add_argument('--recompute_predictions', action='store_true', help='recompute the biomarker predictions')
    parser.add_argument('--plot_file', type=str, default=None, help='filename of the output file')
    args = parser.parse_args()

    visits = ['bl', 'm12', 'm24']
    methods = ['cog', 'vol', 'ml', 'img', 'all']
    values = {}
    for method in methods:
        values.update({method: {}})
        _, _, values_observed, values_naive, values_model = \
            et.get_biomarker_predictions(visits, args.predict_biomarker,
                                         method=method,
                                         phase=args.phase,
                                         recompute_estimates=args.recompute_estimates,
                                         recompute_predictions=args.recompute_predictions,
                                         estimate_dprs=False,
                                         exclude_cn=True,
                                         select_test_set=True,
                                         consistent_data=True)
        values[method].update({'observed': values_observed})
        values[method].update({'naive': values_naive})
        values[method].update({'model_dpi': values_model})

        _, _, values_observed, values_naive, values_model = \
            et.get_biomarker_predictions(visits, args.predict_biomarker,
                                         method=method,
                                         phase=args.phase,
                                         recompute_estimates=args.recompute_estimates,
                                         recompute_predictions=args.recompute_predictions,
                                         estimate_dprs=True,
                                         exclude_cn=True,
                                         select_test_set=True,
                                         consistent_data=True)
        values[method].update({'model_dpi_dpr': values_model})

    plot_errors(args, values, methods)
def main():
    parser = argparse.ArgumentParser(description='Estimate model curves for biomarkers using VGAM.')
    parser.add_argument('-m', '--method', choices=DataHandler.get_method_choices(), default='all', help='the method to collect data for')
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default=None, choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('-n', '--nr_threads', type=int, default=1, help='number of threads')
    parser.add_argument('--min_visits', type=int, default=0, help='the minimal number of visits')
    parser.add_argument('--no_regression', action='store_true', default=False, help='do not perform age regression of biomarker values')
    parser.add_argument('--recompute_models', action='store_true', help='recompute the models with new samples')
    args = parser.parse_args()

    # Get the data files and biomarkers
    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)

    # Estimate curves
    # generate_csv_file(args, data_handler)
    # print_gender_statistics(args, data_handler)
    print_terminal_decline_statistics(args, data_handler)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m', '--method', choices=DataHandler.get_method_choices(), default='all', help='the method to collect data for')
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default='mciad', choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('-e', '--extrapolator', type=str, choices=['lin', 'sqrt', 'exp'], default='exp', help='the type of extrapolator')
    args = parser.parse_args()

    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)

    biomarkers = data_handler.get_biomarker_names()
    if args.method == 'joint':
        offsets = np.linspace(500, 3000, 26)
    else:
        offsets = np.linspace(-1000, 1000, 21)
    all_diffs = np.zeros((len(offsets), len(biomarkers)))

    for i, biomarker in enumerate(biomarkers):
        diffs = get_model_differences(args, data_handler, biomarker, offsets)
        all_diffs[:, i] = diffs
        print biomarker, offsets[np.argmin(diffs)]

    optimum_index = np.argmin(np.mean(all_diffs, axis=1))

    print 'all', offsets[optimum_index]

    mins = all_diffs[optimum_index, :]  # np.min(all_diffs, axis=0)
    indices = np.argsort(mins)
    for i in indices:
        print biomarkers[i], mins[i]

    fig = plt.figure()
    ax1 = plt.subplot(1, 1, 1)
    ax1.plot(offsets, all_diffs, color='r')
    ax1.plot(offsets, np.mean(all_diffs, axis=1), color='b')
    plt.show()
    plt.close(fig)
Esempio n. 11
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--phase', default=None, choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('--consistent_data', action='store_true', help='us only subjects with bl, m12 and m24 visits')
    parser.add_argument('--estimate_dprs', action='store_true', help='estimate dpis and dprs')
    parser.add_argument('--recompute_estimates', action='store_true', help='recompute the dpi / dpr estimations')
    parser.add_argument('--recompute_predictions', action='store_true', help='recompute the biomarker predictions')
    parser.add_argument('--exclude_cn', action='store_true', help='exclude healthy subjects from analysis')
    args = parser.parse_args()

    estimates = {}
    methods = ['cog', 'vol', 'ml', 'img', 'all']
    for method in methods:
        estimates.update({method: {}})
        for visits in [['bl'], ['m12'], ['m24'], ['bl', 'm12'], ['m12', 'm24']]:
            _, diagnoses, dpis, _, _, _ = et.get_progress_estimates(visits,
                                                                    method=method,
                                                                    phase=args.phase,
                                                                    estimate_dprs=args.estimate_dprs)

            diagnoses = np.array(diagnoses)
            dpis = np.array(dpis)
            visits_string = '_'.join(visits)
            estimates[method].update({visits_string: {}})
            estimates[method][visits_string].update({'CN': np.mean(dpis[np.where(diagnoses == 0.0)])})
            estimates[method][visits_string].update({'EMCI': np.mean(dpis[np.where(diagnoses == 0.25)])})
            estimates[method][visits_string].update({'LMCI': np.mean(dpis[np.where(diagnoses == 0.75)])})
            estimates[method][visits_string].update({'AD': np.mean(dpis[np.where(diagnoses == 1.0)])})

    for method in methods:
        print log.INFO, 'Results for {0}'.format(method)
        for diagnosis in ['CN', 'EMCI', 'LMCI', 'AD']:
            print log.RESULT, '{0: <4}:   {1:.2f} {2:.2f} | {3:.2f}  '.format(
                              diagnosis,
                              estimates[method]['m12'][diagnosis] - estimates[method]['bl'][diagnosis],
                              estimates[method]['m24'][diagnosis] - estimates[method]['m12'][diagnosis],
                              estimates[method]['m12_m24'][diagnosis] - estimates[method]['bl_m12'][diagnosis])
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m', '--method', choices=DataHandler.get_method_choices(), default='all', help='the method to collect data for')
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default=None, choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('-n', '--nr_threads', type=int, default=4, help='number of threads')
    parser.add_argument('--recompute_metric', action='store_true', help='recompute the metric')
    parser.add_argument('--value_samples', type=int, default=100, help='the number of values samples')
    parser.add_argument('--progress_samples', type=int, default=50, help='the number of progress samples')
    parser.add_argument('--quantiles', type=float, nargs=2, default=[0.01, 0.99], help='the quantiles for the interval computation')
    parser.add_argument('--metric', type=str, default='cover', help='the metric used for the evaluation')
    args = parser.parse_args()

    # Collect data for test
    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)

    # Compute error for each biomarker
    biomarkers = data_handler.get_biomarker_names()
    evaluation_function = evaluate_biomarker_cover if args.metric == 'cover' else evaluate_biomarker_disc
    jl.Parallel(n_jobs=args.nr_threads)(jl.delayed(evaluation_function)(args, data_handler, biomarker) for biomarker in biomarkers)

    sort_biomarkers(args, data_handler, biomarkers)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m',
                        '--method',
                        choices=DataHandler.get_method_choices(),
                        default='all',
                        help='the method to collect data for')
    parser.add_argument('-b',
                        '--biomarkers',
                        nargs='+',
                        default=None,
                        help='name of the biomarker to be plotted')
    parser.add_argument('-p',
                        '--phase',
                        default=None,
                        choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('--save_plots',
                        action='store_true',
                        default=False,
                        help='save the plots with a default filename')
    args = parser.parse_args()

    # Collect data for test
    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)
    biomarkers = data_handler.get_biomarker_names()
    measurements = data_handler.get_measurements_as_dict(
        visits=['bl', 'm12'],
        biomarkers=biomarkers,
        select_training_set=True,
        select_complete=True)

    # Setup plotting folder
    eval_folder = DataHandler.make_dir(data_handler.get_eval_folder(),
                                       'quants')

    # Process all biomarkers
    for biomarker in biomarkers:
        print log.INFO, 'Generating quantile correlation plot for {0}...'.format(
            biomarker)
        model_file = data_handler.get_model_file(biomarker)
        pm = ProgressionModel(biomarker, model_file)

        q_file = os.path.join(eval_folder, '{0}.p'.format(biomarker))

        if os.path.isfile(q_file):
            (q_bl, q_m12) = pickle.load(open(q_file, 'rb'))
        else:
            q_bl = []
            q_m12 = []

            for rid in measurements:
                val_bl = measurements[rid]['bl'][biomarker]
                val_m12 = measurements[rid]['m12'][biomarker]

                p_bl = measurements[rid]['bl']['progress']
                p_m12 = measurements[rid]['m12']['progress']

                q_bl.append(pm.approximate_quantile(p_bl, val_bl))
                q_m12.append(pm.approximate_quantile(p_m12, val_m12))

            pickle.dump((q_bl, q_m12), open(q_file, 'wb'))

        # Setup plot
        fig, axs = plt.subplots(1, 2)
        plt.suptitle('Correlation between bl and m12 quantiles')

        # Plot 1
        ax = axs[0]
        pt.setup_axes(plt, ax, yspine=True)
        ax.set_xlabel('Quantile bl')
        ax.set_ylabel('Quantile m12')

        ax.scatter(q_bl, q_m12, edgecolor='none', s=25.0, alpha=0.5)

        # Plot 2
        q_bl = np.array(q_bl)
        q_m12 = np.array(q_m12)

        errors = q_bl - q_m12
        loc, scale = norm.fit(errors, floc=0.0)

        ax = axs[1]
        pt.setup_axes(plt, ax)
        ax.set_xlabel('Difference bl to m12')
        ax.set_ylabel('Probability')
        ax.set_xlim(-1.05, 1.05)
        ax.hist(errors, bins=15, normed=True, histtype='stepfilled', alpha=0.3)
        x = np.linspace(-1.0, 1.0, 100)
        ax.plot(x, norm.pdf(x, loc=loc, scale=scale), color='k')

        # Draw or save the plot
        plt.tight_layout()
        if args.save_plots:
            plot_file = os.path.join(eval_folder, '{0}.pdf'.format(biomarker))
            plt.savefig(plot_file, transparent=True)
        else:
            plt.show()
        plt.close(fig)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('visits',
                        nargs='+',
                        type=str,
                        help='the viscodes to be sampled')
    parser.add_argument('-m',
                        '--method',
                        choices=DataHandler.get_method_choices(),
                        default='all',
                        help='the method to collect data for')
    parser.add_argument('-b',
                        '--biomarkers',
                        nargs='+',
                        default=None,
                        help='name of the biomarker to be plotted')
    parser.add_argument('-p',
                        '--phase',
                        default=None,
                        choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('--estimate_dprs',
                        action='store_true',
                        help='recompute the dpis estimations')
    parser.add_argument('--recompute_estimates',
                        action='store_true',
                        help='recompute the dpis estimations')
    parser.add_argument('--consistent_data',
                        action='store_true',
                        help='us only subjects with bl, m12 and m24 visits')
    parser.add_argument('--no_plot',
                        action='store_true',
                        help='do not plot the results')
    parser.add_argument('--plot_lines',
                        action='store_true',
                        help='plot graphs instead of matrix')
    parser.add_argument('--plot_steps',
                        type=int,
                        default=15,
                        help='number of steps for the DPI scale')
    parser.add_argument('--plot_file',
                        type=str,
                        default=None,
                        help='filename of the output file')
    parser.add_argument('--plot_cmap_jet',
                        action='store_true',
                        help='use the colour map jet')
    args = parser.parse_args()

    # Get estimates
    _, diagnoses, dpis, dprs, mean_min, mean_max = et.get_progress_estimates(
        args.visits,
        method=args.method,
        biomarkers=args.biomarkers,
        phase=args.phase,
        estimate_dprs=args.estimate_dprs,
        recompute_estimates=args.recompute_estimates,
        select_test_set=True,
        consistent_data=args.consistent_data)

    # Plot results
    if not args.no_plot:
        plot_dpi_estimates(args, dpis, diagnoses, mean_min, mean_max)
        if args.estimate_dprs:
            plot_dpi_dpr_distribution(args, dpis, dprs, diagnoses)
Esempio n. 15
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('visits',
                        nargs='+',
                        type=str,
                        help='the viscodes of the visits that are available')
    parser.add_argument('-m',
                        '--method',
                        choices=DataHandler.get_method_choices(),
                        default='all',
                        help='the method to collect data for')
    parser.add_argument('-b',
                        '--biomarkers',
                        nargs='+',
                        default=None,
                        help='name of the biomarker to be plotted')
    parser.add_argument('-p',
                        '--phase',
                        default=None,
                        choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('--predict_biomarker',
                        type=str,
                        default='MMSE',
                        help='the biomarker to predict')
    parser.add_argument('--recompute_estimates',
                        action='store_true',
                        help='recompute the dpi / dpr estimations')
    parser.add_argument('--recompute_predictions',
                        action='store_true',
                        help='recompute the biomarker predictions')
    parser.add_argument('--estimate_dprs',
                        action='store_true',
                        help='estimate dpis and dprs')
    parser.add_argument('--consistent_data',
                        action='store_true',
                        help='use only subjects with bl, m12 and m24 visits')
    parser.add_argument('--exclude_cn',
                        action='store_true',
                        help='exclude healthy subjects from analysis')
    parser.add_argument('--use_last_visit',
                        action='store_true',
                        help='use only the last visit for prediction')
    parser.add_argument('--naive_use_diagnosis',
                        action='store_true',
                        help='use the specific mean change for the diagnosis')
    parser.add_argument('--no_plot',
                        action='store_true',
                        help='do not plot the results')
    parser.add_argument('--plot_file',
                        type=str,
                        default=None,
                        help='filename of the output file')
    parser.add_argument('--latex_file',
                        type=str,
                        default=None,
                        help='add output to a LaTeX file')
    args = parser.parse_args()

    _, diagnoses, values_observed, values_naive, values_model = \
        et.get_biomarker_predictions(args.visits, args.predict_biomarker,
                                     method=args.method,
                                     biomarkers=args.biomarkers,
                                     phase=args.phase,
                                     recompute_estimates=args.recompute_estimates,
                                     recompute_predictions=args.recompute_predictions,
                                     estimate_dprs=args.estimate_dprs,
                                     select_test_set=True,
                                     consistent_data=args.consistent_data,
                                     exclude_cn=args.exclude_cn,
                                     use_last_visit=args.use_last_visit,
                                     naive_use_diagnosis=args.naive_use_diagnosis)
    if not args.no_plot:
        plot_biomarker_predictions(args, diagnoses, values_observed,
                                   values_model)
    analyse_biomarker_predictions(args, diagnoses, values_observed,
                                  values_naive, values_model)
Esempio n. 16
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('visits',
                        nargs='+',
                        type=str,
                        help='the viscodes to be sampled')
    parser.add_argument('-m',
                        '--method',
                        choices=DataHandler.get_method_choices(),
                        default='all',
                        help='the method to collect data for')
    parser.add_argument('-b',
                        '--biomarkers',
                        nargs='+',
                        default=None,
                        help='name of the biomarker to be plotted')
    parser.add_argument('-p',
                        '--phase',
                        default=None,
                        choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('-c',
                        '--classifier',
                        default='svm',
                        choices=['lda', 'svm', 'lsvm', 'rf'],
                        help='the approach used to classify the subjects')
    parser.add_argument('--estimate_dprs',
                        action='store_true',
                        help='recompute the dpis estimations')
    parser.add_argument('--recompute_estimates',
                        action='store_true',
                        help='recompute the dpis estimations')
    parser.add_argument('--consistent_data',
                        action='store_true',
                        help='us only subjects with bl, m12 and m24 visits')
    parser.add_argument('--num_folds',
                        type=int,
                        default=10,
                        help='number of folds for the n-fold cross validation')
    parser.add_argument(
        '--num_runs',
        type=int,
        default=1,
        help='number of runs the x-fold cross-validation is performed')
    parser.add_argument('--latex_file',
                        type=str,
                        default=None,
                        help='add output to a LaTeX file')
    args = parser.parse_args()

    # Get estimates
    _, diagnoses, dpis, dprs, _, _ = et.get_progress_estimates(
        args.visits,
        method=args.method,
        biomarkers=args.biomarkers,
        phase=args.phase,
        estimate_dprs=args.estimate_dprs,
        recompute_estimates=args.recompute_estimates,
        consistent_data=args.consistent_data)

    # Analyse estimates
    classify_diagnoses(args, dpis, dprs, diagnoses)
Esempio n. 17
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m',
                        '--method',
                        choices=DataHandler.get_method_choices(),
                        default='all',
                        help='the method to collect data for')
    parser.add_argument('-b',
                        '--biomarkers',
                        nargs='+',
                        default=None,
                        help='name of the biomarker to be plotted')
    parser.add_argument('-p',
                        '--phase',
                        default='mciad',
                        choices=DataHandler.get_phase_choices(),
                        help='the phase for which the model is to be trained')
    parser.add_argument('-e',
                        '--extrapolator',
                        type=str,
                        choices=['lin', 'sqrt', 'exp'],
                        default='exp',
                        help='the type of extrapolator')
    parser.add_argument('--xlim',
                        type=float,
                        nargs=2,
                        default=None,
                        help='force certain x limits for plotting')
    parser.add_argument('--ylim',
                        type=float,
                        nargs=2,
                        default=None,
                        help='force certain y limits for plotting')
    parser.add_argument('--no_model',
                        action='store_true',
                        default=False,
                        help='do not plot the fitted model')
    parser.add_argument('--no_points',
                        action='store_true',
                        default=False,
                        help='do not plot points')
    parser.add_argument('--points_alpha',
                        type=float,
                        default=0.25,
                        help='alpha value of the plotted points')
    parser.add_argument('--no_densities',
                        action='store_true',
                        default=False,
                        help='do not plot densities')
    parser.add_argument('--no_sample_lines',
                        action='store_true',
                        default=False,
                        help='do not plot the sample lines')
    parser.add_argument('--only_densities',
                        action='store_true',
                        default=False,
                        help='only plot densities')
    parser.add_argument('--no_extrapolation',
                        action='store_true',
                        default=False,
                        help='do not extrapolate the model')
    parser.add_argument('--plot_eta',
                        type=str,
                        choices=['lambda', 'mu', 'sigma'],
                        default=None,
                        help='plot a predictor function')
    parser.add_argument('--plot_errors',
                        action='store_true',
                        default=False,
                        help='plot the errors')
    parser.add_argument('--plot_synth_model',
                        action='store_true',
                        default=False,
                        help='plot density distributions for synthetic data')
    parser.add_argument('--plot_quantile_label',
                        action='store_true',
                        default=False,
                        help='plot labels on the quantile curces')
    parser.add_argument(
        '--plot_donohue',
        action='store_true',
        default=False,
        help='plot the trajectory estimated with Donohue et al.')
    parser.add_argument('--save_plots',
                        action='store_true',
                        default=False,
                        help='save the plots with a default filename')
    parser.add_argument('--plot_file',
                        type=str,
                        default=None,
                        help='filename of the output file')
    args = parser.parse_args()

    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)
    for biomarker in data_handler.get_biomarker_names():
        plot_model(args, data_handler, biomarker)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m', '--method', choices=DataHandler.get_method_choices(), default='all', help='the method to collect data for')
    parser.add_argument('-b', '--biomarkers', nargs='+', default=None, help='name of the biomarker to be plotted')
    parser.add_argument('-p', '--phase', default=None, choices=DataHandler.get_phase_choices(), help='the phase for which the model is to be trained')
    parser.add_argument('--save_plots', action='store_true', default=False, help='save the plots with a default filename')
    args = parser.parse_args()

    # Collect data for test
    data_handler = DataHandler.get_data_handler(method=args.method,
                                                biomarkers=args.biomarkers,
                                                phase=args.phase)
    biomarkers = data_handler.get_biomarker_names()
    measurements = data_handler.get_measurements_as_dict(visits=['bl', 'm12'],
                                                         biomarkers=biomarkers,
                                                         select_training_set=True,
                                                         select_complete=True)

    # Setup plotting folder
    eval_folder = DataHandler.make_dir(data_handler.get_eval_folder(), 'quants')

    # Process all biomarkers
    for biomarker in biomarkers:
        print log.INFO, 'Generating quantile correlation plot for {0}...'.format(biomarker)
        model_file = data_handler.get_model_file(biomarker)
        pm = ProgressionModel(biomarker, model_file)

        q_file = os.path.join(eval_folder, '{0}.p'.format(biomarker))

        if os.path.isfile(q_file):
            (q_bl, q_m12) = pickle.load(open(q_file, 'rb'))
        else:
            q_bl = []
            q_m12 = []

            for rid in measurements:
                val_bl = measurements[rid]['bl'][biomarker]
                val_m12 = measurements[rid]['m12'][biomarker]

                p_bl = measurements[rid]['bl']['progress']
                p_m12 = measurements[rid]['m12']['progress']

                q_bl.append(pm.approximate_quantile(p_bl, val_bl))
                q_m12.append(pm.approximate_quantile(p_m12, val_m12))

            pickle.dump((q_bl, q_m12), open(q_file, 'wb'))

        # Setup plot
        fig, axs = plt.subplots(1, 2)
        plt.suptitle('Correlation between bl and m12 quantiles')

        # Plot 1
        ax = axs[0]
        pt.setup_axes(plt, ax, yspine=True)
        ax.set_xlabel('Quantile bl')
        ax.set_ylabel('Quantile m12')

        ax.scatter(q_bl, q_m12, edgecolor='none', s=25.0, alpha=0.5)

        # Plot 2
        q_bl = np.array(q_bl)
        q_m12 = np.array(q_m12)

        errors = q_bl - q_m12
        loc, scale = norm.fit(errors, floc=0.0)

        ax = axs[1]
        pt.setup_axes(plt, ax)
        ax.set_xlabel('Difference bl to m12')
        ax.set_ylabel('Probability')
        ax.set_xlim(-1.05, 1.05)
        ax.hist(errors, bins=15, normed=True, histtype='stepfilled', alpha=0.3)
        x = np.linspace(-1.0, 1.0, 100)
        ax.plot(x, norm.pdf(x, loc=loc, scale=scale), color='k')

        # Draw or save the plot
        plt.tight_layout()
        if args.save_plots:
            plot_file = os.path.join(eval_folder, '{0}.pdf'.format(biomarker))
            plt.savefig(plot_file, transparent=True)
        else:
            plt.show()
        plt.close(fig)