def setup_algorithms(training_data, dist, delta, train=True):
    start = time.time()
    n_x = dist.n_x
    n_a = dist.n_a
    n_y = dist.n_y
    statistical_approximation_prior = StatisticalApproximator(
        n_x, n_a, n_y, training_data, smoothing_mode='gaussian')
    true_approximation = ExactApproximator(dist)

    constraint_prior = Constraint(training_data,
                                  n_a,
                                  n_y,
                                  approximator=statistical_approximation_prior,
                                  delta=delta)
    constraint_true = Constraint(training_data,
                                 n_a,
                                 n_y,
                                 approximator=true_approximation,
                                 delta=delta)

    algorithms = [
        ConstrainedDynamicProgramming(
            n_x,
            n_a,
            n_y,
            training_data,
            constraint_prior,
            statistical_approximation_prior,
            name="Dynamic Programming Historical Prior",
            label="CDP_H"),
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_true,
                                      true_approximation,
                                      name="Dynamic Programming True",
                                      label="CDP_T"),
        ConstrainedGreedy(n_x,
                          n_a,
                          n_y,
                          training_data,
                          constraint_prior,
                          statistical_approximation_prior,
                          name="Greedy Historical Prior",
                          label="CG_H"),
    ]

    print("Setting up algorithms took {:.3f} seconds".format(time.time() -
                                                             start))
    return algorithms
Пример #2
0
def setup_algorithms(training_data, dist, delta):
    start = time.time()
    n_x = dist.n_x
    n_a = dist.n_a
    n_y = dist.n_y
    statistical_approximation_none = StatisticalApproximator(n_x, n_a, n_y, training_data, smoothing_mode='none')
    statistical_approximation_prior = StatisticalApproximator(n_x, n_a, n_y, training_data, smoothing_mode='gaussian')
    function_approximation = FunctionApproximation(n_x, n_a, n_y, training_data)
    true_approximation = ExactApproximator(dist)

    constraint_none = Constraint(training_data, n_a, n_y, approximator=statistical_approximation_none, delta=delta)
    constraint_prior = Constraint(training_data, n_a, n_y, approximator=statistical_approximation_prior, delta=delta)
    constraint_func = Constraint(training_data, n_a, n_y, approximator=function_approximation, delta=delta)
    constraint_true = Constraint(training_data, n_a, n_y, approximator=true_approximation, delta=delta)

    algorithms = [
        ConstrainedGreedy(n_x, n_a, n_y, training_data, constraint_none, statistical_approximation_none, name="Greedy Uniform Prior", label="CG_U"),
        ConstrainedGreedy(n_x, n_a, n_y, training_data, constraint_prior, statistical_approximation_prior, name="Greedy Historical Prior", label="CG_H"),
        ConstrainedGreedy(n_x, n_a, n_y, training_data, constraint_func, function_approximation, name="Greedy Function Approximation", label="CG_F"),
        ConstrainedGreedy(n_x, n_a, n_y, training_data, constraint_true, true_approximation, name="Greedy True Approximation", label="CG_T"),
    ]

    print("Setting up algorithms took {:.3f} seconds".format(time.time() - start))
    return algorithms
Пример #3
0
def setup_algorithms(training_data, dist, delta):
    start = time.time()
    n_x = dist.n_x
    n_a = dist.n_a
    n_y = dist.n_y
    statistical_approximation_prior = StatisticalApproximator(
        n_x, n_a, n_y, training_data, smoothing_mode='gaussian')
    statistical_approximation_none = StatisticalApproximator(
        n_x, n_a, n_y, training_data, smoothing_mode='none')
    true_approximation = ExactApproximator(dist)
    constraint_prior = Constraint(training_data,
                                  n_a,
                                  n_y,
                                  approximator=statistical_approximation_prior,
                                  delta=delta)
    constraint_none = Constraint(training_data,
                                 n_a,
                                 n_y,
                                 approximator=statistical_approximation_none,
                                 delta=delta)
    constraint_true = Constraint(training_data,
                                 n_a,
                                 n_y,
                                 approximator=true_approximation,
                                 delta=delta)
    algorithms = [
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_true,
                                      true_approximation,
                                      name="Dynamic Programming True",
                                      label="CDP_T"),
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_prior,
                                      statistical_approximation_prior,
                                      name="Constrained Dynamic Programming",
                                      label="CDP_H"),
        ConstrainedDynamicProgramming(
            n_x,
            n_a,
            n_y,
            training_data,
            constraint_none,
            statistical_approximation_none,
            name="Constrained Dynamic Programming Uninformed",
            label="CDP_U"),
        ConstrainedGreedy(n_x,
                          n_a,
                          n_y,
                          training_data,
                          constraint_prior,
                          statistical_approximation_prior,
                          name="Constrained Greedy",
                          label="CG"),
        #NaiveGreedy(n_x, n_a, n_y, statistical_approximation_prior, round(delta * (n_a-1))+1, name='Naive Greedy', label='NG'),
        #NaiveDynamicProgramming(n_x, n_a, n_y, training_data, statistical_approximation_prior, reward=-(delta+0.0001), name='Naive Dynamic Programming', label='NDP'),
    ]

    print("Setting up algosrithms took {:.3f} seconds".format(time.time() -
                                                              start))
    return algorithms
