Пример #1
0
def plot_EM_results():
    # 绘制测试结果图像
    from param_options import args_parser
    from plot_indexes_resluts import plot_indicator_results
    from util_tools import mkdir

    args = args_parser()
    args.dataset_path = './constructed_datasets_6_30(1)/'
    exp_name = 'EM'
    result_save_file = './results/' + exp_name + '/'
    plots_file = './plot_results/' + exp_name + '/'

    print(
        '====================== Save every component indicator result ========================'
    )
    for indicator in ['rmse', 'd2', 'r2']:
        print('{} results'.format(indicator))
        fig_save_path = plots_file + indicator + '/'
        mkdir(fig_save_path)
        for component in args.select_dim:
            results_logdir = [result_save_file + indicator + '/']
            plot_indicator_results(results_logdir,
                                   fig_save_path,
                                   component,
                                   xaxis='station',
                                   leg=['EM'])

    print(">>> Finished save resluts figures!")
Пример #2
0
def plot_datasets():
    # a = np.array([[1, 2, 3], [6, 9, 7]])
    # b = np.array([[7, 4, 6], [1, 6, 7]])
    # c = np.array([[6, 7, 1], [6, 2, 5]])
    # l = [a, b, c]
    # d = np.array(l)
    # print('d: ', d)

    from param_options import args_parser
    from plot_indexes_resluts import plot_all_datasets
    from loadDatasets import get_saved_datasets

    args = args_parser()
    args.dataset_path = './constructed_datasets_6_dn(10_SI2)/'
    all_station_datasets = get_saved_datasets(args)
    plot_all_datasets(all_station_datasets, args.select_dim,
                      args.selected_stations, args.dataset_path)
Пример #3
0
def plot_all_rmse_test():
    from param_options import args_parser
    from plot_indexes_resluts import plot_indicator_results

    args = args_parser()
    # 做实验
    exp_time = 5
    exp_name = 'FedWeightAvg(load_numbers_soft)_(5-1)_dn(10)_100_32(lrS_Adam_Fed_0.001_100_0.001_100_bs_128)_32'
    result_save_file = './results/' + exp_name + '/'
    indicator = 'all_rmse'

    # 绘制测试结果图像
    print(
        '====================== Save every component indicator result ========================'
    )

    results_logdir = [
        result_save_file + indicator + '/' + model_name + '/'
        for model_name in ['fed', 'idpt']
    ]
    fig_save_path = result_save_file + indicator + '/'
    plot_indicator_results(results_logdir, fig_save_path, 'all_rmse')
Пример #4
0
def plot_federated_indicator_avg_results(dataset_number):
    args = args_parser()
    # dataset_number = 'one_mi_v1((A5)_1)'

    results_saved_file = 'results_one_dn'
    results_plot_file = 'plot_results_one_dn'
    exp_name = '{}_latest'.format(dataset_number, )

    result_save_root = './{}/'.format(results_saved_file) + exp_name + '/'
    plots_save_root = './{}/'.format(results_plot_file) + exp_name + '/'
    indicator_name = 'all_rmse'
    leg = ['Fed', 'Independent']

    results_logdir = [
        result_save_root + 'avg_' + indicator_name + '/' + model_name + '/'
        for model_name in leg
    ]
    fig_save_path = plots_save_root + indicator_name + '/'
    csv_save_fpth = result_save_root + 'avg_' + indicator_name + '/'
    mkdir(fig_save_path)

    # 将每个数据集计算的均值再计算总的均值和绘制方差均值线图
    plot_indicator_avg_results_m(results_logdir, fig_save_path, 'station',
                                 indicator_name, csv_save_fpth)
Пример #5
0
                       test_x=testX,
                       train_m=trainM,
                       test_m=testM,
                       min_val=Min_val,
                       max_val=Max_val,
                       train_no=Train_No,
                       test_no=Test_No)
        all_data_list.append(dataset)

    return all_data_list


