decompy.utils package

Submodules

decompy.utils.bayesmethods module

decompy.utils.bayesmethods.ldxl(x, mu, sigma, ell, ln2m)
decompy.utils.bayesmethods.ln2moment(mu, s2, lmax)

The ln2moment function calculates the logarithmic moments of a log-normal distribution given the mean, variance, and maximum order.

Parameters:
  • mu – The parameter mu represents the mean of the log-normal distribution.

  • s2 – The parameter s2 represents the variance of the log-normal distribution.

  • lmax – The parameter lmax represents the maximum value of l in the calculation. It determines the

  • calculated. (number of logarithmic moments that will be) –

Return type:

The function ln2moment returns an array l2mom containing the logarithmic moments up to a given

maximum value lmax.

decompy.utils.bayesmethods.rW(kappa, m)

The function rW is a simulation of the auxilliary W variable based on the Wood (1994) method, which generates a random variable W with a specified shape parameter kappa and degrees of freedom m.

Parameters:
  • kappa – The parameter kappa represents the shape parameter of the Wood distribution. It controls the

  • distribution. (skewness of the distribution. A higher value of kappa results in a more skewed) –

  • m – The parameter m represents the degrees of freedom in the Wood (1994) simulation. It determines

  • Z. (the shape of the beta distribution used to generate the random variable) –

Return type:

The function rW returns the value of the auxilliary variable W, which is calculated using the Wood

  1. simulation method.

References

decompy.utils.bayesmethods.rXL(mu, sigma, ell, nu=1)

The rXL function is used to simulate a random variable following the XL (Extreme Lognormal) distribution.

Parameters:
  • mu – The parameter mu represents the mean of the XL random variable. It is a measure of the central

  • distribution. (spread or variability of the) –

  • sigma – The parameter sigma represents the standard deviation of the XL random variable. It measures the

  • distribution.

  • ell – The parameter “ell” represents the shape parameter of the XL random variable. It determines the shape

  • tails. (of the distribution and affects the tail behavior. A higher value of "ell" results in heavier) –

  • nu – The parameter nu represents the degrees of freedom for the t-distribution. It determines the

  • optional – The parameter nu represents the degrees of freedom for the t-distribution. It determines the

  • in (shape of the distribution and affects the tails of the distribution. Higher values of nu result) –

  • result (heavier tails and a distribution that resembles a normal distribution. Lower values of nu) –

  • tails (in lighter) –

Return type:

The function rXL returns a simulated value from the XL (Extreme Lognormal) random variable

distribution.

References

decompy.utils.bayesmethods.rmf_matrix(M: array)

The rmf_matrix function simulates a random orthonormal matrix from the von Mises-Fisher distribution using a rejection sampling method.

Parameters:
  • M (np.array) – The parameter M is a numpy array representing a matrix. The shape of M is (m, R), where m

  • matrix. (is the number of rows and R is the number of columns of the) –

Return type:

The function rmf_matrix returns a simulated random orthonormal matrix from the von Mises-Fisher

distribution.

decompy.utils.bayesmethods.rmf_vector(kmu: array)

The rmf_vector function generates a random normal vector from the von Mises-Fisher distribution given a mean direction.

Parameters:
  • kmu (np.array) – The parameter kmu is a numpy array representing the mean direction of the von Mises-Fisher

  • `(m (distribution. It is a vector of shape) –

  • )`

  • distribution. (where m is the dimensionality of the) –

Return type:

The function rmf_vector returns a random normal vector sampled from the von Mises-Fisher

distribution.

decompy.utils.constants module

decompy.utils.matrixmethods module

decompy.utils.matrixmethods.accum_cv_metric(bcvs: ndarray, metric='MSE')

The accum_cv_metric function calculates a specified metric (MSE, MAE, MAD, or L2) for a given array of cross-validation scores.

Parameters:
  • bcvs (np.ndarray) – The parameter “bcvs” is expected to be a numpy array containing the cross-validated metric scores.

  • fold (Each row of the array represents a different cross-validation) –

  • a (and each column represents) –

  • setting. (different metric score for a specific model or parameter) –

  • metric – The “metric” parameter is a string that specifies the type of metric to be used for calculating the

  • optional – The “metric” parameter is a string that specifies the type of metric to be used for calculating the

  • are (scores. The available options) –

Return type:

The function accum_cv_metric returns the calculated scores based on the input metric.

decompy.utils.matrixmethods.extract_submatrix(X: ndarray, rowmin: int, rowmax: int, colmin: int, colmax: int)

The extract_submatrix function takes a matrix X and extracts a submatrix defined by the given row and column ranges, returning four submatrices A, B, C, and D.

Parameters:
  • X (np.ndarray) – The input matrix from which the submatrix will be extracted.

  • rowmin (int) – The rowmin parameter represents the starting row index of the submatrix to be extracted.

  • rowmax (int) – The parameter rowmax represents the maximum row index of the submatrix to be extracted.

  • colmin (int) – The colmin parameter specifies the minimum column index to be included in the submatrix.

  • colmax (int) – The parameter colmax represents the maximum column index of the submatrix to be extracted.