Пример #4
0
    test_data = datasets['test']['data']
    # print("Initializing function approximator")
    # start = time.time()
    function_approximation = FunctionApproximation(n_x, n_a, n_y,
                                                   split_training_data)
    # print("Initializing {} took {:.3f} seconds".format(function_approximation.name, time.time()-start))
    print("Initializing statistical approximator")
    start = time.time()
    statistical_approximation = StatisticalApproximator(n_x,
                                                        n_a,
                                                        n_y,
                                                        split_training_data,
                                                        smoothing_mode='none')
    # print("Initializing {} took {:.3f} seconds".format(statistical_approximation.name, time.time() - start))

    true_approximation = ExactApproximator(dist)

    print("Initializing Constraint")
    start = time.time()

    constraintStatUpper = Constraint(split_training_data,
                                     n_a,
                                     n_y,
                                     approximator=statistical_approximation,
                                     delta=delta,
                                     epsilon=epsilon,
                                     bound='upper')
    constraintStatLower = Constraint(split_training_data,
                                     n_a,
                                     n_y,
                                     approximator=statistical_approximation,
Пример #5
0
def setup_algorithms(training_data, dist, delta, train=True):
    start = time.time()
    n_x = dist.n_x
    n_a = dist.n_a
    n_y = dist.n_y
    statistical_approximation_prior = StatisticalApproximator(
        n_x, n_a, n_y, training_data, smoothing_mode='gaussian')
    true_approximation = ExactApproximator(dist)

    constraint_upper_stat = Constraint(
        training_data,
        n_a,
        n_y,
        approximator=statistical_approximation_prior,
        delta=delta)
    constraint_upper_true = Constraint(training_data,
                                       n_a,
                                       n_y,
                                       approximator=true_approximation,
                                       delta=delta)
    constraint_exact_true = TrueConstraint(dist,
                                           approximator=true_approximation,
                                           delta=delta)
    constraint_exat_stat = TrueConstraint(
        dist, approximator=statistical_approximation_prior, delta=delta)

    algorithms = [
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_upper_stat,
                                      statistical_approximation_prior,
                                      name="Dynamic Programming Upper Stat",
                                      label="CDP_US"),
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_upper_true,
                                      true_approximation,
                                      name="Dynamic Programming Upper True",
                                      label="CDP_UT"),
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_exact_true,
                                      true_approximation,
                                      name="Dynamic Programming Exact True",
                                      label="CDP_ET"),
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_exat_stat,
                                      statistical_approximation_prior,
                                      name="Dynamic Programming Exact Stat",
                                      label="CDP_ES"),
    ]

    print("Setting up algorithms took {:.3f} seconds".format(time.time() -
                                                             start))
    return algorithms
Пример #6
0
                                              n_x,
                                              n_a,
                                              n_y,
                                              seed=seed,
                                              outcome_sensitivity_x_z=1)
dist.print_treatment_statistics()
dist.print_detailed_treatment_statistics()

split_training_data = split_patients(generate_data(dist, n_training_samples))

sa = StatisticalApproximator(n_x,
                             n_a,
                             n_y,
                             split_training_data,
                             smoothing_mode='gaussian')
ta = ExactApproximator(dist)
print("Init constraints")
csa = Constraint(n_x, n_a, n_y, approximator=sa, delta=delta)
cta = Constraint(n_x, n_a, n_y, approximator=ta, delta=delta)

cdp = ConstrainedDynamicProgramming(n_x,
                                    n_a,
                                    n_y,
                                    split_training_data,
                                    csa,
                                    sa,
                                    name="Dynamic Programming",
                                    label="CDP")
cdpt = ConstrainedDynamicProgramming(n_x,
                                     n_a,
                                     n_y,
def setup_algorithms(training_data, dist, delta):
    start = time.time()
    n_x = dist.n_x
    n_a = dist.n_a
    n_y = dist.n_y
    statistical_approximation_none = StatisticalApproximator(
        n_x, n_a, n_y, training_data, smoothing_mode='none')
    statistical_approximation_prior = StatisticalApproximator(
        n_x, n_a, n_y, training_data, smoothing_mode='gaussian')
    function_approximation = FunctionApproximation(n_x, n_a, n_y,
                                                   training_data)
    true_approximation = ExactApproximator(dist)

    constraint_none = Constraint(training_data,
                                 n_a,
                                 n_y,
                                 approximator=statistical_approximation_none,
                                 delta=delta)
    constraint_prior = Constraint(training_data,
                                  n_a,
                                  n_y,
                                  approximator=statistical_approximation_prior,
                                  delta=delta)
    constraint_func = Constraint(training_data,
                                 n_a,
                                 n_y,
                                 approximator=function_approximation,
                                 delta=delta)
    constraint_true = Constraint(training_data,
                                 n_a,
                                 n_y,
                                 approximator=true_approximation,
                                 delta=delta)

    algorithms = [
        ConstrainedDynamicProgramming(
            n_x,
            n_a,
            n_y,
            training_data,
            constraint_prior,
            statistical_approximation_prior,
            name="Dynamic Programming Historical Prior",
            label="CDP_H"),
        ConstrainedGreedy(n_x,
                          n_a,
                          n_y,
                          training_data,
                          constraint_func,
                          function_approximation,
                          name="Constrained Greedy Historical Prior",
                          label="CG_H"),
        NaiveDynamicProgramming(
            n_x,
            n_a,
            n_y,
            training_data,
            statistical_approximation_prior,
            reward=-(delta + 0.0001),
            name='Naive Dynamic Programming Historical Prior',
            label='NDP_H'),
        NaiveGreedy(n_x,
                    n_a,
                    n_y,
                    approximator=statistical_approximation_prior,
                    max_steps=4),
    ]

    print("Setting up algorithms took {:.3f} seconds".format(time.time() -
                                                             start))
    return algorithms