def __iter__(self):
        pid_iterators = [ps.filtered_pid_iterator(set_hard_coded_key_dec(ps.filtered_pid_iterator,'surgpids')(ps.all_ucla_pid_iterator(), ps.bin_f(ps.ucla_treatment_f(),ps.equals_bin([ps.ucla_treatment_f.surgery]))), ps.is_good_pid())]
        #pid_iterators = [ps.all_ucla_pid_iterator()]
        #filter_fs = [hard_coded_filter_fs.old_filter_f]
        filter_fs = [ps.always_true_f()]
        #filtered_data_fs = [ps.generic_filtered_get_data_f(filter_f) for filter_f in filter_fs]
        upscale_vals = [0]
        diffcovs_iters = [1000]
        diffcovs_numchains = [1]
        diffcovs_seeds = [1]
        perf_percentiles = [[0.25, 0.5, 0.75]]
        perf_times = [[1,2,4,8,12,18,24,30,36,42,48]]
        get_pops_fs = [ps.train_better_pops_f()]
        summarize_fs = [ps.get_param_mean_f()]
        cv_fs = [ps.cv_fold_f(3)]
        upscale_vals = [0.0] #

        ys_fs = [ps.modified_ys_f(ps.ys_f(ps.ys_f.sexual_function), ps.score_modifier_f(c)) for c in upscale_vals]

        post_process_fs = [ps.normalized_data_f()]

        actual_ys_f_shifts = [1]

        loss_fs = [ps.scaled_logistic_loss_f(10.0)]

        feature_sets_iterator = [hard_coded_feature_sets.default_simple_indicators]
        
        hypers = [hard_coded_hypers.default_hyper]

        x_abc_fs = ps.keyed_list([set_hard_coded_key_dec(ps.x_abc_fs, feature_set.get_key())(feature_set, feature_set, feature_set) for feature_set in feature_sets_iterator])

        return itertools.product(pid_iterators, filter_fs, diffcovs_iters, diffcovs_numchains, diffcovs_seeds, perf_percentiles, perf_times, get_pops_fs, summarize_fs, cv_fs, ys_fs, hypers, x_abc_fs, loss_fs, actual_ys_f_shifts, post_process_fs)
    def __iter__(self):
        pid_iterators = [set_hard_coded_key_dec(ps.filtered_pid_iterator,'surgpids')(ps.all_ucla_pid_iterator(), ps.bin_f(ps.ucla_treatment_f(),ps.equals_bin([ps.ucla_treatment_f.surgery])))]
        filtered_data_fs = [ps.old_filtered_get_data_f(), ps.medium_filtered_get_data_f(), ps.filtered_get_data_f()]
        upscale_vals = [0]
        diffcovs_iters = [5000]
        diffcovs_numchains = [4]
        diffcovs_seeds = [1]
        perf_percentiles = [[0.25, 0.5, 0.75]]
        get_pops_fs = [ps.train_better_pops_f()]
        summarize_fs = [ps.get_param_mean_f()]
        cv_fs = [ps.cv_fold_f(4)]
        upscale_vals = [0.0] #
        perf_times = [[1,2,4,8,12,18,24,30,36,42,48]]
        ys_fs = [ps.modified_ys_f(ps.ys_f(ps.ys_f.sexual_function), ps.score_modifier_f(c)) for c in upscale_vals]

        actual_ys_f_shifts = [0,1]

        loss_fs = [ps.scaled_logistic_loss_f(10.0)]


        feature_sets_iterator = [hard_coded_feature_sets.default_initial_categorical_f, hard_coded_feature_sets.medium_initial_categorical_f, hard_coded_feature_sets.highminus_initial_categorical_f, hard_coded_feature_sets.high_initial_categorical_f, hard_coded_feature_sets.higher_initial_categorical_f]
        
        hypers = [hard_coded_hypers.default_hyper]
        x_abc_fs = ps.keyed_list([set_hard_coded_key_dec(ps.x_abc_fs, feature_set.get_key())(feature_set, feature_set, feature_set) for feature_set in feature_sets_iterator])

        return itertools.product(pid_iterators, filtered_data_fs, diffcovs_iters, diffcovs_numchains, diffcovs_seeds, perf_percentiles, perf_times, get_pops_fs, summarize_fs, cv_fs, ys_fs, hypers, x_abc_fs, loss_fs, actual_ys_f_shifts)
