Пример #1
0
def setup_algorithms(dist, training_data, n_x, n_a, n_y, delta):
    start = time.time()
    statistical_approximation = StatisticalApproximator(n_x, n_a, n_y, training_data, smoothing_mode='gaussian')
    function_approximation = FunctionApproximation(n_x, n_a, n_y, training_data)
    doctor_approximation = DoctorApproximator(n_x, n_a, n_y, training_data)

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

    constraintStatUpper = Constraint(training_data, n_a, n_y, approximator=statistical_approximation, delta=delta, bound='upper')
    constraintFuncApprox = Constraint(training_data, n_a, n_y, approximator=function_approximation, delta=delta)
    constraint_exact_func = TrueConstraint(dist, approximator=function_approximation, delta=delta)

    print("Initializing the constraint took {:.3f} seconds".format(time.time() - start))
    print("Initializing algorithms")
    algorithms = [
        #ConstrainedGreedy(n_x, n_a, n_y, training_data, constraintStatUpper, statistical_approximation,
        #                  name='Constrained Greedy', label='CG'),
        # ConstrainedGreedy(n_x, n_a, n_y, split_training_data, constraintStatLower, statistical_approximation,
        #                   name='Constrained Greedy Lower', label='CG_L'),
        ConstrainedGreedy(n_x, n_a, n_y, training_data, constraintFuncApprox, function_approximation,
                         name="Constrained Greedy FuncApprox", label="CG_F"),
        #ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data, constraintStatUpper,
        #                              statistical_approximation),
        ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data, constraintFuncApprox,
                                      function_approximation, name="Constrained Dynamic Programming FuncApprox", label="CDP_F"),

        #NaiveGreedy(n_x, n_a, n_y, function_approximation, max_steps=n_a),
        #NaiveGreedy(n_x, n_a, n_y, function_approximation, max_steps=n_a),
        NaiveDynamicProgramming(n_x, n_a, n_y, training_data, constraintStatUpper, reward=-0.35),
        Doctor(),
        EmulatedDoctor(n_x, n_a, n_y, training_data, approximator=doctor_approximation)
    ]
    return algorithms
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')

    constraint_upper = Constraint(training_data,
                                  n_a,
                                  n_y,
                                  approximator=statistical_approximation_prior,
                                  delta=delta,
                                  bound='upper')
    constraint_lower = Constraint(training_data,
                                  n_a,
                                  n_y,
                                  approximator=statistical_approximation_prior,
                                  delta=delta,
                                  bound='lower')
    constraint_exact = TrueConstraint(
        dist, approximator=statistical_approximation_prior, delta=delta)

    algorithms = [
        #ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data, constraint_upper, statistical_approximation_prior, name="Dynamic Programming Upper Bound", label="CDP_U"),
        #ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data, constraint_lower, statistical_approximation_prior, name="Dynamic Programming Lower bound", label="CDP_L"),
        #ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data, constraint_exact, statistical_approximation_prior, name="Dynamic Programming Exact Bound", label="CDP_E"),
        ConstrainedGreedy(n_x,
                          n_a,
                          n_y,
                          training_data,
                          constraint_upper,
                          statistical_approximation_prior,
                          name="Greedy Upper Bound",
                          label="CG_U"),
        ConstrainedGreedy(n_x,
                          n_a,
                          n_y,
                          training_data,
                          constraint_lower,
                          statistical_approximation_prior,
                          name="Greedy Lower Bound",
                          label="CG_L"),
        ConstrainedGreedy(n_x,
                          n_a,
                          n_y,
                          training_data,
                          constraint_exact,
                          statistical_approximation_prior,
                          name="Greedy Exact Bound",
                          label="CG_E"),
    ]

    print("Setting up algorithms took {:.3f} seconds".format(time.time() -
                                                             start))
    return algorithms
Пример #3
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')

    constraint_prior = Constraint(training_data,
                                  n_a,
                                  n_y,
                                  approximator=statistical_approximation_prior,
                                  delta=delta)
    constraint_prior = TrueConstraint(
        dist, approximator=statistical_approximation_prior, delta=delta)

    algorithms = [
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_prior,
                                      statistical_approximation_prior,
                                      name="Constrained Dynamic Programming",
                                      label="CDP"),
        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 algorithms took {:.3f} seconds".format(time.time() -
                                                             start))
    return algorithms
