ingenii_quantum.tensor_networks.VBMF
- ingenii_quantum.tensor_networks.VBMF.EVBMF(Y, sigma2=None, H=None)[source]
Analytical implementation of Empirical Variational Bayesian Matrix Factorization (VBMF).
- Parameters:
Y (numpy.ndarray) – Input matrix to factorize with shape (L, M), where L <= M.
sigma2 (float, optional) – Noise variance. If None, it is estimated.
H (int, optional) – Maximum rank of the factorized matrices. If None, set to L.
- Returns:
U (numpy.ndarray): Left singular vectors of the factorized matrix.
S (numpy.ndarray): Diagonal matrix of singular values.
V (numpy.ndarray): Right singular vectors of the factorized matrix.
post (dict): Dictionary containing posterior values including ‘sigma2’ and ‘F’.
- Return type:
tuple
References
Nakajima, Shinichi, et al. “Global analytic solution of fully-observed variational Bayesian matrix factorization.” Journal of Machine Learning Research 14.Jan (2013).
- ingenii_quantum.tensor_networks.VBMF.EVBsigma2(sigma2, L, M, s, residual, xubar)[source]
Compute the objective function for optimizing the noise variance (sigma2) in Empirical Variational Bayesian Matrix Factorization (EVBMF).
- Parameters:
sigma2 (float) – Noise variance to optimize.
L (int) – Number of rows in the input matrix.
M (int) – Number of columns in the input matrix.
s (numpy.ndarray) – Singular values of the matrix to factorize.
residual (float) – Residual sum of squares from truncated singular values.
xubar (float) – Threshold for singular values based on prior knowledge.
- Returns:
Objective function value for the given noise variance.
- Return type:
float
- ingenii_quantum.tensor_networks.VBMF.VBMF(Y, cacb, sigma2=None, H=None)[source]
Implementation of the analytical solution to Variational Bayes Matrix Factorization.
This function can be used to calculate the analytical solution to VBMF. This is based on the paper and MatLab code by Nakajima et al.: “Global analytic solution of fully-observed variational Bayesian matrix factorization.”
- Parameters:
Y (numpy-array) – Input matrix that is to be factorized. Y has shape (L,M), where L<=M.
cacb (int) – Product of the prior variances of the matrices that factorize the input.
sigma2 (int or None) – Variance of the noise on Y.
H (int or None) – Maximum rank of the factorized matrices.
- Returns:
Left-singular vectors. S (numpy-array): Diagonal matrix of singular values. V (numpy-array): Right-singular vectors. (post dictionary): Dictionary containing the computed posterior values.
- Return type:
U (numpy-array)
References
[1] Nakajima, Shinichi, et al. “Global analytic solution of fully-observed variational Bayesian matrix factorization.” Journal of Machine Learning Research 14.Jan (2013): 1-37. [2] Nakajima, Shinichi, et al. “Perfect dimensionality recovery by variational Bayesian PCA.” Advances in Neural Information Processing Systems. 2012.
- ingenii_quantum.tensor_networks.VBMF.VBsigma2(sigma2, L, M, cacb, s, residual)[source]
Computes the free energy of the Variational Bayesian Matrix Factorization (VBMF) model to optimize the noise variance parameter.
- Parameters:
sigma2 (float) – Variance of the noise in the model.
L (int) – Number of rows in the input matrix.
M (int) – Number of columns in the input matrix.
cacb (float) – Multiplicative factor derived from prior hyperparameters.
s (numpy.ndarray) – Singular values of the matrix to factorize.
residual (float) – Residual sum of squares from truncated singular values.
- Returns:
Free energy of the VBMF model for the given noise variance.
- Return type:
float
- ingenii_quantum.tensor_networks.VBMF.estimate_ranks(layer)[source]
Estimate the optimal ranks for Tucker decomposition of a tensor using Variational Bayesian Matrix Factorization (VBMF). This function unfolds the input tensor along two modes (rows and columns) and applies VBMF to estimate the optimal ranks of the matrices corresponding to each mode. The estimated ranks are then returned as a list.
- Parameters:
layer (torch.nn.Module) – A neural network layer whose weights are represented as a tensor.
- Returns:
A list containing the estimated ranks for the decomposition along the first and second modes.
- Return type:
list
- ingenii_quantum.tensor_networks.VBMF.phi0(x)[source]
Calculate the phi0 function for EVBMF.
- Parameters:
x (float or numpy.ndarray) – Input value(s).
- Returns:
Result of the phi0 calculation.
- Return type:
float or numpy.ndarray
- ingenii_quantum.tensor_networks.VBMF.phi1(x, alpha)[source]
Calculate the phi1 function for EVBMF.
- Parameters:
x (float or numpy.ndarray) – Input value(s).
alpha (float) – Aspect ratio of the input matrix (L / M).
- Returns:
Result of the phi1 calculation.
- Return type:
float or numpy.ndarray
- ingenii_quantum.tensor_networks.VBMF.tau(x, alpha)[source]
Compute the tau function, which is part of the EVBMF framework.
- Parameters:
x (float or numpy.ndarray) – Input value(s).
alpha (float) – Aspect ratio of the input matrix (L / M).
- Returns:
Computed tau values.
- Return type:
float or numpy.ndarray
ingenii_quantum.tensor_networks.tucker_decomposition
- ingenii_quantum.tensor_networks.tucker_decomposition.count_params(network)[source]
Counts the number of parameters in the neural network
- Parameters:
network (torch.nn) – Neural network model
- Returns:
Number of training parameters
- Return type:
float
- ingenii_quantum.tensor_networks.tucker_decomposition.tucker_decomposition_conv_layer(layer, ranks)[source]
Gets a convolutional layer, applies Tucker decomposition and returns the set of smaller layers.
- Parameters:
layer (torch layer) – convolutional layer to decompose
ranks (tuple) – Ranks of the Tucker decomposition
- Returns
nn.Sequential: object with the Tucker decomposition.