User:Sheng-Yu PJ Huang/sandbox

$$-\min_{x\in X}(\min_{y\in Y}\mid\mid x-y\mid\mid^2_2)$$

In deep learning, a graph neural network (GNN) is a subarea of neural network, which is designed to process graph structured data or data that is able to be formulated as a graph potentially (e.g. social network, polygon mesh, point cloud). Since graph data is non-Euclidean, relations between data points cannot be easily represented by their ordering when recording them, and hence standard CNN is not able to be directly applied to graph data. On the other hand, GNN not only be able to applied to non-Euclidean data but also Euclidean data such as sentences, images or videos since such data can be represented as graph data if organized properly.

Pipeline of a GNN model
The design pipeline for a GNN model can be generally derived as four steps: find graph structure, specify graph, design loss functions, and build model.

Find graph structure
In graph theory, a graph is denoted as $$G=(V,E)$$, where:


 * $$V$$, a set of vertices (also called nodes or points);
 * $$E$$, a set of edges (either directed or undirected, also called links or lines);
 * $$A$$, the given graph's adjacency matrix;
 * $$D$$, the given graph's degree matrix.

If the input data is already in graph structure, then this step is done. Otherwise, you need to observe the data first and reorganize it to be a graph according to your requirement, while not destroying the data's property (so that your model won't face the "garbage in, garbage out" problem).

Specify graph
After a graph structure is found in the given data, the type of this graph should also be specified. A graph can be simply categorize as directed/undirected or homogeneous/heterogeneous. Note that for heterogeneous graphs, each edge may differ to the others by its property. For example, each edge in a scene graph has different meaning to represent the relation between nodes. Sometimes the data's nodes can be merged to obtain graphs of different resolutions, and hence the graph structure may dynamically changed during the learning process. For example, when regarding point cloud as a graph, it is mostly a dynamic graph

Design loss function
Base on the task you are dealing with, loss functions have to be chosen wisely. For example, for a supervised node-level classification task, cross-entropy might be a reasonable choice.

Build model

 * Propagation module: updating information carried by nodes and/or edges by some aggregation methods.
 * Sampling module: when a graph is too large, sampling modules are needed for computation preservation.
 * Pooling module: when higher level information (sub-graph-level, graph-level) is needed for the task, pooling modules are needed to aggregate low-level information and provide hierarchical propagation.

Convolution based methods
The main idea of this type of methods is to generalize standard CNN or attentional methods to graph structured data, and that is, to define some receptive fields with respect to given nodes and propagate information within. Based on the operation domain, we can further divide these methods into two groups, spectral approaches and spatial approaches.

Spectral approaches
For spectral approaches, a graph signal $$x$$ is first transformed to spectral domain by the graph Fourier Transform $$\mathcal{F}$$, then the convolution operation can be conducted. After that, we can transform the result back to the original domain (spatial domain) by the inverse graph Fourier Transform $$\mathcal{F^{-1}}$$. $$\mathcal{F}$$ and $$\mathcal{F^{-1}}$$ are defined as:


 * $$\mathcal{F}(x) = U^{T}x$$
 * $$\mathcal{F^{-1}}(x) = Ux$$,

where $$U$$ is the matrix of eigenvectors of the symmetric normalized graph Laplacian $$L^\text{sym}$$. $$L^\text{sym}$$ is denoted as:

$$L^\text{sym} := D^{-\frac{1}{2}} L D^{-\frac{1}{2}} = I - D^{-\frac{1}{2}} A D^{-\frac{1}{2}} = U\Lambda U^{T}$$ ,

where $$L$$ is the original graph Laplacian, $$I$$ is an identity matrix, and $$\Lambda$$ is a diagonal matrix.

Therefore, based on the convolution's property, the convolution of the signal $$x$$ and a learnable kernel function $$g$$ is defined as:

$$g\star x = \mathcal{F^{-1}}(\mathcal{F}(g)\odot \mathcal{F}(x)) = U(U^Tg\odot U^Tx)$$,

and if we set the learnable kernel function to be a diagonal one $$g_{\theta}$$, this operation is further simplified to:

$$g_{\theta}\star x = Ug_{\theta}U^Tx$$.

