def main():
    """
    Test the trained agent
    """
    # set of different testing seeds
    test_num = [1]
    # set of different D2D FBs
    num_feedback_set = [3]
    # number of BS outputs, that is, the number of compressed global information
    num_bs_output_set = [12, 12, 16, 24]
    gamma_set = [0.05]
    # set of different batch sizes
    batch_set = [512]
    # number of different testing seeds
    num_test_settings = 1

    # number of different BS outputs and FBs
    num_BS_Out = 1

    # weight for the V2V sum rate
    v2v_weight = 1
    # weight for the V2I sum rate
    v2i_weight = 0.1

    # parameter setting for testing
    num_test_episodes = 2000
    num_test_steps = 1000
    opt_flag = False

    # start training
    for BS_loop in range(num_BS_Out):
        # run at different FB
        curr_FB = num_feedback_set[0]
        curr_BS_Output = num_bs_output_set[BS_loop]
        FB_str = '>>>>>>>>>Testing FB = ' + str(curr_FB) + ' -BS Outputs = ' + str(curr_BS_Output) \
                 + ' at different random seeds<<<<<<<<<'
        print(FB_str)

        for test_loop in range(num_test_settings):

            # set the current random seed for training
            test_seed_sequence = test_num[test_loop]
            random.seed(test_seed_sequence)
            np.random.seed(test_seed_sequence)
            tf.set_random_seed(test_seed_sequence)

            # set values for current simulation
            curr_RL_Config = RL_Config()

            train_show_tra = '----- Start the Number -- ' + str(
                test_num[test_loop]) + ' -- Testing -----!'
            print(train_show_tra)

            # set key parameters for this train
            num_feedback = num_feedback_set[0]
            gamma = gamma_set[0]
            batch_size = batch_set[0]
            num_bs_output = num_bs_output_set[BS_loop]
            curr_RL_Config.set_train_value(num_feedback, gamma, batch_size,
                                           num_bs_output, v2v_weight,
                                           v2i_weight)

            # display the parameters settings for current trained model
            curr_RL_Config.display()

            # start the Environment
            Env = start_env()

            # load the trained model
            BS_Agent = load_trained_model(Env, curr_RL_Config)

            # set key parameters for this testing
            curr_RL_Config.set_test_values(num_test_episodes, num_test_steps,
                                           opt_flag, v2v_weight, v2i_weight)

            # run the testing process and save the testing results
            save_flag = run_test(curr_RL_Config, BS_Agent, test_seed_sequence)

            # track the testing process
            if save_flag:
                print('RL Testing is finished!')
