decompy.interfaces package

Submodules

decompy.interfaces.lsnresult module

class decompy.interfaces.lsnresult.LSNResult(L: ndarray, S: ndarray | None = None, N: ndarray | None = None, **kwargs)

Bases: object

The LSNResult class is a structure for holding the matrix decomposition in form of a low rank matrix L, a sparse matrix S and a small perturbation noise matrix N.

Parameters:
  • L (np.ndarray) – a numpy ndarray representing the low rank matrix

  • S (np.ndarray) – a sparse matrix that represents the sparse component of a given matrix. This is an optional parameter. If provided, it should be a 2D numpy

  • L. (array with the same shape as the low rank matrix) –

  • N (np.ndarray) – The noise perturbation matrix, which is an optional parameter. If provided, it should be a 2D numpy

  • L.

metrics

a python dictionary object to hold arbitrary values related to convergence metrics of the relevant algorithm

Type:

dict

convergence_metrics()

This function returns the convergence metrics from a dictionary called “metrics”.

Return type:

The method convergence_metrics is returning the value of the key “convergence” from the metrics

dictionary attribute of the object.

cumulative_variance(type: Literal['identity', 'proportion'] = 'identity', threshold: float = 1e-05)

The function calculates the cumulative variance of singular values and returns either the cumulative sum or proportion based on the specified type.

Parameters:
  • type (Literal["identity", "proportion"], optional) – The type parameter is a string literal that specifies the type of cumulative variance to be

  • values (calculated. It can take two possible) –

  • selected (the function returns the cumulative sum of the singular values. If "proportion" is) –

  • function (the) –

  • values. (returns the cumulative proportion of variance explained by the singular) –

  • threshold (float) – The threshold parameter is a float value that is used to set any singular values that are smaller

  • that (than the threshold to zero. This is done to remove any noise or small variations in the data) –

  • 1e-5 (may not be significant. The default value for threshold is) –

  • singular (which means that any) –

Return type:

a numpy array containing the cumulative sum of the singular values of a matrix, either as an

identity or as a proportion of the total sum of singular values. The type of output is determined by the type parameter, which can be either “identity” or “proportion”. If the type parameter is not one of these two options, a ValueError is raised. The function

estimated_rank(threshold: float = 1e-05)

The function calculates the estimated rank of a matrix based on its singular values.

Parameters:
  • threshold (float) – The threshold parameter is a float value that is used to determine the minimum value of singular

  • below (values that will be considered in the calculation of the estimated rank. Any singular value) –

  • The (this threshold will be considered as zero and will not be included in the rank calculation.) –

  • 1e-5 (default value of the threshold is) –

Return type:

The function estimated_rank returns the estimated rank of the matrix represented by the instance

of the SVD class. The estimated rank is calculated as the number of singular values that are greater than or equal to the specified threshold value. The function returns an integer value representing the estimated rank.

singular_values(as_matrix: bool = True)

This function computes the singular values of a matrix and returns them either as a diagonal matrix or a 1D array.

