当前位置:网站首页>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
边栏推荐
- A survey on model compression for natural language processing (NLP model compression overview)
- How FEA and FEM work together
- What is Ethernet
- Zblog determines whether a plug-in installs the enabled built-in function code
- Release! Tencent IOA and Tencent sky screen were selected into the first batch of certified products of domestic digital trusted services
- What is the difference between a network card and a port
- Video intelligent analysis platform easycvr derivative video management platform menu bar small screen adaptive optimization
- Kubernetes popular series: getting started with container Foundation
- Abstract factory pattern
- zblog系统如何根据用户ID获取用户相关信息的教程
猜你喜欢

A survey of training on graphs: taxonomy, methods, and Applications

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

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

A survey on model compression for natural language processing (NLP model compression overview)
![[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)

MySQL learning -- table structure of SQL test questions
随机推荐
Clickhouse high performance column storage core principle
Introduction to website development for zero foundation Xiaobai
Kubernetes popular series: getting started with container Foundation
AI video structured intelligent security platform easycvr intelligent security monitoring scheme for protecting community residents
What is Ethernet
Scuffle on China's low code development platform -- make it clear that low code
Activeindex selection and redirection in the menu bar on the right of easycvs
What is the difference between a network card and a port
What can Lu yuanjiu Jiao buy?
Edit distance (linear dp+ violence matching)
Memo list: useful commands for ffmpeg command line tools
Introduction to koa (IV) koa operation database
Experience and suggestions on cloud development database
实现TypeScript运行时类型检查
Game business DDoS attack and defense confrontation case sharing
Video structured intelligent analysis platform easycvr video recording plan function optimization / regularly delete expired videos
区块哈希游戏竞猜系统开发(成熟代码)
Try catch finally implementation mechanism
AI structured intelligent security video monitoring technology, supporting the protective umbrella of the reserve / wild animals
Development of block hash game guessing system (mature code)