superdsm.config
- class superdsm.config.Config(other=None)
Bases:
objectRepresents 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
Configobject by passing it to the constructor (no copying occurs). If anotherConfigobject 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_overrideis merged into a deep copy of this configuration (see themerge()method).- Parameters:
config_override – A
Configobject 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
keyis not set.
- Returns:
The value of the hyperparameter
keyordefaultifkeyis 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 fromconfig_override.
- pop(key, default)
Removes a hyperparameter from this configuration.
- Parameters:
key – The hyperparameter to be removed.
default – Returned if the hyperparameter
keyis not set.
- Returns:
The value of the hyperparameter
keyordefaultifkeyis 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
keyis not set.override_none –
Trueif a hyperparameter set toNoneshould be treated as not set.
- Returns:
The value of the hyperparameter
keyafter 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.