=
GCN ===== Given a input graph with $$N$$ nodes and the node feature matrix $$X$$, GCN simplified the convolution layer to $$H^{(l+1)} = \sigma (\tilde{D}^{-1/2}\tilde{A}\tilde{D}^{-1/2}H^{(l)}W^{(l)})$$, where


 * $$\tilde{A} = A + I$$;
 * $$\tilde{D}_{ii} = \textstyle \sum_{j} \displaystyle\tilde{A}_{ij} $$;
 * $$H^{(l)}\in\mathbb{R}^{N\times D}$$ is the input feature map at $$l$$-th layer, $$H^{(0)} = X$$;
 * $$H^{(l+1)}\in\mathbb{R}^{N\times D'}$$ is the output feature map at $$l$$-th layer;
 * $$W^{(l)}\in\mathbb{R}^{D\times D'}$$is the trainable weight matrix at $$l$$-th layer;
 * $$\sigma (\centerdot) $$ is the activation function.

Since both $$\tilde{A}$$ and $$\tilde{D}$$ are able to be pre-calculated, this graph convolution method can be easily accelerated by GPU implementation. Note that this method only suits for undirected graphs with no edge features.

Spatial approaches
Spatial approaches directly design convolution operation on the graph based on the graph topology (hence called spatial), making these methods more flexible compared with spectral approaches. Since the size of neighbors is mostly different for each node within a graph, designing an efficient way to define receptive fields and feature propagation is the prime challenge of such approaches. Unlike spectral approaches that severely affected by the global graph structure, spatial approaches mostly focus on local relations between nodes and edge properties, and the global properties can be found by apply pooling mechanisms between convolution layers properly.

=
GAT and GaAN ===== Attentional networks have already gain huge success in multiple deep learning areas, especially sequenced data related works. As nodes features of a graph can be represented as a unordered dat sequence, the graph attentional network (GAT) and the gated attention network (GaAN) make use of the benefit that multi-head attention model can automatically learn the importance of each neighbor with respect to different heads.

=
GCN for scene graph  ===== Scene graphs have different edge features which indicate the semantic relations between neighboring nodes, and therefore when designing convolution operations on such structure, both node features and edge features are updated. GCN for scene graph usually regard the features of two neighboring nodes and the edge between as a triplet, and update the edge feature by passing this triplet through MLPs. As for node features, the updating method is similar to GCN, instead not only considering neighbor points' feature but also edge features.

=
GCN for point cloud analysis   ===== Point clouds are some point sets lies in 3D space with no edges between each point, so the original format of such data is not a graph. However, we can dynamically construct graph structures from point clouds by connecting points which satisfy given relation (mostly kNN or distance smaller than some thresholds), and the constructed graph can also be dynamically changed when sub-sampling or pooling methods are applied.

KC-Net
The graph in KC-Net is constructed by kNN. They design a 3D kernel which composed of several learnable 3D points, and the convolution of a given point as center is operated by calculate the similarity between each pair of "one kernel point and relative position of one neighboring point of the given center point". KC-Net also provides a graph max-pooling module to better capture higher level features of point clouds.

DGCNN
Convolution method used is DGCNN is using two sets of learnable weights to aggregate feature of a given center point and feature difference between this point and each of its neighbors separately. Although not using pooling module to obtain multi-scale feature, DGCNN dynamically re-define the graph by changing the neighbor number and considering distances in feature space instead of the original 3D space. This idea helps DGCNN better captures semantic information.

KP-Conv
The neighbor points of a given center point of KP-Conv is chosen by a given radius, all the points inside would regard as the center point's neighbor. While the key idea is similar to KC-Net, kernel points of KP-Conv can be either deformable or stable based on the current task. To explore geometry in different scale, KP-Conv provides pooling module by regional sampling.

3D-GCN
Graphs are constructed by kNN. 3D-GCN designs deformable 3D kernels as each kernel has one center kernel point $$k_C\in \mathbb{R}^3$$ and several support points $$k_1, k_2, ... k_S\in \mathbb{R}^3$$. Given a data point $$p_n\in \mathbb{R}^3$$and its neighbor points $$p_1, p_2, ... p_M \in \mathbb{R}^3$$, the convolution is operated by taking the direction vector of the center point to each neighbor $$p_m - p_n$$ and the direction vector of the center kernel point to each support $$k_s - k_C = k_s$$(since $$k_C$$ is set to be $$(0,0,0)$$), calculate their cosine similarity, and then map this similarity to feature space by another learnable parameters $$\mathcal{w}$$. Since the convolution is calculated by cosine similarity instead of exact coordinate, 3D-GCN better captures an 3D object's geometry instead of location, and is totally shift and scale invariant. Similar to KC-Net, 3D-GCN also design a graph max-pooling to explore multi-resolution information, while preserving the largest activation.

=== Recurrent based methods  === Different from convolution based methods which learns different weight at each layer, recurrent based methods tend to use same shared module and recursively update node or edge information, borrowing some RNN approaches such as GRU, LSTM, etc.