Function dimlpPred(const std::string&)

Function Documentation

int dimlpPred(const std::string &command = "")

Executes the Dimlp prediction process on test set with specified parameters for a model trained with dimlpTrn.

The function performs the following steps:

  1. Parses the command string to extract parameters.

  2. Sets up the neural network and other necessary objects.

  3. Loads the weights from the provided weights file.

  4. Performs predictions on the provided test dataset.

  5. Saves the network’s predictions for the test dataset.

  6. Saves the total execution time.

Notes:

  • Each file is located with respect to the root folder dimlpfidex or to the content of the ‘root_folder’ parameter if specified.

  • It’s mandatory to specify the number of attributes and classes in the data, as well as the test dataset and weights file.

  • The hidden layers configuration file must also be provided to specify the network architecture.

  • Parameters can be defined directly via the command line or through a JSON configuration file.

  • Providing no command-line arguments or using -h/--help displays usage instructions, detailing both required and optional parameters for user guidance.

Outputs:

  • test_pred_outfile: File containing the model’s test predictions.

  • console_file: If specified, contains the console output.

File formats:

  • Data files: These files should contain one sample per line, with numbers separated either by spaces, tabs, semicolons, or commas. Supported formats:

    1. Only attributes (floats).

    2. Attributes (floats) followed by an integer class ID.

    3. Attributes (floats) followed by one-hot encoded class.

  • Weights file: This file should be obtained by training with DimlpTrn and not with DimlpBT(!). The first row represents bias values of the Dimlp layer and the second row are values of the weight matrix between the previous layer and the Dimlp layer. Each value is separated by a space. As an example, if the layers are of size 4, the biases are: b1 b2 b3 b4 and the weights are w1 w2 w3 w4.

  • Hidden layers file

    : This file contains the number of nodes in each hidden layer. In each line there is the layer id and the number of its nodes separated by a space. Ex :

    1 16

    2 5

Example of how to call the function:

from dimlpfidex import dimlp

dimlp.dimlpPred('--test_data_file datanormTest.txt --weights_file dimlpDatanorm.wts --nb_attributes 16 --hidden_layers_file hidden_layers.out --nb_classes 2 --test_pred_outfile predTest.out --root_folder dimlp/datafiles')

Parameters:

command – A single string containing either the path to a JSON configuration file with all specified arguments, or all arguments for the function formatted like command-line input. This includes file paths and options for output.

Returns:

Returns 0 for successful execution, -1 for errors encountered during the process.