Function densCls(const std::string&)
Defined in File densClsFct.h
Function Documentation
-
int densCls(const std::string &command = "")
Executes the Dense Classification (densCls) process with specified parameters. This function obtains train and, optionally, test predictions and accuracy for a model trained with dimlpBT. It can also perform rule extraction with the Dimlp algorithm.
The function performs the following steps:
Parses the command string to extract parameters.
Sets up the neural network and other necessary objects.
Computes the global accuracy on the training and test datasets if provided.
Saves the network’s predictions and optionally extracts rules.
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 training dataset and weights file.
The hidden layers configuration file must also be provided to specify the network architecture.
True train class labels must be provided, either within the data file or separately through a class file. Test classes are given the same way if present.
Normalization parameters can be specified to denormalize the dimlp explaining rules if data were normalized beforehand.
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:
train_pred_outfile: File containing the model’s train predictions.
test_pred_outfile: File containing the model’s test predictions.
stats_file: File containing global train accuracy and test accuracy.
global_rules_outfile: If specified and if computing rules, contains the explanation rules with statistics.
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:
Only attributes (floats).
Attributes (floats) followed by an integer class ID.
Attributes (floats) followed by one-hot encoded class.
Class files: These files should contain one class sample per line, with integers separated by spaces, tabs, semicolons, or commas. Supported formats:
Integer class ID.
One-hot encoded class.
Weights file: This file should be obtained by training with DimlpBT and not with DimlpTrn(!). Each network is separated by a “Network <id>” marker. For each network, 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 5Attributes file: Each line corresponds to one attribute, each attribute must be specified. Classes can be specified after the attributes but are not mandatory. Each attribute or class must be in one word without spaces (you can use _ to replace a space). The order is important as the first attribute/class name will represent the first attribute/class in the dataset.
Normalization file
: Each line contains the mean/median and standard deviation for an attribute.
Format: ‘2 : original mean: 0.8307, original std: 0.0425’
Attribute indices (index 2 here) can be replaced with attribute names, then an attribute file is required.
Example of how to call the function:
from dimlpfidex import dimlp
dimlp.densCls('--train_data_file datanormTrain.txt --train_class_file dataclass2Train.txt --test_data_file datanormTest.txt --test_class_file dataclass2Test.txt --nb_attributes 16 --hidden_layers_file hidden_layers.out --nb_classes 2 --weights_file dimlpDatanormBT.wts --with_rule_extraction true --global_rules_outfile globalRules.rls --train_pred_outfile predTrain.out --test_pred_outfile testPred.out --stats_file stats.txt --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.