tensorly | TensorLy : Tensor Learning in Python | Machine Learning library
kandi X-RAY | tensorly Summary
kandi X-RAY | tensorly Summary
TensorLy: Tensor Learning in Python.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Calculate parafac .
- Validate constraints .
- r Constraints a tensor .
- Perform a cross product of the input tensor .
- Compute the parafac model .
- Calculate the non - negative tucker Hessian .
- Calculate non - negative parafac hals .
- Calculate the HAL decomposition problem .
- Generate RST directive .
- Import phantom module .
tensorly Key Features
tensorly Examples and Code Snippets
$ git clone https://github.com/pydata/sparse/ & cd sparse
$ pip install .
$ git clone https://github.com/jcrist/tensorly.git tensorly-sparse & cd tensorly-sparse
$ git checkout sparse-take-2
import mxnet as mx
import numpy as np
import tensorly as tl
import matplotlib.pyplot as plt
import tensorly.decomposition
# Load data
mnist = mx.test_utils.get_mnist()
train_data = mnist['train_data'][:,0]
err = np.zeros([28,28]) # here
import tensorly as tl
from tensorly import random
from tensorly.decomposition import partial_tucker
size = 10
order = 3
shape = (size, )*order
tensor = random.random_tensor(shape)
core, fac
import tensorly as tl
import numpy as np
X = tl.tensor(np.random.random((10, 11, 12)))
from tensorly.decomposition import robust_pca
D, E = robust_pca(X)
from tensorly.decomposition impor
import tensorly as tl
import numpy as np
tl.set_backend('tensorflow')
k = 2; m = 3; n = 5; h = 4
A = tl.tensor(np.random.random((m, n)))
B = tl.tensor(np.random.random((k, n, h)))
res = tl.tenalg.contract(A, 1, B, 1)
import numpy as np
import tensorly as tl
tensor = tl.tensor([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 1., 1., 1., 1., 0., 0., 0., 0.],
[ 0., 0., 0.
a = [[1, 2, 3],
[2, 3, 4],
[3, 4, 5]]
b = [[6, 7]]
[[[[1], [2], [3]]],
[[[2], [3], [4]]],
[[[3], [4], [5]]]]
[[[[6, 7]]]]
[[[[1*6, 1*7], [2*6, 2*7], [3*
import tensorly as tl
tl.set_backend('pytorch')
U, S, V = tl.truncated_svd(matrix, n_eigenvecs=10)
Community Discussions
Trending Discussions on tensorly
QUESTION
I want to apply a partial tucker decomposition algorithm to minimize MNIST image tensor dataset of (60000,28,28), in order to conserve its features when applying another machine algorithm afterwards like SVM. I have this code that minimizes the second and third dimension of the tensor
...ANSWER
Answered 2021-Dec-28 at 21:05So if you look at the source code for tensorly
linked here you can see that the documentation for the function in question partial_tucker
says:
QUESTION
I have a set of manufactured data (generated from an explicit mathematical function) stored in a 3-dimensional tensor called A
.
When I try to run parafac, I receive the following:
ANSWER
Answered 2021-May-07 at 09:33In the latest version of TensorLy, parafac returns a CPTensor that acts as a tuple (weight, factors) : in addition to the factors of the decomposition, you also get a vector of weights. This is because the CP decomposition expresses the original tensor as a weighted sum of rank-1 tensors.
In other words, if you are using the latest version of TensorLy, your code should be either:
QUESTION
I try to design a test in order to verify that the partial_tucker
function from tensorly works as I expect it to work. In other words, I want to design an input for the partial_tucker
function along with its associated expected output.
So, what I have tried to do is to take an initial random tensor A
(of order 4), compute its "low rank" tucker decomposition by hand then reconstruct the tensor of same shape than the initial tensor, say A_tilde
. I think the A_tilde
tensor is then the "low rank approximation" of the initial tensor A
. Am I correct?
Then I would like to us the partial_tucker
function on that A_tilde
tensor and I expect the result to be the same as the tucker decomposition that I have computed by hand. It is not the case so I guess my handcrafted tucker decomposition is wrong. If so, why?
ANSWER
Answered 2020-Apr-23 at 14:05You are implicitely making a lot of assumptions here: you are assuming, for instance that you can just trim a rank-R decomposition to get the rank-(R-1) decomposition. This is in general not true. Also, note that the Tucker decomposition you are using is not just Higher-Order SVD (HO-SVD). Rather, HO-SVD is used for initialization and followed by Higher Order Orthogonal Iteration (HOOI).
You are also assuming that the low-rank decomposition is unique, for any given rank, which would allow you to compare the factors of the decomposition directly. This is also not the case (even in the matrix case, and with strong constraints such as orthonormality, you still would have sign indeterminacy).
Instead you could for example check the relative reconstruction error. I suggest you have a look at the tests in TensorLy. There are lots of good references on this, if you are starting with tensors. For instance, the seminal work by Kolda and Bader; for Tucker in particular, the work by De Lathauwer et al (eg.on best low-rank approximation of tensors), etc.
QUESTION
I'm trying to understand tl.kruskal_to_tensor () method in tensorly package. In the webpage I understand that it takes as input a list of matrices and produces the tensor whose cp-decomposiiton are the matrices? It takes as input a list of matrices.
But I saw the following code:
...ANSWER
Answered 2020-Mar-27 at 13:27This version of kruskal_to_tensor
is documented in the dev version of the API.
The np.ones
corresponds to the weight of the Kruskal tensor: a Kruskal tensor expresses a tensor as a weighted sum of rank one tensors (outer product of vectors, collected as the columns of the factor matrices). In your case, the weights of the sum are all ones and accumulated in this vector of ones.
Note that you could normalize the factors of your Kruskal tensor and absorb their magnitude in theses weights.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install tensorly
You can use tensorly like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page