superdsm.config

class superdsm.config.Config(other=None)

Bases: object

Represents a set of hyperparameters.

Hyperparameters can be worked with as follows:

cfg = superdsm.config.Config()
cfg['global-energy-minimization/beta'] = 1000
cfg['global-energy-minimization/max_iter'] = 5

A dictionary can be wrapped into a Config object by passing it to the constructor (no copying occurs). If another Config object is passed to the constructor, a deep copy is created.

copy()

Returns a deep copy.

derive(config_override)

Creates and returns an updated deep copy of this configuration.

The configuration config_override is merged into a deep copy of this configuration (see the merge() method).

Parameters:

config_override – A Config object corresponding to the configuration which is to be merged.

Returns:

The updated deep copy.

dump_json(fp)

Writes the JSON representation of this configuration.

Parameters:

fp – The file pointer where the JSON representation is to be written to.

get(key, default)

Returns the value of a hyperparameter.

Parameters:
  • key – The hyperparameter to be queried.

  • default – Returned if the hyperparameter key is not set.

Returns:

The value of the hyperparameter key or default if key is not set.

property md5

The MD5 hash code associated with the hyperparameters set in this configuration.

merge(config_override)

Updates this configuration using the hyperparameters set in another configuration.

The hyperparameters of this configuration are set to the values from config_override. If a hyperparameter was previously not set in this configuration, it is set to the value from config_override.

Parameters:

config_override – A Config object corresponding to the configuration which is to be merged.

Returns:

The updated Config object (itself).

pop(key, default)

Removes a hyperparameter from this configuration.

Parameters:
  • key – The hyperparameter to be removed.

  • default – Returned if the hyperparameter key is not set.

Returns:

The value of the hyperparameter key or default if key is not set.

set_default(key, default, override_none=False)

Sets a hyperparameter if it is not set yet.

Parameters:
  • key – The hyperparameter to be set.

  • default – Returned if the hyperparameter key is not set.

  • override_noneTrue if a hyperparameter set to None should be treated as not set.

Returns:

The value of the hyperparameter key after the method invocation is finished.

update(key, func)

Updates a hyperparameter by mapping it to a new value.

Parameters:
  • key – The hyperparameter to be set.

  • func – Function which maps the previous value to the new value.

Returns:

The new value.