atm.utilities module

Functions

base_64_to_object(b64str)

Inverse of object_to_base_64.

ensure_directory(directory)

Create directory if it doesn’t exist.

get_instance(class_, **kwargs)

Create an instance of the given class with required kwargs.

hash_dict(dictionary[, ignored_keys])

Hash a python dictionary to a hexadecimal string.

hash_nested_tuple(tup)

Hash a nested tuple to hexadecimal

hash_string(s)

Hash a string to hexadecimal

load_metrics(classifier, metrics_dir)

Load the performance metrics for a particular classifier

load_model(classifier, models_dir)

Load the Model object for a particular classifier

make_save_path(dir, classifier, suffix)

Generate the base save path for a classifier’s model and metrics files, based on the classifier’s dataset name and hyperparameters.

obj_has_method(obj, method)

http://stackoverflow.com/questions/34439/finding-what-methods-an-object-has

object_to_base_64(obj)

Pickle and base64-encode an object.

params_to_vectors(params, tunables)

Converts a list of parameter vectors (with metadata) into a numpy array ready for BTB tuning.

save_metrics(classifier, metrics_dir, metrics)

Save a JSON-serialized version of a set of performance metrics for a particular classifier.

save_model(classifier, models_dir, model)

Save a serialized version of a Model object for a particular classifier.

update_params(params, categoricals, constants)

Update params with categoricals and constants for the fitting proces.

atm.utilities.base_64_to_object(b64str)[source]

Inverse of object_to_base_64. Decode base64-encoded string and then unpickle it.

atm.utilities.ensure_directory(directory)[source]

Create directory if it doesn’t exist.

atm.utilities.get_instance(class_, **kwargs)[source]

Create an instance of the given class with required kwargs.

The exact keyword arguments that the given class_ expects will be taken from kwargs and the rest will be ignored.

Parameters
  • class_ (type) – class to instantiate

  • **kwargs – keyword arguments

Returns

instance of specific class with the args that accepts.

atm.utilities.hash_dict(dictionary, ignored_keys=None)[source]

Hash a python dictionary to a hexadecimal string. http://stackoverflow.com/questions/5884066/hashing-a-python-dictionary

atm.utilities.hash_nested_tuple(tup)[source]

Hash a nested tuple to hexadecimal

atm.utilities.hash_string(s)[source]

Hash a string to hexadecimal

atm.utilities.load_metrics(classifier, metrics_dir)[source]

Load the performance metrics for a particular classifier

atm.utilities.load_model(classifier, models_dir)[source]

Load the Model object for a particular classifier

atm.utilities.make_save_path(dir, classifier, suffix)[source]

Generate the base save path for a classifier’s model and metrics files, based on the classifier’s dataset name and hyperparameters.

atm.utilities.obj_has_method(obj, method)[source]

http://stackoverflow.com/questions/34439/finding-what-methods-an-object-has

atm.utilities.object_to_base_64(obj)[source]

Pickle and base64-encode an object.

atm.utilities.params_to_vectors(params, tunables)[source]

Converts a list of parameter vectors (with metadata) into a numpy array ready for BTB tuning.

Parameters
  • params – list of hyperparameter vectors. Each vector is a dict mapping the names of parameters to those parameters’ values.

  • tunables – list of HyperParameter metadata structures describing all the optimizable hyperparameters that should be in each vector. e.g.

  • = [ (tunables) – (‘degree’, HyperParameter(‘int’, (2, 4))), (‘gamma’, HyperParameter(‘float_exp’, (1e-05, 1e5)))]

Returns

np.array of parameter vectors ready to be optimized by a

Gaussian Process (or what have you). vectors.shape = (len(params), len(tunables))

Return type

vectors

atm.utilities.save_metrics(classifier, metrics_dir, metrics)[source]

Save a JSON-serialized version of a set of performance metrics for a particular classifier. The metrics will be stored at a path generated from the classifier’s attributes.

atm.utilities.save_model(classifier, models_dir, model)[source]

Save a serialized version of a Model object for a particular classifier. The object will be stored at a path generated from the classifier’s attributes.

atm.utilities.update_params(params, categoricals, constants)[source]

Update params with categoricals and constants for the fitting proces.

params: params proposed by the tuner

Examples of the format for SVM sigmoid hyperpartition:

categoricals = ((‘kernel’, ‘poly’),

(‘probability’, True), (‘_scale’, True))

constants = [(‘cache_size’, 15000)]