当前位置:网站首页>Tensor and tensor network background and significance - basic knowledge
Tensor and tensor network background and significance - basic knowledge
2022-06-24 16:57:00 【Unknown webmaster】
tensor (Tensor) It can be understood as a generalized matrix , Its main feature is that the digital matrix is represented in a graphical way , This allows us to abstract a large matrix operation into a tensor graph with good properties . The operational network graph composed of tensors , It's called tensor network (Tensor Network). Let's use some common graphs to see what tensor networks look like ( The picture below is reproduced from Reference link 1):
The graph above shows from left to right : First order tensor 、 Second order tensors and third order tensors , We can see that , The order of a tensor is abstractly called the order of tensor in the image representation leg The number of , The square or circle in the middle represents the tensor itself . actually , A vector represented by a tensor of first order , For example, we usually use python An array variable defined by :
1 2 3 x = [1, 0] y = [0, 1, 0] z = [1, 2, 3, 4]
So here x,y,z They're all first-order tensors . The second-order tensor is a two-dimensional matrix , As we often see python Multidimensional arrays :
1 2 M = [[1, -1], [-1, 1]] N = [[1, 3], [2, 4], [5, 6]]
What is defined here M, N They're all second order tensors . By looking at the first and second order tensors in these examples, we can get a rule : Can be used in the form of var[i] Read and traverse in the form of var The scalar elements in can be called first-order tensors , Can be used in the form of var[i][j] Read and traverse in the form of var The scalar elements in can be called second order tensors . obviously , A tensor of several orders , It has nothing to do with the number of elements contained in the tensor . Then according to this objective law , We can extend it to zero order tensors and higher order tensors :
1 2 3 pi = 3.14 P = [[[1]]] Q = [[[1, 1, 1], [1, 1, 1], [1, 1, 1]]]
In the above python Variable definition ,pi It's a zero order tensor , A tensor of order zero is actually equivalent to a scalar , and P, Q They're all third-order tensors . It should be noted that , Although tensor P There's only one element , But if we need to read this scalar element , We have to use the following python Instruction to execute :
print (P[0][0][0])
therefore P It's also one with Three legs Tensor . While using tensor form to represent a single matrix , We need to consider if there are multiple matrix multiplication operations , How should we express ? Let's start with two forms of python Matrix operation to illustrate the expression of tensor calculation :
1 2 3 4 5 6 7 import numpy as np M = np.random.rand(2, 2) v = np.random.rand(2) w = np.dot(M, v) print (M) print (v) print (w)
This string python The calculation process of code representation is :w2×1=M2×2⋅v2×1w2×1=M2×2⋅v2×1, In order not to lose widespread effectiveness , Here we use random tensors to calculate , there M It's a second-order tensor ,v,w It's a tensor of first order . If we understand it from the perspective of matrix operation , It's actually a 2×22×2 Multiply by a matrix of 2×12×1 Vector of , And got a new 2×12×1 Vector of . The results are as follows :
1 2 3 4 [[0.09660039 0.55849787] [0.93007524 0.32329559]] [0.74966152 0.59573188] [0.40513259 0.88983912]
At the same time, we also consider another tensor operation scenario , One tensor of higher order operates with another tensor of higher order :
1
2
3
4
5
6
7
import numpy as np
A = np.random.rand(1, 2, 2, 2)
B = np.random.rand(2, 2, 2)
C = np.einsum('ijkl,klm->ijm', A, B)
print ('A:', A)
print ('B:', B)
print ('C:', C) This string python The calculation process of code representation is :C1×2×2=A1×2×2×2⋅B2×2×2C1×2×2=A1×2×2×2⋅B2×2×2, Because the multi-dimensional tensor operation here can no longer use the ordinary numpy.dot To deal with it , So we still apply the professional tensor calculation function numpy.einsum To process , The calculation results are as follows :
1 2 3 4 5 6 7 8 9 10 11 12 A: [[[[0.85939221 0.43684494] [0.71895754 0.31222944]] [[0.49276976 0.13639093] [0.04176578 0.14400289]]]] B: [[[0.21157005 0.58052674] [0.59166167 0.21243451]] [[0.11420572 0.98995349] [0.1145634 0.97101076]]] C: [[[0.5581652 1.60661377] [0.20621996 0.49621469]]]
The above two cases , From the perspective of tensor theory , It's equivalent to the tensor w And tensor C It is expressed as the result of several tensor combination operations . A combinatorial operation consisting of multiple tensors , We can use tensor networks to represent :
The picture above shows (a)(a) and (b)(b) I mean tensors w And tensor C Tensor network diagram of . And this computes all the tensors of the tensor network , Finally, we get one or a series of new tensor matrix multiplication and addition processes , We call it Tensors are reduced and merged , English name Tensor Contraction
边栏推荐
- [tke] nodelocaldnschache is used in IPVS forwarding mode
- 让UPS“印象派用户”重新认识可靠性
- Introduction to koa (III) koa routing
- How important is it to document the project? I was chosen by the top 100 up leaders and stood up again
- ClassNotFoundException v/s NoClassDefFoundError
- What is zero trust? Three classes will show you how to understand him!
- Best practices for H5 page adaptation and wechat default font size
- Zblog system realizes the tutorial of the number of articles published on the same day when the foreground calls
- Is CICC securities reliable? Is it legal? Is it safe to open a stock account?
- The problem is as big as the middle stage
猜你喜欢

MySQL learning -- table structure of SQL test questions

A survey of training on graphs: taxonomy, methods, and Applications
![[leetcode108] convert an ordered array into a binary search tree (medium order traversal)](/img/e1/0fac59a531040d74fd7531e2840eb5.jpg)
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)

A survey on dynamic neural networks for natural language processing, University of California

Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)

A survey on model compression for natural language processing (NLP model compression overview)
随机推荐
MySQL learning -- table structure of SQL test questions
How to save data to the greatest extent after deleting LV by misoperation under AIX?
During JMeter pressure measurement, time_ The number of requests does not go up due to many waits. The problem is solved
跟着Vam一起学习Typescript(第一期)
API documents are simple and beautiful. It only needs three steps to open
A survey on model compression for natural language processing (NLP model compression overview)
AI video structured intelligent security platform easycvr intelligent security monitoring scheme for protecting community residents
Recent progress of ffmpeg go
Abnormal dockgeddon causes CPU 100%
A very good educational man and resource center planning scheme, with word file download
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)
Industrial security experts talk about how to guarantee the safety of data elements in the rapid development of digital economy?
Heavy release! Tencent cloud ASW workflow, visual orchestration cloud service
Scuffle on China's low code development platform -- make it clear that low code
Week7 weekly report
What is a reptile
FPGA project development: experience sharing of lmk04821 chip project development based on jesd204b (I)
Sigai intelligent container damage identification products are deployed in Rizhao Port and Yingkou Port
Kubernetes 1.20.5 setting up Sentinel
Solution to the problem that kibana's map cannot render longitude and latitude coordinate data