Function fidexGloRules(const std::string&)

Function Documentation

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

Executes the FidexGloRules algorithm with specified parameters to extract a ruleset from a dataset of training samples.

FidexGloRules computes a rule for each training sample by calling Fidex. Fidex is based on the training samples and hyperlocus and directed by the given parameters, including dropout and the maximum number of iterations allowed. It works by identifying hyperplanes in the feature space that discriminate between different classes of samples and constructing a rule for the training sample based on these hyperplanes covering this sample and as many other training samples as possible. Then, a heuristic is used to remove the duplicated and unnecessary rules.

The Fidex algorithm is computed until a rule is created or until the max failed attempts limit is reached.

  • First attempt to generate a rule with a covering greater or equal to ‘min_covering’ and a fidelity greater or equal to ‘min_fidelity’.

  • If the attempt fails and the ‘covering_strategy’ is on, Fidex is computed to find a rule with the maximum possible minimal covering that can be lower than ‘min_covering’.

  • If all attempts fail, the targeted fidelity is gradually lowered until it succeeds or ‘lowest_min_fidelity’ is reached.

  • Each failed attempt at the lowest minimal fidelity is counted.

  • If the max failed attempts limit is reached, then the rule couldn’t be computed for this sample.

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 train dataset.

  • True train class labels must be provided, either within the data file or separately through a class file.

  • Train predictions are also mandatory.

  • A heuristic needs to be chosen; the first one should always be chosen if the execution time permits it.

  • The weights file or rules_file (when training with decision trees) obtained from the model training must be provided.

  • The path of the file containing the computed rules must be provided. It can be generated as a JSON if a JSON extension is specified.

  • Normalization parameters can be specified to denormalize the 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:

  • global_rules_outfile : File containing the obtained global explanation rule for train set. It’s generated as a JSON if a JSON extension is specified.

  • 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.

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

    1. Integer class ID.

    2. One-hot encoded class.

  • Prediction files: These files should contain one line per data sample, each line consisting of a series of numerical values separated by a space, a comma (CSV), a semicolon (;), or a tab representing the prediction scores for each class.

  • Weights file: This file should be obtained by training with Dimlp, SVM, MLP, or a CNN from dimlpfidex because an additional special Dimlp layer is needed. If the training was made with more than one network, each network is separated by a “Network <id>” marker. 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.

  • Rule file: This file should be obtained directly by training with Random Forests or Gradient Boosting from dimlpfidex because rules need to be extracted from the trees.

  • Attributes 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 fidex

fidex.fidexGloRules('--train_data_file datanormTrain.txt --train_pred_file predTrain.out --train_class_file dataclass2Train.txt --weights_file weights.wts --nb_attributes 16 --nb_classes 2 --heuristic 1 --global_rules_outfile globalRules.rls --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, Fidex parameters, and options for output.

Returns:

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