Returns:

The function `extract_submatrix` returns four submatrices

Return type:

A, B, C, and D.

decompy.utils.matrixmethods.g_inverse(X: ndarray, rank: int = 1)

The g_inverse function performs a rank-SVD decomposition on an input matrix and returns its inverse.

Parameters:
  • X (np.ndarray) – The parameter X is a numpy array representing the input matrix for which we want to perform the

  • inverse. (SVD and) –

  • rank (int, optional) – The rank parameter specifies the number of singular values and vectors to keep in the rank-SVD

  • default (decomposition. It determines the level of approximation in the inverse calculation. By) –

  • it

  • 1 (is set to) –

  • inverse (meaning only the first singular value and vector will be used in the) –

  • calculation.

Return type:

The function g_inverse returns the inverse of the rank-SVD decomposition of the input matrix X.

decompy.utils.rootmethods module

decompy.utils.rootmethods.roots_cubic(a2, a1, a0)

The roots_cubic function calculates the roots of a cubic equation given the coefficients.

Parameters:
  • a2 – The coefficient of the cubic term in the equation.

  • a1 – The parameter a1 represents the coefficient of the linear term in the cubic equation.

  • a0 – The coefficient of the constant term in the cubic equation.

Return type:

The function roots_cubic returns an array containing the three roots of a cubic equation.

decompy.utils.rootmethods.roots_quartic(a3, a2, a1, a0)

The roots_quartic function calculates the roots of a quartic equation given its coefficients.

Parameters:
  • a3 – The parameter a3 represents the coefficient of the quartic term in the quartic equation.

  • a2 – The parameter a2 represents the coefficient of the quadratic term in the quartic equation.

  • a1 – The parameter a1 represents the coefficient of the linear term in the quartic equation.

  • a0 – The parameter a0 represents the coefficient of the constant term in the quartic equation.

Return type:

The function roots_quartic returns an array containing the four roots of the quartic equation.

decompy.utils.simmethods module

decompy.utils.simmethods.generate_LSN(n, p, r, noise=None, outlier=None)

The generate_LSN function generates a matrix X by multiplying two low rank random matrices A and B, and adding noise and outliers to the result.

Parameters:
  • n – The parameter n represents the number of rows in the generated matrix X. It determines the size

  • axis. (of the matrix along the vertical) –

  • p – The parameter p represents the number of columns in the matrix X.

  • r – The parameter r represents the rank of the matrix L. It determines the number of linearly

  • L. (independent columns in the matrix) –

  • noise – The “noise” parameter controls the amount of random noise added to the generated matrix. It is a

  • to (scalar value that determines the standard deviation of the noise. If the noise parameter is set) –

  • None

  • matrix. (no noise will be added to the) –

  • outlier – The “outlier” parameter controls the presence of outliers in the generated data. It is a value

  • the (between 0 and 1 that represents the probability of an outlier being present in each element of) –

  • 0 (data matrix. If the value is) –

  • present. (no outliers will be) –

Returns:

The function `generate_LSN` returns a matrix `X` which is the sum of three components

Return type:

L, S,

and N.

decompy.utils.validations module

decompy.utils.validations.check_binary_matrix(X: ndarray)

The function checks if a given numpy array is a binary matrix.

Parameters:
  • X (np.ndarray) – a numpy array representing a binary matrix. The function check_binary_matrix checks if the input

  • conditions (matrix satisfies the following) –

decompy.utils.validations.check_real_matrix(X: ndarray)

The function checks if the input is a real matrix in the form of a numpy array.

Parameters:

X (np.ndarray) – a numpy array that represents a matrix.

decompy.utils.validations.is_decreasing(a)

The function checks if all elements in a given array are in decreasing order.

Parameters:
  • a – The parameter a is a one-dimensional numpy array of numbers. The function is_decreasing checks

  • order (if the elements in the array are in decreasing) –

  • or (meaning that each element is greater than) –

  • is (equal to the element that comes after it. The function returns True if the array) –

Return type:

The function is_decreasing(a) returns a boolean value indicating whether the input array a is

in decreasing order or not. If a is in decreasing order, the function returns True, otherwise it returns False.

decompy.utils.validations.is_increasing(a)

The function checks if a given array is in increasing order.

Parameters:
  • a – a is a one-dimensional numpy array containing a sequence of numbers. The function is_increasing

  • increasing (checks if the sequence is strictly) –

  • greater (meaning that each element in the sequence is) –

  • and (than the previous element. The function returns True if the sequence is strictly increasing) –

  • otherwise. (False) –

Return type:

The function is_increasing(a) returns a boolean value indicating whether the input array a is

increasing or not. It returns True if all the elements in the array are in increasing order, and False otherwise.

Module contents