Пример #2
0
def main():
    """
    Test the trained agent
    """

    # number of different testings
    test_num = [1, 2, 3, 4, 5]
    # number of real feedback values
    num_feedback_set = [3, 2, 1, 6, 9]
    # discount factor
    gamma_set = [0.05]
    # size of mini-batch
    batch_set = [512]
    # weight for sum rate of V2V in the reward
    v2v_weight = 1
    # weight for sum rate of V2I in the reward
    v2i_weight = 0.1

    num_test_settings = 1

    # parameter setting for testing
    num_test_episodes = 200
    num_test_steps = 1000
    opt_flag = False

    robust_flag = False  # whether run robust test
    # for debugging
    # num_test_episodes = 20
    # num_test_steps = 100

    if robust_flag:
        # robust parameters setting
        feedback_interval_set = [1, 1, 1, 1, 1, 1]
        # feedback_interval_set = [1, 2, 5, 10, 20, 50]
        # input_noise_level_set = [0.05, 0.1, 0.2, 2, 10, 100]
        input_noise_level_set = [0, 0, 0, 0, 0, 0]
        # feedback_noise_level_set = [0, 0, 0, 0, 0, 0]
        feedback_noise_level_set = [0.05, 0.1, 0.2, 2, 10, 100]

    # start testing
    for test_loop in range(num_test_settings):

        # set the current random seed for testing
        test_seed_sequence = 1
        random.seed(test_seed_sequence)
        np.random.seed(test_seed_sequence)
        tf.set_random_seed(test_seed_sequence)

        # set values for current simulation
        curr_RL_Config = RL_Config()

        train_show_tra = '----- Start the Number -- ' + str(
            test_num[test_loop]) + ' -- Testing -----!'
        print(train_show_tra)

        # set key parameters for the trained model
        num_feedback = num_feedback_set[0]
        gamma = gamma_set[0]
        batch_size = batch_set[0]
        curr_RL_Config.set_key_value(num_feedback, gamma, batch_size,
                                     v2v_weight, v2i_weight)

        # display the parameters settings for current trained model
        curr_RL_Config.display()

        # start the Environment
        Env = start_env()

        # load the trained model
        BS_Agent = load_trained_model(Env, curr_RL_Config)

        if robust_flag:
            # set key values for testing
            feedback_interval = feedback_interval_set[test_loop]
            input_noise_level = input_noise_level_set[test_loop]
            feedback_noise_level = feedback_noise_level_set[test_loop]

            curr_RL_Config.set_robust_test_values(num_test_episodes,
                                                  num_test_steps, opt_flag,
                                                  v2v_weight, v2i_weight,
                                                  feedback_interval,
                                                  input_noise_level,
                                                  feedback_noise_level)

            # run the testing process and save the testing results
            save_flag = robust_run_test(curr_RL_Config, BS_Agent,
                                        test_seed_sequence)

            # track the testing process
            if save_flag:
                print('RL ROBUST Testing is finished!')

        else:
            # set key parameters for this testing
            curr_RL_Config.set_test_values(num_test_episodes, num_test_steps,
                                           opt_flag, v2v_weight, v2i_weight)

            # run the testing process and save the testing results
            save_flag = run_test(curr_RL_Config, BS_Agent, test_seed_sequence)

            # track the testing process
            if save_flag:
                print('RL Testing is finished!')
def main():
    """
    Test the trained agent
    """
    # set of different numbers of testing seeds
    test_num = [1]
    # set of different numbers of Real Feedback
    num_feedback_set = [3]
    # discount factor
    gamma_set = [0.05]
    # size of mini-batch
    batch_set = [512]
    # number of different testing seeds
    num_test_settings = 1

    # number of different BS outputs and FBs
    num_BS_Out = 1

    # weight for the V2V sum rate in the reward
    v2v_weight = 1
    # weight for the V2I sum rate in the reward
    v2i_weight = 0.1
    # evaluation exploration rate epsilon
    Fixed_Epsilon = 0
    # number of test while evaluating the training process
    num_evaluate_trials = 10
    # parameter setting for testing
    num_test_episodes = 400
    num_test_steps = 1000
    opt_flag = False

    # start evaluation
    for BS_loop in range(num_BS_Out):
        # run at different FB
        curr_FB = num_feedback_set[0]
        FB_str = '>>>>>>>>>Testing FB = ' + str(
            curr_FB) + ' at different random seeds<<<<<<<<<'
        print(FB_str)
        # start training
        for test_loop in range(num_test_settings):

            # set the current random seed for evaluating
            test_seed_sequence = test_num[test_loop]
            random.seed(test_seed_sequence)
            np.random.seed(test_seed_sequence)
            tf.set_random_seed(
                test_seed_sequence)  # random seed for tensor flow

            # set values for current simulation
            curr_RL_Config = RL_Config()

            train_show_tra = '----- Start the Number -- ' + str(
                test_num[test_loop]) + ' -- Testing -----!'
            print(train_show_tra)

            # set key parameters for this train
            num_feedback = num_feedback_set[0]
            gamma = gamma_set[0]
            batch_size = batch_set[0]

            curr_RL_Config.set_key_value(num_feedback, gamma, batch_size,
                                         v2v_weight, v2i_weight)

            # display the parameters settings for current trained model
            curr_RL_Config.display()

            # start the Environment
            Env = start_env()

            # load the trained model
            BS_Agent = load_trained_model(Env, curr_RL_Config)

            # set key parameters for this testing
            curr_RL_Config.set_test_values(num_test_episodes, num_test_steps,
                                           opt_flag, v2v_weight, v2i_weight)

            # run the testing process and save the testing results
            save_flag = run_test(curr_RL_Config, BS_Agent, test_seed_sequence,
                                 Fixed_Epsilon, num_evaluate_trials)

            # track the testing process
            if save_flag:
                print('RL Testing is finished!')