if rank == 0: """ executed by main MPI process mpiexec -n <num_nodes> python -m mpi4py.futures mpi\mpi_bagging.py will create 1 dispatcher node with rank 0 and num_node-1 workers for the pool """ ## generate Training set, Test set & V_0s X_train, y_train = generate_train_set(Config.N_train, Config.Delta, Config.d) X_test, y_test = generate_test_set(Config.N_test, Config.Delta, Config.d) V_0_train = generate_V_0(Config.N_train, Config.Delta, Config.d) V_0_test = generate_V_0(Config.N_test, Config.Delta, Config.d) logger.info(f"V_0_test = {V_0_test}") reference = create_GPR(Config.N_train) reference.fit(X_train, y_train) f_X = reference.predict(X_test) reference_error = normalized_error_VT(f_X, y_test, V_0_test) logger.info(f"reference error : {reference_error}") ## MPI execute results = [] with MPIPoolExecutor() as executor: futures = []
# combine the ensemble predictions into a single prediction for each trial of each hyperparam setting # predictions = [] for result in results: predictor_results = result[2] #M* [(m_ij,s_ij)] each of len trials if SOFTVOTING: bagging_predictions = trials_soft_prediction( predictor_results, Config.trials) else: bagging_predictions = trials_hard_prediction( predictor_results, Config.trials) predictions.append([result[0], result[1], bagging_predictions]) ## compute the normalized error for all hyperparam runs & all trials V_0 = generate_V_0(100000, Config.Delta, Config.d) logger.info(f"V_0 = {V_0}") normalized_error_results = [] for result in predictions: errors = [] for index, prediction in enumerate(result[2]): error = normalized_error_VT(prediction, DataContainer.y_test_list[index], V_0) errors.append(error) normalized_error_results.append([result[0], result[1], errors]) print(normalized_error_results) if WRITEBACK: write_results("mpi_regularized_bagging", normalized_error_results, Config)