if __name__ == '__main__':
    from param_options import args_parser

    args = args_parser()
    exp_num = 5

    generate_condition = 'one_time'  # general /  one_time / missing_rate
    dataset_name_temp = '(A5_A10_A15)_nCO_321r'

    params_test_list = []
    test_param_name = None

    if generate_condition == 'missing_rate':
        params_test_list = [5, 10, 15, 20, 25, 30, 35, 40]
        test_param_name = 'missing_rate'
        Dname_prefix = '(A{})'
        Dname_suffix = 'norm_1r_1P'
    elif generate_condition == 'one_time':
        params_test_list = [1]
Пример #6
0
        plot_indicator_avg_results_m(results_logdir,
                                     fig_save_path,
                                     'station',
                                     indicator_name,
                                     csv_save_fpth,
                                     select_dim=arg.select_dim)
        # plot_fed_avg_acc(results_logdir, indicator_name, fig_save_path)
        # plot_indicator_results(results_logdir, fig_save_path, indicator_name)

        print(
            "\033[0;34;40m >>>[Visulize] Finished save {} resluts figures! \033[0m"
            .format(indicator_name))


if __name__ == '__main__':
    arg = args_parser()

    # 做实验
    exp_total_time = 1
    cross_validation_set_num = 5

    result_saved_file = 'Fed_wGAN_results'
    result_plot_file = 'Fed_wGAN_plot_results_test'

    indicator_list = ['rmse', 'd2', 'r2', 'all_rmse']

    # params_test_list = [0.9]
    # test_param_name = 'p_hint'

    # 训练模式,是训练一次还是根据不同的参数训练多次
    training_model = 'One_time'  # Many_time / One_time
Пример #7
0
def run_multi_cross_validation_datasets_test():
    """
    用于计算每个数据集的学习训练测试结果的总学习测试结果的平均
    :return:
    """

    args = args_parser()

    # 做实验
    exp_total_time = 10
    cross_validation_sets = 5
    exp_name = 'FedWeightAvg(soft)_6_dn(15)_100_32(0.001_0.001_bs_128)_32(phint_0.95)'

    indicator_list = ['rmse', 'd2', 'r2', 'all_rmse']

    # for i in range(cross_validation_sets):
    #     print('============= Start training at datasets {} =============='.format(i))
    #     # 用于统计各种指标,建立相对应的文件夹
    #     result_save_file = './results_v2/' + exp_name + '/datasets_{}/'.format(i)
    #     plots_file = './plot_results/' + exp_name + '/datasets_{}/'.format(i)
    #     for exp_t in range(exp_total_time):
    #         # 当前数据集
    #         args.dataset_path = './constructed_datasets_6_dn(5)/{}/'.format(i)
    #         fed_gain_test_exp(args, result_save_file, i)

    # print('>>> Finished training & testing!')
    result_save_root = './results_v3/' + exp_name + '/'
    plots_save_root = './plot_results/' + exp_name + '/'
    indicator_name = 'all_rmse'
    leg = ['Fed', 'Independent']
    '''
    # 建立保存结果的文件夹
    indicator_results_csv_save_fpth = result_save_root + indicator_name + '/'
    for mode in leg:
        mkdir(indicator_results_csv_save_fpth+mode+'/')

    # 计算每个数据集的几次实验的均值
    for c in range(cross_validation_sets):
        results_logdir = [result_save_root + 'datasets_' + str(c) + '/' + indicator_name + '/' + model_name + '/'
                          for model_name in ['fed', 'idpt']]

        compute_avg_of_data_in_file(args, c, results_logdir, indicator_results_csv_save_fpth,
                                    indicator_name)
    '''
    # 绘制测试结果图像
    print(
        '====================== Save every component indicator result ========================'
    )

    print('{} results'.format(indicator_name))

    results_logdir = [
        result_save_root + indicator_name + '/' + model_name + '/'
        for model_name in leg
    ]
    fig_save_path = plots_save_root + indicator_name + '/'
    csv_save_fpth = result_save_root + indicator_name + '/'
    mkdir(fig_save_path)

    # 计算几次实验的最后的平均值并画出均值和方差曲线图
    plot_indicator_avg_results_m(results_logdir, fig_save_path, 'station',
                                 indicator_name, csv_save_fpth)
    # plot_indicator_results(results_logdir, fig_save_path, indicator_name)

    print(">>> Finished save resluts figures!")