Additional functions

limmbo.utils.utils.boolanize(string)[source]

Convert command line parameter “True”/”False” into boolean

Parameters:
  • string (string) –
  • or "True" ("False") –
Returns:

False/True

Return type:

(bool)

limmbo.utils.utils.generate_permutation(P, S, n, seed=12321, exclude_zero=False)[source]

Generate permutation.

Parameters:
  • seed (int) – used as seed for pseudo-random numbers generation; default: 12321
  • n (int) – number of permutations to generated
  • P (int) – total number of traits
  • S (int) – subsampling size
  • exclude_zero (bool) – should zero be in set to draw from
Returns:

Returns list of length n containing [np.arrays] of length [S] with subsets/permutations of numbers range(P)

Return type:

(list)

limmbo.utils.utils.getEigen(covMatrix, reverse=True)[source]

Get eigenvectors and values of hermitian matrix:

Parameters:
  • covMatrix (array-like) – hermitian matrix
  • reverse (bool) – if True (default): order eigenvalues (and vectors) in decreasing order
Returns:

tuple containing:

  • eigenvectors
  • eigenvalues

Return type:

(tuple)

limmbo.utils.utils.getVariance(eigenvalue)[source]

Based on input eigenvalue computes cumulative sum and normalizes to overall sum to obtain variance explained

Parameters:eigenvalue (array-like) – eigenvalues
Returns:variance explained
Return type:(float)
limmbo.utils.utils.inflate_matrix(bootstrap_traits, bootstrap, P, zeros=True)[source]

Project small matrix into large matrix using indeces provided:

Parameters:
  • bootstrap_traits (array-like) – [S x S] covariance matrix estimates
  • bootstrap (array-like) – [S x 1] array with indices to project [S x S] matrix values into [P x P] matrix
  • P (int) – total number of dimensions
  • zeros (bool) – fill void spaces in large matrix with zeros (True, default) or nans (False)
Returns:

Returns [P x P] matrix containing [S x S] matrix values at bootstrap indeces and zeros/nans elswhere

Return type:

(numpy array)

limmbo.utils.utils.match(samples_ref, data_compare, samples_compare, squarematrix=False)[source]

Match the order of data and ID matrices to a reference sample order,

Parameters:
  • samples_ref (array-like) – [M] sammple Ids used as reference
  • data_compare (array-like) – [N x L] data matrix with [N] samples and [L] columns
  • samples_compare (array-like) – [N] sample IDs to be matched to samples_ref
  • squarematrix (bool) – is data_compare a square matrix i.e. samples in cols and rows
Returns:

tuple containing:

  • data_compare (numpy array): [M x L] data matrix of input data_compare
  • samples_compare (numpy array): [M] sample IDs of input samples_compare
  • samples_before (int): number of samples in data_compare/samples_compare before matching to samples_ref
  • samples_after (int): number of samples in data_compare/samples_compare after matching to samples_ref

Return type:

(tuple)

limmbo.utils.utils.nans(shape)[source]

Create numpy array of NaNs

Parameters:shape (tuple) – shape of the empty array
Returns:numpy array of NaNs
Return type:(numpy array)
limmbo.utils.utils.regularize(m, verbose=True)[source]

Make matrix positive-semi definite by ensuring minimum eigenvalue >= 0: add absolute value of minimum eigenvalue and 1e-4 (for numerical stability of abs(min(eigenvalue) < 1e-4 to diagonal of matrix

Parameters:m (array-like) – symmetric matrix
Returns:Returns tuple containing:
  • positive, semi-definite matrix from input m (numpy array)
  • minimum eigenvalue of input m
Return type:(tuple)
limmbo.utils.utils.scale(x)[source]

Mean center and unit variance input array

Parameters:x (array-like) – array to be scaled by column
Returns:mean-centered, unit-variance array of x
Return type:(numpy array)
limmbo.utils.utils.verboseprint(message, verbose=True)[source]

Print message if verbose option is True.

Parameters:
  • message (string) – text to print
  • verbose (bool) – flag whether to print message (True) or not (False)