Pytorch Neural Network Practical Study Notes_39 Based on Spectral Domain Graph Neural Network GNN: Basic Knowledge + GNN Function + Matrix Foundation + Graph Convolutional Neural Network + Laplacian Matrix

Graph Neural Network (GNN) is a type of neural network that can learn characteristic rules from graph-structured data, and is the most important technology to solve machine learning problems of graph-structured data (non-Euclidean spatial data) .

1 Basics of graph neural networks

    Graph Neural Network (GNN) is a type of neural network that can learn feature rules from graph-structured data, and is one of the most important technologies to solve machine learning problems with graph-structured data (non-Euclidean spatial data).
    The previous chapters mainly introduced the relevant knowledge of neural network. Next, let's understand the basics related to graph neural networks.

1.1 Euclidean space and non-Euclidean space

  • Euclidean space/Euclidean space: It can be represented by a one-dimensional, two-dimensional or higher-dimensional matrix, and its most notable feature is the regular spatial structure. This is a special metric space. For example, audio, image and video are all Euclidean structured data defined in Euclidean space.
  • Non-Euclidean space: It is not a flat regular space, but a surface space, that is, a structure other than a regular matrix space. The most representative structure in non-Euclidean space is the graph structure, which is often used to represent relational data such as social networks.

1.2 Figure

In computer science, a graph is a data structure consisting of vertices (also called nodes) and edges between vertices. It is usually expressed in the form G(V, E), where G represents a graph, V is the set of vertices in the graph G, and E is the set of edges in the graph G.

Graph structure studies the many-to-many relationship between data elements, that is, there may be a relationship between any two elements, that is, the relationship between vertices can be arbitrary, and any element in the graph may be related.

In a graph structure, no vertices are not allowed. There may be a relationship between any two vertices, and the logical relationship between vertices is represented by edges. Edges can be directed or undirected, and the set of edges can be empty.

Each vertex in the graph structure has its own feature information, and the relationship between the vertices can reflect the feature information of the graph structure. In practical applications, it can be classified according to graph vertex features or graph structure features.

1.3 Graph-related terminology

  • Undirected and directed graphs: Determined by whether or not the edges between graph vertices have directions.
  • Weight: The additional quantitative information on the edge or arc in the graph. This kind of data that can reflect a certain feature of the edge or arc is called weight.
  • Net: The edge or arc belt weight on the graph is called net, which can be divided into directed net and undirected net.
  • Degree: In an undirected graph, the number of edges associated with vertex v is called the degree of vertex v. In a directed graph, the number of arcs with vertex v as the tail is called the out-degree of vertex v, the number of arcs with vertex v as the head of the arc is called the in-degree of vertex v, and the degree of vertex ν is its The sum of out-degree and in-degree.

1.4 Units of measurement in graph calculations

  1. number of vertices (node); the number of nodes.
  2. Edges: The number of edges or connections.
  3. Average degree: Indicates the average number of edges connected to each vertex. If the graph is an undirected graph, the average degree is calculated as 2×edge÷nodes
  4. Average path length (average netwok distarce): The average distance between any two vertices. It reflects the degree of separation between vertices in the network. The smaller the value, the greater the connectivity of the vertices in the network.
  5. Modularity index: Measures the degree of modularity of the network graph structure. Generally, a value greater than 0.44 indicates that the network graph has reached a certain degree of modularity.
  6. Clustering coefficient: Together with the average path length, it can show that the average path of the network nodes is small, giving an overall indication that some nodes are clustered or "clustered".
  7. Network diameter (diameter): The maximum measured length of the diameter of a network graph, that is, the maximum value in the set consisting of the shortest distance between any two points.

1.5 Structured and Unstructured Data

1.5.1 Structured data

The data logically expressed and realized by the two-dimensional table structure strictly follows the data format and length specifications, and is mainly stored and managed through a relational database.

1.5.2 Unstructured data

The data structure is irregular or incomplete, and there is no predefined data model. It is inconvenient to use the two-dimensional logical table of the database to represent the data. It includes all formats of office documents, text, picture HTML, various reports, images, audio or video information and so on.

1.6 Application of GNN on Different Types of Data

Graph Neural Network (GNN) is a neural network that operates directly on the graph structure. It can process graph structure data based on node features or structural features, and extract (hierarchically) through information transfer, transformation and aggregation between vertices. or processing features. GNNs become the mainstream approach for representation learning on graphs, point clouds, and manifolds.

In structured scenarios, GNNs are widely used in social networks, recommendation systems, physical systems, and chemical molecule prediction, referring to knowledge graphs.

In the unstructured domain, GNNs can be used in domains such as images and text.

In other fields, there are graph generative models and scenarios where GNNs are used to solve combinatorial optimization problems.

1.7 Origin of GNN

1.7.1 GCN 

The first motivation of GNN stems from the convolutional neural network (CNN), the most basic CNN is the Graph Convolutional Network (GCN). The wide application of GNN has brought breakthroughs in the field of machine learning and opened up operations on regular Euclidean space data. GCD is the application of convolutional neural networks to various models.

1.7.2 Graph embedding

Another motivation for GNNs comes from graph embeddings, which learn low-dimensional vector space representations of nodes, edges, or subgraphs in a graph. Methods such as DeepWalk, LINE, SDNE, etc. have achieved great success in the field of network representation learning, however, these methods are computationally complex and not optimal on large-scale graphs. GNN can solve these problems.

1.7.3 Summary

GNN can not only perform feature processing on single vertices and the entire structure, but also perform feature processing on subgraphs composed of a small number of vertices in the graph. If the graph data is regarded as a network, then GNN can perform feature processing on the whole, part and individual of the network respectively. GNN applies deep learning technology to graph data represented by symbols, fully integrates symbolic representation and low-dimensional vector representation, and takes advantage of both.

