in Education by
I am trying to decompose a 3D matrix using python library scikit-tensor. I managed to decompose my Tensor (with dimensions 100x50x5) into three matrices. My question is how can I compose the initial matrix again using the decomposed matrix produced with Tensor factorization? I want to check if the decomposition has any meaning. My code is the following: import logging from scipy.io.matlab import loadmat from sktensor import dtensor, cp_als import numpy as np //Set logging to DEBUG to see CP-ALS information logging.basicConfig(level=logging.DEBUG) T = np.ones((400, 50)) T = dtensor(T) P, fit, itr, exectimes = cp_als(T, 10, init='random') // how can I re-compose the Matrix T? TA = np.dot(P.U[0], P.U[1].T) I am using the canonical decomposition as provided from the scikit-tensor library function cp_als. Also what is the expected dimensionality of the decomposed matrices? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You can simply perform a cross product of matrics. can be expressed using Einstein notation as Code implementation of this problem using NumPy: numpy.einsum('az,bz,cz,dz -> abcd', A, B, C, D) so in your case, you would use numpy.einsum('az,bz->ab', P.U[0], P.U[1]) or, in your 3-matrix case numpy.einsum('az,bz,cz->abc', P.U[0], P.U[1], P.U[2]) sktensor.ktensor.ktensor also have a method totensor() that does exactly this: np.allclose(np.einsum('az,bz->ab', P.U[0], P.U[1]), P.totensor()) >>> True If you want to be build successful data science career then enroll for best data science certification. Hope this answer helps.

Related questions

0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am new to TensorFlow. While I am reading the existing documentation, I found the term tensor really confusing. ... types of tensors? Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I have worked all the tutorials and searched for "load csv tensorflow" but just can't get the logic of it all. ... and test the net. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I'm wondering how to calculate precision and recall measures for multiclass multilabel classification, i.e. classification ... labels? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    I'm creating a very basic AI with Tensorflow, and am using the code from the official docs/tutorial. Here's my ... Tensorflow 1.13.1. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I have a Python dictionary like the following: {u'2012-06-08': 388, u'2012-06-09': 388, u'2012-06-10 ... (my_dict,index=my_dict.keys()) Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I'm hoping to use either Haskell or OCaml on a new project because R is too slow. I need to be able to ... in either Haskell or OCaml? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm hoping to use either Haskell or OCaml on a new project because R is too slow. I need to be able to ... in either Haskell or OCaml? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I'm Working on document classification tasks in java. Both algorithms came highly recommended, what are the ... Processing tasks? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I am trying to do a hyperparameter search using scikit-learn's GridSearchCV on XGBoost. During grid search ... ':42} Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    What is the difference between the two? It seems that both create new columns, in which their number is equal to ... they are in. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I have a dataframe that looks like this: from to datetime other ---------------------------------- ... !! Thank you so much in advance! Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am receiving the error: ValueError: Wrong number of items passed 3, placement implies 1, and I am struggling to ... 'sigma'] = sigma Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I need to know the most efficient way of installing JQ on Mac (el capitan). The code is downloaded to my mac ... via the command line. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am training on 970 samples and validating on 243 samples. How big should batch size and number of epochs be ... on data input size? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
...