Function fidex(const std::string&)

Function Documentation

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

Executes the Fidex algorithm with specified parameters to extract an explanation rule for one or several given samples.

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 each test sample based on these hyperplanes covering this sample and as many other samples as possible.

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 failed and the ‘covering_strategy’ is on, Fidex is computed to find a rule with the max possible minimal covering that can be lower than ‘min_covering’.

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

  • Each failed attempt on lowest minimal fidelity are 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 and test datasets.

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

  • Train and test predictions are mandatory, either within the data file for test or separately through prediction file for both.

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

  • rules_outfile : File containing the obtained explanation rule for every test sample. It’s generated as a JSON if a JSON extension is specified.

  • stats_file : If specified, contains the statistics of the test set :

    1. The mean covering size per rule.

    2. The mean number of antecedents per rule.

    3. The mean rule fidelity rate.

    4. The mean rule accuracy.

    5. The mean rule confidence.

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

  • Test data files: These files can also include predictions. The format of each sample in the file will be as follows:

    • First Line: Contains data attributes. It may be followed by class information (either as an ID or in one-hot format).

    • Second Line: Contains prediction values.

    • Third Line (optional): Contains class information, only if it was not included in the first line and if present.

  • 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.fidex('--train_data_file datanorm --train_pred_file dimlp.out --train_class_file dataclass2 --test_data_file testSampleDataCombine --nb_attributes 16 --nb_classes 2 --weights_file dimlp.wts --nb_quant_levels 50 --rules_outfile rule.txt --stats_file stats --max_iterations 100 --min_covering 25 --dropout_dim 0.5 --dropout_hyp 0.5 --root_folder fidex/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.