2 Matrix Basics

2.1 Hadamard product

The result of multiplying the elements at the corresponding positions of the two moments

 2.2 Dot Product

result of row-column multiplication of two matrices

2.3 Degree Matrix and Adjacency Matrix

Degree matrix of a graph: Describes the number of edges connected to each node in the graph.

Graph adjacency matrix: Describes the adjacency relationship between each node in the graph.


Degree matrix D:

 Adjacency matrix A:

 2.4 Several operations on adjacency matrix

The number of rows and columns of an adjacency matrix must be equal (that is, a square matrix). The adjacency matrix of an undirected graph must be symmetric, while the adjacency matrix of a directed graph is not necessarily symmetric. Generally, the node information in the graph is processed through matrix operations.

2.4.1 Get the short side of a directed graph

2.4.2 Get the long edge of a directed graph

2.4.3 Convert the adjacency matrix of a directed graph to an adjacency matrix of an undirected graph

3 Graph Convolutional Neural Networks

As you can see in the figure below, the input of the graph convolutional neural network is a graph, and the output is still a graph after layer-by-layer calculation and transformation.

If understood from the perspective of convolution, the processed adjacency matrix can be regarded as a convolution kernel, and this convolution kernel is used to perform full-scale convolution on the feature results of each hidden layer. Since the content of the convolution kernel is the normalized edge relationship in the graph, using this convolution kernel for convolution processing can transform the features of the hidden layer according to the distance relationship information between nodes. Denoising has been done. The denoised features contain more information between similar samples, so that the neural network can train a model with good performance without training a large number of samples.

The essence of the graph neural network is to calculate the graph structure relationship between nodes, and apply the calculation results to the fitting of the attribute features of each node.

3.1 The relationship between graph structure and Laplace matrix

Instead of propagating labels, graph convolutions are inherently propagating features. Graph convolution propagates unknown label features to feature nodes with known labels, and uses the classifier of known label nodes to infer the attributes of unknown label features.

The graph convolution model uses the relationship information between nodes to achieve feature propagation. The relationship information between nodes is represented by the processed adjacency matrix. This processed adjacency matrix is ​​called the Laplace matrix/Kirchhoff matrix.

3.2 Steps of graph convolution operation

1. The features of the graph structure are represented by the Laplace matrix.
2. The Laplace matrix is ​​applied to the calculation model of node features to complete the fitting of node features.

The main purpose of the Laplacian matrix is ​​to express the characteristics of the graph structure (decomposition of the characteristics of the matrix), which is a necessary step in the graph convolution operation.

3.3 Three Forms of Laplace Matrix

4 Deep Learning from the Perspective of Graph Neural Networks

  1. Deep learning neural networks are good at processing data in Euclidean space.
  2. Graph neural networks can handle data in non-Euclidean spaces.
  3. In the actual processing process of the graph neural network, the structure of the non-Euclidean space is converted into a matrix to realize. Using the matrix as a bridge, the connection between the neural network and the graph neural network can be found.

4.1 Example to explain the relationship between graph neural network and deep learning (taking common image processing tasks in neural networks as an example)

An image is usually understood as a matrix, each element in the matrix is ​​a pixel, and a pixel is a vector of 3 values ​​of RGB channels. Thinking about it from another angle, a matrix can also be understood as a graph. The graph consists of points and edges, and adjacent points are connected by edges.

4.1.1 Matrices are special graphs

(1) Each point in the matrix has a fixed number of neighbors. From an atlas point of view, the pixels in the image are the points in the atlas. Each pixel in the image, that is, each point in the map, has a total of 8 neighbors around it.
(2) The weight of each edge in the matrix is ​​constant. From the point of view of the map, each pixel in the image only has an edge with the surrounding 8 neighbors, and the weight of the length of the edge is constant.

4.1.2 Limitations of Graphs

As a special kind of map, the image is special in these two constraints. If these two restrictions are relaxed, the problem is more complicated. This is the only way for deep learning algorithms to evolve into graph neural networks.

4 Reasons why graph neural networks use Laplacian matrices

The calculation process of graph convolution is to perform dot product operation on Laplacian matrix and graph node features to realize the fusion of graph structure features into single node features. This problem is mainly explained from the perspective of the propagation relationship between graph nodes.

4.1 Dot Product Effect of Node and Adjacency Matrix

4.1.1 Dot Product Calculation

4.1.2 Analyzing the Aggregate Features of Neighbor Nodes

4.1.3 Conclusion

Performing the dot product operation on the node feature and the adjacency matrix with self-loop is essentially adding each node feature and its own neighbor node feature, that is, adding and aggregating the neighbor node features in the graph .

4.2 Dot Product Effect of Laplace Matrix

A Laplacian matrix is ​​essentially a normalization of an adjacency matrix. In the same way, the dot product effect of the Laplace matrix is ​​essentially the additive aggregation of the features of the neighbor nodes in the graph, except that normalization is added to the additive aggregation process.

4.3 Fitting properties of graph convolution

The operation of integrating graph structure information into node features is essentially to add up the node features of surrounding neighbors according to the relationship between nodes in the graph structure. In this way, in the adjacent node features, there will be feature information of other nodes in each other, which realizes the feature propagation of label nodes.

4.4 Extension of Dot Product Calculation

Using the matrix operation method will have great limitations, because in the calculation process of the node feature and the Laplacian matrix performing the dot product, only the neighbor node features in the graph can be added and aggregated.

In the process of aggregating the neighbor features of the graph nodes, more other mathematical methods (such as taking the average value, the maximum value) can also be used, and are not limited to addition.
 

Guess you like

Origin blog.csdn.net/qq_39237205/article/details/123821765
Recommended