validate_params

gtda.utils.validate_params(parameters, references, exclude=None)[source]

Function to automate the validation of (hyper)parameters.

Parameters
  • parameters (dict, required) – Dictionary in which the keys parameter names (as strings) and the corresponding values are parameter values. Unless exclude (see below) contains some of the keys in this dictionary, all parameters are checked against references.

  • references (dict, required) –

    Dictionary in which the keys are parameter names (as strings). Let name and parameter denote a key-value pair in parameters. Since name should also be a key in references, let reference be the corresponding value there. Then, reference must be a dictionary containing any of the following keys:

    • 'type', mapping to a class or tuple of classes. parameter is checked to be an instance of this class or tuple of classes.

    • 'in', mapping to a dictionary, when the value of 'type' is not one of list, tuple, numpy.ndarray or dict. Letting ref_in denote that dictionary, the following check is performed: parameter in ref_in.

    • 'of', mapping to a dictionary, when the value of 'type' is one of list, tuple, numpy.ndarray or dict. Let ref_of denote that dictionary. Then:

      1. If reference['type'] == dict – meaning that parameter should be a dictionary – ref_of should have a similar structure as references, and validate_params is called recursively on (parameter, ref_of).

      2. Otherwise, ref_of should have a similar structure as reference and each entry in parameter is checked to satisfy the constraints in ref_of.

    • 'other', which should map to a callable defining custom checks on parameter.

  • exclude (list of str, or None, optional, default: None) – List of parameter names which are among the keys in parameters but should be excluded from validation. None is equivalent to passing the empty list.