Пример #4
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')

    algorithms = [
        NaiveDynamicProgramming(n_x, n_a, n_y, training_data, statistical_approximation_prior, reward=-(delta/2+0.0001), name='Naive Dynamic Programming', label='NDP'),
    ]

    print("Setting up algorithms took {:.3f} seconds".format(time.time() - start))
    return algorithms
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
Пример #6
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
Пример #7
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
Пример #8
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')
    function_approximation = FunctionApproximation(n_x, n_a, n_y,
                                                   training_data)
    constraint_prior = Constraint(training_data,
                                  n_a,
                                  n_y,
                                  approximator=statistical_approximation_prior,
                                  delta=delta)

    constraintFuncApprox = Constraint(training_data,
                                      n_a,
                                      n_y,
                                      approximator=function_approximation,
                                      delta=delta)

    algorithms = [
        ConstrainedDynamicProgramming(n_x,
                                      n_a,
                                      n_y,
                                      training_data,
                                      constraint_prior,
                                      statistical_approximation_prior,
                                      name="Constrained Dynamic Programming",
                                      label="CDP"),
        ConstrainedGreedy(n_x,
                          n_a,
                          n_y,
                          training_data,
                          constraint_prior,
                          statistical_approximation_prior,
                          name="Constrained Greedy",
                          label="CG"),
        ConstrainedGreedy(n_x,
                          n_a,
                          n_y,
                          training_data,
                          constraintFuncApprox,
                          function_approximation,
                          name="Constrained Greedy FuncApprox",
                          label="CG_F"),
        # ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data, constraintStatUpper,
        #                              statistical_approximation),
        ConstrainedDynamicProgramming(
            n_x,
            n_a,
            n_y,
            training_data,
            constraintFuncApprox,
            function_approximation,
            name="Constrained Dynamic Programming FuncApprox",
            label="CDP_F"),
        NaiveDynamicProgramming(n_x,
                                n_a,
                                n_y,
                                training_data,
                                statistical_approximation_prior,
                                reward=-(delta / 2 + 0.0001),
                                name='Naive Dynamic Programming',
                                label='NDP'),
    ]

    print("Setting up algorithms took {:.3f} seconds".format(time.time() -
                                                             start))
    return algorithms
Пример #9
0
        n_a = dist.n_a
        n_y = dist.n_y
        n_test_samples = len(test_data)

    split_training_data = datasets['training']['data']
    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,
Пример #10
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
Пример #11
0
n_training_samples = 500000
delta = 0.3
dist = DiscreteDistributionWithSmoothOutcomes(n_z,
                                              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")
Пример #12
0
    print("Generating training data set {}".format(n_training_samples))
    main_data = generate_data(dist, n_training_samples)
    for i in range(len(data_limits)):
        d_tmp = {}
        d_tmp['x'] = np.copy(main_data['x'][0:data_limits[i]])
        d_tmp['h'] = np.copy(main_data['h'][0:data_limits[i]])
        d_tmp['z'] = np.copy(main_data['z'][0:data_limits[i]])
        data_sets.append(split_patients(d_tmp))

    true_approximation = ExactApproximator(dist)
    evaluations_data_amount = {}
    time_name = 'time'
    outcome_name = 'outcome'
    for training_data_set in data_sets:
        print("Initializing approximator")
        statistical_approximationPrior = StatisticalApproximator(n_x, n_a, n_y, training_data_set, smoothing_mode='gaussian')
        statistical_approximationNone = StatisticalApproximator(n_x, n_a, n_y, training_data_set, smoothing_mode='none')
        function_approximation = FunctionApproximation(n_x, n_a, n_y, training_data_set)

        print("Initializing Constraint")
        start = time.time()
        constraintNone = Constraint(training_data_set, n_a, n_y, approximator=statistical_approximationNone, delta=delta, epsilon=epsilon)
        constraintPrior = Constraint(training_data_set, n_a, n_y, approximator=statistical_approximationPrior, delta=delta, epsilon=epsilon)
        constraintFunc = Constraint(training_data_set, n_a, n_y, approximator=function_approximation, delta=delta, epsilon=epsilon)
        constraintTrue = Constraint(training_data_set, n_a, n_y, approximator=true_approximation, delta=delta, epsilon=epsilon)

        print("Initializing the constraint took {:.3f} seconds".format(time.time()-start))
        print("Initializing algorithms")
        algorithms = [
            ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data_set, constraintNone, statistical_approximationNone, name="CDP_U", label="CDP_U"),
            ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data_set, constraintPrior, statistical_approximationPrior, name="CDP_H", label="CDP_H"),
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