예제 #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
예제 #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, 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
예제 #4
0
                'data': split_patients(training_data)
            },
            'test': {
                'data': test_data
            }
        }
        n_x = dist.n_x
        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()
예제 #5
0
    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"),
            ConstrainedGreedy(n_x, n_a, n_y, training_data_set, constraintPrior, statistical_approximationPrior, name="CG_H"),
            ConstrainedDynamicProgramming(n_x, n_a, n_y, training_data_set, constraintTrue, true_approximation, name="CDP_T", label="CDP_T"),
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