magmap.settings.grid_search_prof module#

Profile settings for grid search hyperparameter tuning.

class magmap.settings.grid_search_prof.GridSearchProfile(*args, **kwargs)[source]#

Bases: SettingsDict

Grid search profile dictionary.

This profile is used to set up combinations of parameter values for hyperparameter tuning in a grid search. Hyperparameter dictionaries are in the format:

{
    hyperparam1: [param1_val1, param1_val2, ...],
    hyperparm2: [param2_val1, param2_val2, ...],
    ...
}
PATH_PREFIX: str = 'grid'#

Prefix for grid search profile files.

static get_files(profiles_dir=None, filename_prefix=None)[source]#

Get grid search profile files.

Parameters:
  • profiles_dir (str) – Directory from which to get files; defaults to None.

  • filename_prefix (str) – Only get files starting with this string; defaults to None to use PATH_PREFIX.

Returns:

List of files in profiles_dir matching the given filename_prefix.

Return type:

List[str]

hyperparams: OrderedDict[str, Sequence[float]]#

Ordered dictionary of hyperparameters, which should consist of key-pairs in the format: <ROIProfile-key>: <seq-of-param-vals>.

profiles: OrderedDict[str, Dict[str, OrderedDict[str, Sequence[float]]]]#

Profiles as collections of pre-defined hyperparameters in an ordered dict. Keys are the names of each group. Each group contains a dict with a “hyperparams” key to another ordered dict with hyperparameters as defined by hyperparams.

magmap.settings.grid_search_prof.make_hyperparm_arr(start, stop, num_steps, num_col, coli, base=1)[source]#

Make a hyperparameter 2D array that varies across the first axis for the given index.

The 2D array is used for grid searches, where each row is given as a parameter. Each parameter is a 1D array with the same values except at a given index, which varies across these 1D arrays. The varying values are constructed by np.linspace().

Parameters:
  • start (int, float) – Starting value for varying parameter.

  • stop (int, float) – Ending value for varying parameter, inclusive.

  • num_steps (int) – Number of steps from start to stop, which determines the number of rows in the output array.

  • num_col (int) – Number of columns in the output array.

  • coli (int) – Index of column to vary.

  • base (int, float) – All values are set to this number except for the varying values.

Returns:

2D array in the format [[start, base, base, ...], [start0, base, base, ...], ...].

Return type:

np.ndarray