Parameters:
  • as_matrix (a diagonal matrix with the singular values on the diagonal) or as a 1D array. If) – A boolean parameter that specifies whether the singular values should be returned as a matrix

  • (i.e.

  • as_matrix

  • True (is) –

  • False (the function returns the singular values as a matrix. If as_matrix is) –

  • function (the) –

  • vector. (returns the singular values as a) –

Return type:

The function singular_values returns the singular values of the matrix self.L. If the parameter

as_matrix is set to True, it returns a diagonal matrix with the singular values on the diagonal. If as_matrix is set to False, it returns a 1D array with the singular values.

singular_vectors(type: Literal['left', 'right', 'both'] = 'left')

The function returns the left, right, or both singular vectors of a given matrix using the SVD method in numpy.

Parameters:
  • type (Literal["left", "right", "both"], optional) – The type parameter is a string literal that specifies which singular vectors to return. It can

  • values (take one of three) –

  • specified (If "both" is) –

  • returned. (only the right singular vectors (V) are) –

  • specified

  • tuple (both singular values (U and V) are returned as a) –

Return type:

The function singular_vectors returns the left singular vectors, right singular vectors, or both

depending on the value of the type parameter. If type is “left”, the function returns the left singular vectors (matrix U), if type is “right”, the function returns the right singular vectors (matrix V), and if type is “both”, the function returns both

decompy.interfaces.pcaresult module

class decompy.interfaces.pcaresult.PCAResult(loc: ndarray, eval: ndarray, evec: ndarray, **kwargs)

Bases: object

The PCAResult class is a structure for holding the matrix decomposition in form of location and the principal components.

Parameters:
  • loc (np.ndarray) – a numpy array representing the location of a point in space

  • eval (np.ndarray) – A 1-dimensional numpy array representing the eigenvalues of a matrix.

  • evec (np.ndarray) – evec is a 2D numpy array representing the eigenvectors of a matrix. Each column of the array represents an eigenvector.

metrics

a python dictionary object to hold arbitrary values related to convergence metrics of the relevant algorithm

Type:

dict

convergence_metrics()

This function returns the convergence metrics from a dictionary called “metrics”.

Return type:

The method convergence_metrics is returning the value of the key “convergence” from the metrics

dictionary attribute of the object.

cumulative_variance(type: Literal['identity', 'proportion'] = 'identity', threshold: float = 1e-05)

The function calculates the cumulative variance of eigenvalues and returns either the cumulative sum of squared eigenvalues or the proportion of the cumulative sum of squared eigenvalues.

Parameters:
  • type (Literal["identity", "proportion"], optional) – The type parameter is a string literal that specifies the type of cumulative variance to be

  • values (calculated. It can take two possible) –

  • selected (the function returns the cumulative sum of the squared eigenvalues. If "proportion" is) –

  • function (the) –

  • eigenvalues. (returns the cumulative proportion of variances explained by the) –

  • threshold (float) – The threshold parameter is a float value that is used to filter out small eigenvalues. Any

  • and (eigenvalue smaller than the threshold value will be set to zero. This is done to remove noise) –

  • variance. (numerical instability in the calculation of the cumulative) –

Return type:

a numpy array containing the cumulative sum of the squared eigenvalues of the matrix, either as an

“identity” or “proportion” type. If “identity” is chosen, the function returns the cumulative sum of the squared eigenvalues. If “proportion” is chosen, the function returns the cumulative sum of the squared eigenvalues divided by the sum of all squared eigenvalues.

eigen_values(as_matrix: bool = True)

The function returns either the diagonal matrix of eigenvalues or the number of eigenvalues of a given matrix.

Parameters:
  • as_matrix (bool, optional) – A boolean parameter that determines whether the eigenvalues should be returned as a matrix or a 1D

  • True (array. If as_matrix is) –

  • matrix (the eigenvalues will be returned as a diagonal) –

  • the (where) –

  • False (diagonal elements are the eigenvalues. If as_matrix is) –

:param :

Return type:

If as_matrix is True, the function returns a diagonal matrix of the eigenvalues of the object

self. If as_matrix is False, the function returns the number of eigenvalues of the object self.

eigen_vectors()

The function returns the eigenvectors of the PCAResult.

Return type:

The function eigen_vectors is returning the attribute evec of the object.

estimated_rank(threshold: float = 1e-05)

The function calculates the estimated rank of a matrix based on its eigenvalues.

Parameters:
  • threshold (float) – The threshold parameter is a float value that is used to determine the minimum value of eigenvalues

  • this (that will be considered in the calculation of the estimated rank. Any eigenvalue below) –

  • The (threshold will be considered as zero and will not be included in the calculation of the rank.) –

  • 1e-5 (default value of the threshold is) –

Return type:

The function estimated_rank returns the estimated rank of the matrix based on the eigenvalues. It

counts the number of eigenvalues that are greater than or equal to the threshold value (default is 1e-5) and returns that count as the estimated rank.

location()

The function returns a flattened version of the “loc” attribute of the PCAResult.

Return type:

The location method is returning a flattened version of the loc attribute of the object. The

reshape(-1) method is used to convert the loc attribute into a one-dimensional array.

decompy.interfaces.rankfactorresult module

class decompy.interfaces.rankfactorresult.RankFactorizationResult(A: ndarray, B: ndarray, **kwargs)

Bases: object

The RankFactorizationResult class is a structure for holding the matrix decomposition in form of rank factorization.

Parameters:
  • A (np.ndarray) – A is a numpy ndarray representing a matrix with 2 dimensions. It is the first of the rank factorized pair

  • B (np.ndarray) – The parameter B is a numpy ndarray representing a matrix. The assert statements in the code ensure

  • matrix (that B has two dimensions and that its second dimension matches the second dimension of the) –

  • A.

metrics

a python dictionary object to hold arbitrary values related to convergence metrics of the relevant algorithm

Type:

dict

convergence_metrics()

This function returns the convergence metrics from a dictionary called “metrics”.

Return type:

The method convergence_metrics is returning the value of the key “convergence” from the metrics

dictionary attribute of the object.

cumulative_variance(type: Literal['identity', 'proportion'] = 'identity')

The function calculates the cumulative variance of a matrix’s singular values and returns either the cumulative sum or proportion of the singular values based on the specified type.

Parameters:
  • type (Literal["identity", "proportion"], optional) – The type parameter is a string literal that specifies the type of cumulative variance to be

  • values (calculated. It can take two possible) –

  • function (the function returns the cumulative sum of the singular values. If "proportion" is selected the) –

  • values. (returns the cumulative proportion of the variance explained by the singular) –

Return type:

a numpy array containing the cumulative sum of the singular values of a matrix. The type of

cumulative sum returned can be either “identity” or “proportion”, depending on the argument passed to the function. If “identity” is passed, the function returns the cumulative sum of the singular values. If “proportion” is passed, the function returns the cumulative proportion of the singular values

estimated_rank()

This function returns the rank of the result matrix decomposition.

Return type:

the rank of the result matrix decomposition.

singular_values(as_matrix: bool = True)

This function computes the singular values of a matrix product and returns them either as a diagonal matrix or a list.

Parameters:
  • as_matrix (a diagonal matrix with the singular values on the diagonal) or as a 1D array. If) – A boolean parameter that specifies whether the singular values should be returned as a matrix

  • (i.e.

  • as_matrix

  • True (is) –

  • `as (the function returns the singular values as a matrix. If) –

Return type:

The function singular_values returns the singular values of the matrix product A @ B.T of the

MatrixFactorization object. The singular values are computed using the numpy.linalg.svd function. The function returns either a diagonal matrix of singular values (if as_matrix is True) or a 1D array of singular values (if as_matrix is

singular_vectors(type: Literal['left', 'right', 'both'] = 'left')

The function computes the singular vectors of a matrix product and returns either the left, right, or both singular vectors depending on the specified type.

Parameters:
  • type (Literal["left", "right", "both"], optional) – The type parameter is a string literal that specifies which singular vectors to return. It can

  • values (take one of three) –

  • specified (vectors are returned. If "right" is) –

  • right (only the) –

Return type:

The function singular_vectors returns either the left singular vector U, the right singular

vector V, or both U and V, depending on the value of the type parameter. If type is not one of the valid options (“left”, “right”, “both”), a ValueError is raised.

decompy.interfaces.svdresult module

class decompy.interfaces.svdresult.SVDResult(U: ndarray, D: ndarray, V: ndarray, **kwargs)

Bases: object

The SVDResult class is a structure for holding the matrix decomposition in form of singular value decomposition.

Parameters:
  • U (np.ndarray) – a numpy array representing the left singular vectors of a matrix

  • D (np.ndarray) – A 1-dimensional numpy array containing the singular values of a matrix.

  • V (np.ndarray) – V is a 2D numpy array representing the right singular vectors of a matrix. It is part of the output

  • matrix. (of a singular value decomposition (SVD) and is used to reconstruct the original) –

metrics

a python dictionary object to hold arbitrary values related to convergence metrics of the relevant algorithm

Type:

dict

convergence_metrics()

This function returns the convergence metrics from a dictionary called “metrics”.

Return type:

The method convergence_metrics is returning the value of the key “convergence” from the metrics

dictionary attribute of the object.

cumulative_variance(type: Literal['identity', 'proportion'] = 'identity', threshold: float = 1e-05)

The function calculates the cumulative variance of singular values and returns either the cumulative sum or proportion based on the specified type.

Parameters:
  • type (Literal["identity", "proportion"], optional) – The type parameter is a string literal that specifies the type of cumulative variance to be

  • values (calculated. It can take two possible) –

  • selected (the function returns the cumulative sum of the singular values. If "proportion" is) –

  • threshold (float) – The threshold parameter is a float value that is used to set any singular values that are smaller

  • of (than the threshold to zero. This is done to reduce the noise in the data and improve the accuracy) –

  • be (the results. Any singular values that are smaller than the threshold are considered to) –

  • set (insignificant and are therefore) –

Return type:

a numpy array containing the cumulative sum of the singular values of a matrix, either as an

identity or as a proportion of the total sum of singular values. The type of output is determined by the type parameter, which can be either “identity” or “proportion”. If the type parameter is not one of these two options, a ValueError is raised.

estimated_rank(threshold: float = 1e-05)

The function calculates the estimated rank of a matrix based on its singular values.

Parameters:
  • threshold (float) – The threshold parameter is a float value that is used to determine the minimum value of singular

  • below (values that will be considered in the calculation of the estimated rank. Any singular value) –

  • The (this threshold will be considered as zero and will not be included in the rank calculation.) –

  • 1 (default value of the threshold is) –

Return type:

The function estimated_rank returns the estimated rank of the matrix represented by the instance

of the SVD class. The estimated rank is calculated as the number of singular values that are greater than or equal to the threshold value, which is set to 1e-5 by default. The function returns an integer value representing the estimated rank of the matrix.

singular_values(as_matrix: bool = True)

The function returns the singular values of a matrix either as a diagonal matrix or as a flattened array.

Parameters:
  • as_matrix (bool, optional) – A boolean parameter that specifies whether the singular values should be returned as a matrix (2D

  • True (array) or as a 1D array. If as_matrix is) –

  • the (the function returns a diagonal matrix with) –

  • False (singular values on the diagonal. If as_matrix is) –

:param :

Return type:

The method singular_values returns either a diagonal matrix of singular values if as_matrix is

True, or a 1D array of singular values if as_matrix is False.

singular_vectors(type: Literal['left', 'right', 'both'] = 'left')

The function singular_vectors returns the left, right, or both singular vectors of a matrix depending on the input type.

Parameters:
  • type (Literal["left", "right", "both"], optional) – The type parameter is a string literal that specifies which singular vectors to return. It can

  • values (take one of three) –

  • " (left singular vectors (stored in the U attribute). If) –

Return type:

The singular_vectors method returns the left singular vectors if the type parameter is set to

“left”, the right singular vectors if type is set to “right”, both left and right singular vectors if type is set to “both”. If type is set to any other value, a ValueError is raised.

Module contents

class decompy.interfaces.LSNResult(L: ndarray, S: ndarray | None = None, N: ndarray | None = None, **kwargs)

Bases: object

The LSNResult class is a structure for holding the matrix decomposition in form of a low rank matrix L, a sparse matrix S and a small perturbation noise matrix N.

Parameters:
  • L (np.ndarray) – a numpy ndarray representing the low rank matrix

  • S (np.ndarray) – a sparse matrix that represents the sparse component of a given matrix. This is an optional parameter. If provided, it should be a 2D numpy

  • L. (array with the same shape as the low rank matrix) –

  • N (np.ndarray) – The noise perturbation matrix, which is an optional parameter. If provided, it should be a 2D numpy

  • L.

metrics

a python dictionary object to hold arbitrary values related to convergence metrics of the relevant algorithm

Type:

dict

convergence_metrics()

This function returns the convergence metrics from a dictionary called “metrics”.

Return type:

The method convergence_metrics is returning the value of the key “convergence” from the metrics

dictionary attribute of the object.

cumulative_variance(type: Literal['identity', 'proportion'] = 'identity', threshold: float = 1e-05)

The function calculates the cumulative variance of singular values and returns either the cumulative sum or proportion based on the specified type.

Parameters:
  • type (Literal["identity", "proportion"], optional) – The type parameter is a string literal that specifies the type of cumulative variance to be

  • values (calculated. It can take two possible) –

  • selected (the function returns the cumulative sum of the singular values. If "proportion" is) –

  • function (the) –

  • values. (returns the cumulative proportion of variance explained by the singular) –

  • threshold (float) – The threshold parameter is a float value that is used to set any singular values that are smaller

  • that (than the threshold to zero. This is done to remove any noise or small variations in the data) –

  • 1e-5 (may not be significant. The default value for threshold is) –

  • singular (which means that any) –

Return type:

a numpy array containing the cumulative sum of the singular values of a matrix, either as an

identity or as a proportion of the total sum of singular values. The type of output is determined by the type parameter, which can be either “identity” or “proportion”. If the type parameter is not one of these two options, a ValueError is raised. The function

estimated_rank(threshold: float = 1e-05)

The function calculates the estimated rank of a matrix based on its singular values.

Parameters:
  • threshold (float) – The threshold parameter is a float value that is used to determine the minimum value of singular

  • below (values that will be considered in the calculation of the estimated rank. Any singular value) –

  • The (this threshold will be considered as zero and will not be included in the rank calculation.) –

  • 1e-5 (default value of the threshold is) –

Return type:

The function estimated_rank returns the estimated rank of the matrix represented by the instance

of the SVD class. The estimated rank is calculated as the number of singular values that are greater than or equal to the specified threshold value. The function returns an integer value representing the estimated rank.

singular_values(as_matrix: bool = True)

This function computes the singular values of a matrix and returns them either as a diagonal matrix or a 1D array.

Parameters:
  • as_matrix (a diagonal matrix with the singular values on the diagonal) or as a 1D array. If) – A boolean parameter that specifies whether the singular values should be returned as a matrix

  • (i.e.

  • as_matrix

  • True (is) –

  • False (the function returns the singular values as a matrix. If as_matrix is) –

  • function (the) –

  • vector. (returns the singular values as a) –

Return type:

The function singular_values returns the singular values of the matrix self.L. If the parameter

as_matrix is set to True, it returns a diagonal matrix with the singular values on the diagonal. If as_matrix is set to False, it returns a 1D array with the singular values.

singular_vectors(type: Literal['left', 'right', 'both'] = 'left')

The function returns the left, right, or both singular vectors of a given matrix using the SVD method in numpy.

Parameters:
  • type (Literal["left", "right", "both"], optional) – The type parameter is a string literal that specifies which singular vectors to return. It can

  • values (take one of three) –

  • specified (If "both" is) –

  • returned. (only the right singular vectors (V) are) –

  • specified

  • tuple (both singular values (U and V) are returned as a) –

Return type:

The function singular_vectors returns the left singular vectors, right singular vectors, or both

depending on the value of the type parameter. If type is “left”, the function returns the left singular vectors (matrix U), if type is “right”, the function returns the right singular vectors (matrix V), and if type is “both”, the function returns both

class decompy.interfaces.PCAResult(loc: ndarray, eval: ndarray, evec: ndarray, **kwargs)

Bases: object

The PCAResult class is a structure for holding the matrix decomposition in form of location and the principal components.

Parameters:
  • loc (np.ndarray) – a numpy array representing the location of a point in space

  • eval (np.ndarray) – A 1-dimensional numpy array representing the eigenvalues of a matrix.

  • evec (np.ndarray) – evec is a 2D numpy array representing the eigenvectors of a matrix. Each column of the array represents an eigenvector.

metrics

a python dictionary object to hold arbitrary values related to convergence metrics of the relevant algorithm

Type:

dict

convergence_metrics()

This function returns the convergence metrics from a dictionary called “metrics”.

Return type:

The method convergence_metrics is returning the value of the key “convergence” from the metrics

dictionary attribute of the object.

cumulative_variance(type: Literal['identity', 'proportion'] = 'identity', threshold: float = 1e-05)

The function calculates the cumulative variance of eigenvalues and returns either the cumulative sum of squared eigenvalues or the proportion of the cumulative sum of squared eigenvalues.

Parameters:
  • type (Literal["identity", "proportion"], optional) – The type parameter is a string literal that specifies the type of cumulative variance to be

  • values (calculated. It can take two possible) –

  • selected (the function returns the cumulative sum of the squared eigenvalues. If "proportion" is) –

  • function (the) –

  • eigenvalues. (returns the cumulative proportion of variances explained by the) –

  • threshold (float) – The threshold parameter is a float value that is used to filter out small eigenvalues. Any

  • and (eigenvalue smaller than the threshold value will be set to zero. This is done to remove noise) –

  • variance. (numerical instability in the calculation of the cumulative) –

Return type:

a numpy array containing the cumulative sum of the squared eigenvalues of the matrix, either as an

“identity” or “proportion” type. If “identity” is chosen, the function returns the cumulative sum of the squared eigenvalues. If “proportion” is chosen, the function returns the cumulative sum of the squared eigenvalues divided by the sum of all squared eigenvalues.

eigen_values(as_matrix: bool = True)

The function returns either the diagonal matrix of eigenvalues or the number of eigenvalues of a given matrix.

Parameters:
  • as_matrix (bool, optional) – A boolean parameter that determines whether the eigenvalues should be returned as a matrix or a 1D

  • True (array. If as_matrix is) –

  • matrix (the eigenvalues will be returned as a diagonal) –

  • the (where) –

  • False (diagonal elements are the eigenvalues. If as_matrix is) –

:param :

Return type:

If as_matrix is True, the function returns a diagonal matrix of the eigenvalues of the object

self. If as_matrix is False, the function returns the number of eigenvalues of the object self.

eigen_vectors()

The function returns the eigenvectors of the PCAResult.

Return type:

The function eigen_vectors is returning the attribute evec of the object.

estimated_rank(threshold: float = 1e-05)

The function calculates the estimated rank of a matrix based on its eigenvalues.

Parameters:
  • threshold (float) – The threshold parameter is a float value that is used to determine the minimum value of eigenvalues

  • this (that will be considered in the calculation of the estimated rank. Any eigenvalue below) –

  • The (threshold will be considered as zero and will not be included in the calculation of the rank.) –

  • 1e-5 (default value of the threshold is) –

Return type:

The function estimated_rank returns the estimated rank of the matrix based on the eigenvalues. It

counts the number of eigenvalues that are greater than or equal to the threshold value (default is 1e-5) and returns that count as the estimated rank.

location()

The function returns a flattened version of the “loc” attribute of the PCAResult.

Return type:

The location method is returning a flattened version of the loc attribute of the object. The

reshape(-1) method is used to convert the loc attribute into a one-dimensional array.

class decompy.interfaces.RankFactorizationResult(A: ndarray, B: ndarray, **kwargs)

Bases: object

The RankFactorizationResult class is a structure for holding the matrix decomposition in form of rank factorization.

Parameters:
  • A (np.ndarray) – A is a numpy ndarray representing a matrix with 2 dimensions. It is the first of the rank factorized pair

  • B (np.ndarray) – The parameter B is a numpy ndarray representing a matrix. The assert statements in the code ensure

  • matrix (that B has two dimensions and that its second dimension matches the second dimension of the) –

  • A.

metrics

a python dictionary object to hold arbitrary values related to convergence metrics of the relevant algorithm

Type:

dict

convergence_metrics()

This function returns the convergence metrics from a dictionary called “metrics”.

Return type:

The method convergence_metrics is returning the value of the key “convergence” from the metrics

dictionary attribute of the object.

cumulative_variance(type: Literal['identity', 'proportion'] = 'identity')

The function calculates the cumulative variance of a matrix’s singular values and returns either the cumulative sum or proportion of the singular values based on the specified type.

Parameters:
  • type (Literal["identity", "proportion"], optional) – The type parameter is a string literal that specifies the type of cumulative variance to be

  • values (calculated. It can take two possible) –

  • function (the function returns the cumulative sum of the singular values. If "proportion" is selected the) –

  • values. (returns the cumulative proportion of the variance explained by the singular) –

Return type:

a numpy array containing the cumulative sum of the singular values of a matrix. The type of

cumulative sum returned can be either “identity” or “proportion”, depending on the argument passed to the function. If “identity” is passed, the function returns the cumulative sum of the singular values. If “proportion” is passed, the function returns the cumulative proportion of the singular values

estimated_rank()

This function returns the rank of the result matrix decomposition.

Return type:

the rank of the result matrix decomposition.

singular_values(as_matrix: bool = True)

This function computes the singular values of a matrix product and returns them either as a diagonal matrix or a list.

Parameters:
  • as_matrix (a diagonal matrix with the singular values on the diagonal) or as a 1D array. If) – A boolean parameter that specifies whether the singular values should be returned as a matrix

  • (i.e.

  • as_matrix

  • True (is) –

  • `as (the function returns the singular values as a matrix. If) –

Return type:

The function singular_values returns the singular values of the matrix product A @ B.T of the

MatrixFactorization object. The singular values are computed using the numpy.linalg.svd function. The function returns either a diagonal matrix of singular values (if as_matrix is True) or a 1D array of singular values (if as_matrix is

singular_vectors(type: Literal['left', 'right', 'both'] = 'left')

The function computes the singular vectors of a matrix product and returns either the left, right, or both singular vectors depending on the specified type.

Parameters:
  • type (Literal["left", "right", "both"], optional) – The type parameter is a string literal that specifies which singular vectors to return. It can

  • values (take one of three) –

  • specified (vectors are returned. If "right" is) –

  • right (only the) –

Return type:

The function singular_vectors returns either the left singular vector U, the right singular

vector V, or both U and V, depending on the value of the type parameter. If type is not one of the valid options (“left”, “right”, “both”), a ValueError is raised.

class decompy.interfaces.SVDResult(U: ndarray, D: ndarray, V: ndarray, **kwargs)

Bases: object

The SVDResult class is a structure for holding the matrix decomposition in form of singular value decomposition.

Parameters:
  • U (np.ndarray) – a numpy array representing the left singular vectors of a matrix

  • D (np.ndarray) – A 1-dimensional numpy array containing the singular values of a matrix.

  • V (np.ndarray) – V is a 2D numpy array representing the right singular vectors of a matrix. It is part of the output

  • matrix. (of a singular value decomposition (SVD) and is used to reconstruct the original) –

metrics

a python dictionary object to hold arbitrary values related to convergence metrics of the relevant algorithm

Type:

dict

convergence_metrics()

This function returns the convergence metrics from a dictionary called “metrics”.

Return type:

The method convergence_metrics is returning the value of the key “convergence” from the metrics

dictionary attribute of the object.

cumulative_variance(type: Literal['identity', 'proportion'] = 'identity', threshold: float = 1e-05)

The function calculates the cumulative variance of singular values and returns either the cumulative sum or proportion based on the specified type.

Parameters:
  • type (Literal["identity", "proportion"], optional) – The type parameter is a string literal that specifies the type of cumulative variance to be

  • values (calculated. It can take two possible) –

  • selected (the function returns the cumulative sum of the singular values. If "proportion" is) –

  • threshold (float) – The threshold parameter is a float value that is used to set any singular values that are smaller

  • of (than the threshold to zero. This is done to reduce the noise in the data and improve the accuracy) –

  • be (the results. Any singular values that are smaller than the threshold are considered to) –

  • set (insignificant and are therefore) –

Return type:

a numpy array containing the cumulative sum of the singular values of a matrix, either as an

identity or as a proportion of the total sum of singular values. The type of output is determined by the type parameter, which can be either “identity” or “proportion”. If the type parameter is not one of these two options, a ValueError is raised.

estimated_rank(threshold: float = 1e-05)

The function calculates the estimated rank of a matrix based on its singular values.

Parameters:
  • threshold (float) – The threshold parameter is a float value that is used to determine the minimum value of singular

  • below (values that will be considered in the calculation of the estimated rank. Any singular value) –

  • The (this threshold will be considered as zero and will not be included in the rank calculation.) –

  • 1 (default value of the threshold is) –

Return type:

The function estimated_rank returns the estimated rank of the matrix represented by the instance

of the SVD class. The estimated rank is calculated as the number of singular values that are greater than or equal to the threshold value, which is set to 1e-5 by default. The function returns an integer value representing the estimated rank of the matrix.

singular_values(as_matrix: bool = True)

The function returns the singular values of a matrix either as a diagonal matrix or as a flattened array.

Parameters:
  • as_matrix (bool, optional) – A boolean parameter that specifies whether the singular values should be returned as a matrix (2D

  • True (array) or as a 1D array. If as_matrix is) –

  • the (the function returns a diagonal matrix with) –

  • False (singular values on the diagonal. If as_matrix is) –

:param :

Return type:

The method singular_values returns either a diagonal matrix of singular values if as_matrix is

True, or a 1D array of singular values if as_matrix is False.

singular_vectors(type: Literal['left', 'right', 'both'] = 'left')

The function singular_vectors returns the left, right, or both singular vectors of a matrix depending on the input type.

Parameters:
  • type (Literal["left", "right", "both"], optional) – The type parameter is a string literal that specifies which singular vectors to return. It can

  • values (take one of three) –

  • " (left singular vectors (stored in the U attribute). If) –

Return type:

The singular_vectors method returns the left singular vectors if the type parameter is set to

“left”, the right singular vectors if type is set to “right”, both left and right singular vectors if type is set to “both”. If type is set to any other value, a ValueError is raised.