Helper routines and functions

Those functions are not accessible and only needed for the software.

mdgru.helper._initializer_Q(k1, k2)[source]

Computes a block circulant k1xk1 matrix, consisting of circulant k2xk2 blocks.

Parameters:
  • k1 – Outer convolution filter size
  • k2 – Inner convolution filter size
Returns:

block circulant matrix with circulant blocks

mdgru.helper.argget(dt, key, default=None, keep=False, ifset=None)[source]

Evaluates function arguments.

It takes a dictionary dt and a key “key” to evaluate, if this key is contained in the dictionary. If yes, return its value. If not, return default. By default, the key and value pair are deleted from the dictionary, except if keep is set to True. ifset can be used to override the value, and it is returned instead (except if None). :param dt: dictionary to be searched :param key: location in dictionary :param default: default value if key not found in dictionary :param keep: bool, indicating if key shall remain in dictionary :param ifset: value override. :return: chosen value for key if available. Else default or ifset override.

mdgru.helper.check_if_kw_empty(class_name, kw, module_name)[source]

Prints standardised warning if an unsupported keyword argument is used for a given class

mdgru.helper.collect_parameters(cls, kw_args={})[source]

helper function to collect all parameters defined in cls’ _defaults needed for both compile arguments and define arguments :param cls: :param kw_args: :return:

mdgru.helper.compile_arguments(cls, kw, transitive=False, override_static=False, keep_entries=True)[source]

Extracts valid keywords for cls from given keywords and returns the resulting two dicts.

Parameters:
  • cls – instance or class having property or attribute “_defaults”, which is a dict of default parameters.
  • transitive – determines if parent classes should also be consulted
  • kw – the keyword dictionary to separate into valid arguments and rest
Returns:

tuple of dicts, one with extracted/copied relevant keywords and one with the rest

mdgru.helper.counter_generator(maxim)[source]

Generates indices over multidimensional ranges.

Parameters:maxim – Number of iterations per dimension
Returns:Generator yielding next iteration
mdgru.helper.define_arguments(cls, parser)[source]

Requires cls to have field _defaults! Parses all fields defined in _defaults and creates a argparse compatible structure from them. These are then appended to the parser structure.

Parameters:
  • cls – cls which contains (at least an empty) _defaults dict.
  • parser – parser to add parameters to
Returns:

parser with added parameters

mdgru.helper.deprecated(func)[source]

Decorator function to indicate through our logger that the decorated function should not be used anymore :param func: function to decorate :return: decorated function

Tries to create symlink. If it fails, it tries to remove the folder obstructing its way to create one. :param file1: path :param file2: symlink name

mdgru.helper.generate_defaults_info(cls)[source]

Adds description for keyword dict to docstring of class cls

Parameters:cls (Class to extract _defaults field from to generate additional docstring info from.) –
mdgru.helper.harmonize_filter_size(fs, ndim)[source]

Used in both model classes to set filters to their default values, given either no or incomplete input. :param fs: filters as specified :param ndim: number of dimensions :return: corrected list for filter sizes

mdgru.helper.initializer_W(n, k1, k2)[source]

Computes kronecker product between an orthogonal matrix T and a circulant orthogonal matrix Q.

Creates a block circulant matrix using the Kronecker product of a orthogonal square matrix T and a circulant orthogonal square matrix Q.

Parameters:
  • n – Number of channels
  • k1 – Outer convolution filter size
  • k2 – Inner convolution filter size
Returns:

mdgru.helper.lazy_property(function)[source]

This function computes a property or simply returns it if already computed.

mdgru.helper.notify_user(chat_id, token, message='no message')[source]

Sends a notification when training is completed or the process was killed.

Given that a telegram bot has been created, and it’s api token is known, a chat_id has been opened, and the corresponding chat_id is known, this method can be used to be informed if something happens to our process. More on telegram bots at https://telegram.org/blog/bot-revolution. :param chat_id: chat_id which is used by telegram to communicate with your bot :param token: token generated when creating your bot through the BotFather :param message: The message to be sent

mdgru.helper.np_arr_backward(matrix, n, k1, k2)[source]

Transforms from block block circulant matrix to filter representation using indices. :param matrix: matrix representation of filter :param n: number of channels :param k1: filter dim 1 :param k2: filter dim 2 :return: filter representation

mdgru.helper.np_arr_forward(filt, n, k1, k2)[source]

Transforms from filter to block block circulant matrix representation using indices. :param filt: filter variable :param n: number of channels :param k1: filter dimension 1 :param k2: filter dimension 2 :return: matrix representation of filter