def param_to_datasets_and_trainers(pid_iterator, filtered_data_f, diffcovs_iter, diffcovs_numchains, diffcovs_seed, perf_percentiles, perf_times, get_pops_f, summarize_f, cv_f, ys_f, hypers, x_abc_f, loss_f):
    get_posterior_f = ps.get_diffcovs_posterior_f(get_pops_f, hypers, diffcovs_iter, diffcovs_numchains, diffcovs_seed)
    diffcovs_trainer = ps.get_diffcovs_point_predictor_f(get_posterior_f, summarize_f)
    prior_trainer = ps.get_prior_predictor_f(get_pops_f)
    logreg_trainer = ps.get_logreg_predictor_f(perf_times)
    init_f = ps.set_hard_coded_key_dec(ps.s_f, 'init')(ys_f)
    data = ps.get_data_f(x_abc_f, init_f, ps.after_0_ys_f(ys_f))(pid_iterator)
    filtered_data = filtered_data_f(data)
    return ps.keyed_list([prior_trainer, logreg_trainer, diffcovs_trainer]), cv_f, loss_f, perf_percentiles, perf_times, filtered_data
def plot_model_performances(the_iterable):

    for (
        pid_iterator,
        filter_f,
        diffcovs_iter,
        diffcovs_numchains,
        diffcovs_seed,
        perf_percentiles,
        perf_times,
        get_pops_f,
        summarize_f,
        cv_f,
        ys_f,
        hypers,
        x_abc_f,
        loss_f,
        actual_ys_f_shift,
        post_process_f,
    ) in the_iterable:

        try:
            get_posterior_f = ps.get_pystan_diffcovs_posterior_f(
                get_pops_f, hypers, diffcovs_iter, diffcovs_numchains, diffcovs_seed
            )
            diffcovs_trainer = ps.get_diffcovs_point_predictor_f(get_posterior_f, summarize_f)
            prior_trainer = ps.get_prior_predictor_f(get_pops_f)
            shifted_perf_times = [t - actual_ys_f_shift for t in perf_times]
            logreg_trainer = ps.get_logreg_predictor_f(shifted_perf_times)
            trainers = ps.keyed_list([prior_trainer, logreg_trainer, diffcovs_trainer])
            init_f = ps.set_hard_coded_key_dec(ps.s_f, "init")(ys_f)
            actual_ys_f = ps.actual_ys_f(ys_f, actual_ys_f_shift)
            data = ps.get_data_f(x_abc_f, init_f, actual_ys_f)(pid_iterator)
            filtered_data = ps.generic_filtered_get_data_f(filter_f)(data)
            filtered_data = post_process_f(filtered_data)
            ps.model_comparer_f(trainers, cv_f, loss_f, perf_percentiles, shifted_perf_times)(filtered_data)
        except Exception, e:
            for frame in traceback.extract_tb(sys.exc_info()[2]):
                fname, lineno, fn, text = frame
                print "Error in %s on line %d" % (fname, lineno)
            print e
            pdb.set_trace()
            pass
def plot_predicted_patient_curves(the_iterable):

    for (
        pid_iterator,
        filtered_data_f,
        diffcovs_iter,
        diffcovs_numchains,
        diffcovs_seed,
        perf_percentiles,
        perf_times,
        get_pops_f,
        summarize_f,
        cv_f,
        ys_f,
        hypers,
        x_abc_f,
        loss_f,
        actual_ys_f_shift,
        post_process_f,
    ) in the_iterable:

        try:
            get_posterior_f = ps.get_pystan_diffcovs_posterior_f(
                get_pops_f, hypers, diffcovs_iter, diffcovs_numchains, diffcovs_seed
            )
            diffcovs_trainer = ps.get_diffcovs_point_predictor_f(get_posterior_f, summarize_f)
            prior_trainer = ps.get_prior_predictor_f(get_pops_f)
            shifted_perf_times = [t - actual_ys_f_shift for t in perf_times]
            logreg_trainer = ps.get_logreg_predictor_f(shifted_perf_times)
            init_f = ps.set_hard_coded_key_dec(ps.s_f, "init")(ys_f)
            actual_ys_f = ps.actual_ys_f(ys_f, actual_ys_f_shift)
            data = ps.get_data_f(x_abc_f, init_f, actual_ys_f)(pid_iterator)
            filtered_data = ps.generic_filtered_get_data_f(filter_f)(data)
            filtered_data = post_process_f(filtered_data)

            ps.plot_all_predictions_fig_f(
                ps.keyed_list([prior_trainer, logreg_trainer, diffcovs_trainer]), cv_f, shifted_perf_times
            )(filtered_data)
        except:
            pass