def run_basic_agent():
    """
    Runs the basic agent program.
    :return:
    """
    # Retrieve data from CSV file and encode it.
    data = None
    if config.csv_file == "tickets":
        data = DataProcessor(config.csv_file)
    elif config.csv_file == "AND_gate":
        data = DataProcessor("AND_gate")
    elif config.csv_file == "OR_gate":
        data = DataProcessor("OR_gate")
    else:
        print("CSV file {} could not be found, please check spelling.")
        exit(1)
    encode_data(data)

    # Run Grid Search algorithm to determine optimal hyperparameters for the neural network.
    if config.is_grid_search:
        gs = GridSearch(data.input_data_encoded, data.target_data_encoded)
        run_grid_search(gs)
    # Train and test the neural network based on the chosen data.
    else:
        mlp = create_multi_layer_perceptron(data)
        start_time = time.time()  # Start measuring runtime.
        run_multi_layer_perceptron(mlp)
        print_runtime("Training", round(time.time() - start_time,
                                        2))  # Record and print runtime.
    def run_grid_search(self):
        """
        Runs the grid search algorithm, testing every possible combination in the grid_search_params dictionnary.
        Measures runtime as well.
        :return: None.
        """
        start_time = time.time()  # Start measuring runtime.

        # Run Grid Search using all possible combinations in grid_search_params.
        self.grid_search.fit(self.X_train, self.y_train)

        print_runtime("Grid Search", round(time.time() - start_time,
                                           2))  # Record and print runtime.
def train_classification_models(X, y, ground_truth) -> None:
    """

    :param X:
    :param y:
    :param ground_truth:
    :return:
    """
    # Start recording time.
    start_time = time.time()

    # Create classifier model instance.
    Classifier(config.model, X, y, ground_truth)

    # Print training runtime.
    print_runtime(round(time.time() - start_time, 2))
def run_advanced_agent():
    """
    Runs the basic agent program.
    :return:
    """
    # Retrieve data from CSV file and encode it.
    data = DataProcessor(config.csv_file)
    encode_data(data)

    mlp = MultiLayerPerceptron(
        classifier_model="dt",
        name=config.csv_file,
        input_data=data.input_data_encoded,
        target_data=data.target_data_encoded,
    )
    start_time = time.time()  # Start measuring runtime.
    run_multi_layer_perceptron(mlp)
    print_runtime("Training", round(time.time() - start_time,
                                    2))  # Record and print runtime.
def main() -> None:
    """
    Program entry point. Parses command line arguments to decide which agent to run.
    :return: None
    """
    parse_command_line_arguments()

    if config.verbose_mode:
        print("Verbose mode: ON\n")

    # Make final predictions on X_test.csv (produce 'Y_test.csv' for practical submission).
    if config.section == "test":
        X_test = load_testing_data()

        # Run this once to save the CSV files imported into DFs in PKL format for quicker loading times.
        # save_df_to_pickle(X_test, config.dataset, "X_test")

        make_final_test_predictions(X_test)

    # Explore and train the classifiers.
    else:
        X_train, y_train = load_training_data()

        # Run this once to save the CSV files imported into DFs in PKL format for quicker loading times.
        # save_df_to_pickle(X_train, config.dataset, "X_train")
        # save_df_to_pickle(y_train, config.dataset, "y_train")

        # Visualise data.
        if config.section == "data_vis":
            start_time = time.time()
            # Split training dataset's features in 3 distinct DFs.
            X_train_HoG, X_train_normal_dist, X_train_colour_hists = split_features(
                X_train)
            # Visualise data.
            data_overview(X_train)
            visualise_hog(X_train_HoG)
            visualise_rgb_hist(X_train_colour_hists)
            visualise_class_distribution(y_train)
            visualise_correlation(X_train, y_train)
            print_runtime(round(time.time() - start_time, 2))

        # Train classification models.
        elif config.section == "train":

            # Over sample binary dataset.
            if config.dataset == "binary":
                X_train, y_train = over_sample(X_train, y_train)

            # Run this once to save the CSV files imported into DFs in PKL format for quicker loading times.
            # save_df_to_pickle(X_train_resampled, config.dataset, "X_train_resampled")
            # save_df_to_pickle(y_train_resampled, config.dataset, "Y_train_resampled")
            if config.verbose_mode:
                visualise_class_distribution(y_train)

            X = input_preparation(X_train)
            y, ground_truth = output_preparation(y_train)
            if config.section == "train":
                train_classification_models(X, y, ground_truth)

        else:
            print_error_message()