|
1 | 1 | 特征可视化 |
2 | 2 | ========================= |
3 | 3 |
|
4 | | -即将上线! |
| 4 | +.. hint:: |
5 | 5 |
|
6 | | -.. Basic Usages |
7 | | -.. --------------- |
| 6 | + - 作者: 唐青梅 |
| 7 | + - 翻译:颜杰龙 |
| 8 | + - 校对: `丰一帆 <https://fengyifan.site/>`_ |
8 | 9 |
|
9 | | -.. draw feature in Euclidean space, draw feature in manifold space |
| 10 | +Basic Usages |
| 11 | +--------------- |
| 12 | +DHG provides an interface to visualize the distribution of feaures: |
10 | 13 |
|
11 | | -.. Make Animation |
12 | | -.. ------------------------- |
| 14 | +1. Input the features and lable (optional); |
| 15 | +2. Specify parameters (*i.e.*, `the dimensionality of the visualisation`, `point size`, `color` and `the method of dimensionality reduction`); |
| 16 | +3. Call ``plt.show()`` funtion to show the figure/animation. |
13 | 17 |
|
| 18 | + |
| 19 | +.. note:: The ``plt`` is short for ``matplotlib.pyplot`` module. |
| 20 | + |
| 21 | + |
| 22 | +Visualization of Features in Euclidean Space |
| 23 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 24 | + |
| 25 | +.. image:: ../_static/img/vis_ft_euclidean.png |
| 26 | + :align: center |
| 27 | + :alt: Visualization of Features in Euclidean Space |
| 28 | + :height: 400px |
| 29 | + |
| 30 | + |
| 31 | +.. code-block:: python |
| 32 | +
|
| 33 | + >>> import dhg |
| 34 | + >>> import numpy as np |
| 35 | + >>> import matplotlib.pyplot as plt |
| 36 | + >>> import dhg.visualization as vis |
| 37 | + >>> lbl = (np.random.rand(200)*10).astype(int) |
| 38 | + >>> ft = dhg.random.normal_features(lbl) |
| 39 | + >>> vis.draw_in_euclidean_space(ft, lbl) |
| 40 | + >>> plt.show() |
| 41 | +
|
| 42 | +
|
| 43 | +Visualization of Features in Poincare Space |
| 44 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 45 | + |
| 46 | +.. image:: ../_static/img/vis_ft_poincare.png |
| 47 | + :align: center |
| 48 | + :alt: Visualization of Features in Poincare Space |
| 49 | + :height: 400px |
| 50 | + |
| 51 | + |
| 52 | +.. code-block:: python |
| 53 | +
|
| 54 | + >>> import dhg |
| 55 | + >>> import numpy as np |
| 56 | + >>> import matplotlib.pyplot as plt |
| 57 | + >>> import dhg.visualization as vis |
| 58 | + >>> lbl = (np.random.rand(200)*10).astype(int) |
| 59 | + >>> ft = dhg.random.normal_features(lbl) |
| 60 | + >>> vis.draw_in_poincare_space(ft, lbl) |
| 61 | + >>> plt.show() |
| 62 | +
|
| 63 | +
|
| 64 | +Make Animation |
| 65 | +------------------------- |
| 66 | + |
| 67 | +We provide functions to make 3D rotation animation for feature visualization. |
| 68 | + |
| 69 | +Rotating Visualization of Features in Euclidean Space |
| 70 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 71 | + |
| 72 | +.. image:: ../_static/img/vis_ft_euclidean_ani.png |
| 73 | + :align: center |
| 74 | + :alt: Rotating Visualization of Features in Euclidean Space |
| 75 | + :height: 400px |
| 76 | + |
| 77 | + |
| 78 | +.. code-block:: python |
| 79 | +
|
| 80 | + >>> import dhg |
| 81 | + >>> import numpy as np |
| 82 | + >>> import matplotlib.pyplot as plt |
| 83 | + >>> import dhg.visualization as vis |
| 84 | + >>> lbl = (np.random.rand(200)*10).astype(int) |
| 85 | + >>> ft = dhg.random.normal_features(lbl) |
| 86 | + >>> vis.animation_of_3d_euclidean_space(ft, lbl) |
| 87 | + >>> plt.show() |
| 88 | +
|
| 89 | +.. |
| 90 | + >>> import numpy as np |
| 91 | + >>> from dhg.visualization.feature import animation_of_3d_euclidean_ball |
| 92 | + >>> ile_dir = "data/modelnet40/test_img_feat_4.npy" |
| 93 | + >>> save_dir = None # None for show now or file name to save |
| 94 | + >>> label = np.load("data/modelnet40/test_label.npy") |
| 95 | + >>> ft = np.load(file_dir) |
| 96 | + >>> d = 3 |
| 97 | + >>> low_demen_method = "tsne" # vis for poincare_ball: pca or tsne |
| 98 | + >>> show_method = "Rotation" # None for 2d or Rotation and Drag for 3d |
| 99 | + >>> animation_of_3d_euclidean_ball( |
| 100 | + ft, save_dir, d, label, reduce_method=low_demen_method, auto_play=show_method |
| 101 | + ) |
| 102 | +
|
| 103 | +Rotating Visualization of Features in Poincare Space |
| 104 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 105 | + |
| 106 | +.. image:: ../_static/img/vis_ft_poincare_ani.png |
| 107 | + :align: center |
| 108 | + :alt: Rotating Visualization of Features in Poincare Space |
| 109 | + :height: 400px |
| 110 | + |
| 111 | + |
| 112 | +.. code-block:: python |
| 113 | +
|
| 114 | + >>> import dhg |
| 115 | + >>> import numpy as np |
| 116 | + >>> import matplotlib.pyplot as plt |
| 117 | + >>> import dhg.visualization as vis |
| 118 | + >>> lbl = (np.random.rand(200)*10).astype(int) |
| 119 | + >>> ft = dhg.random.normal_features(lbl) |
| 120 | + >>> vis.animation_of_3d_poincare_ball(ft, lbl) |
| 121 | + >>> plt.show() |
| 122 | +
|
| 123 | +.. |
| 124 | + >>> import numpy as np |
| 125 | + >>> from dhg.visualization.feature import animation_of_3d_poincare_ball |
| 126 | + >>> file_dir = "data/modelnet40/test_img_feat_4.npy" #This varies depending on the situation |
| 127 | + >>> save_dir = None # None for show now or file name to save |
| 128 | + >>> label = np.load("data/modelnet40/test_label.npy") |
| 129 | + >>> ft = np.load(file_dir) |
| 130 | + >>> d = 3 |
| 131 | + >>> low_demen_method = "tsne" # vis for poincare_ball, pca or tsne |
| 132 | + >>> show_method = "Rotation" # None for 2d or Rotation and Drag for 3d |
| 133 | + >>> animation_of_3d_poincare_ball( |
| 134 | + ft, save_dir, d, label, reduce_method=low_demen_method, auto_play=show_method |
| 135 | + ) |
| 136 | +
|
| 137 | + |
| 138 | + |
| 139 | +Mathamatical Principles of Hyperbolic Space |
| 140 | +-------------------------------------------------- |
| 141 | + |
| 142 | +The hyperbolic space is a manifold with constant Gaussian constant negative curvature everywhere, |
| 143 | +which has several models. We base our work on the Poincaré ball model for its well-suited for gradient-based optimization. |
| 144 | + |
| 145 | +The Poincaré ball model with constant negative curvature :math:`-1 / k(k>0)` corresponds to the |
| 146 | +Riemannian manifold |
| 147 | +:math:`\left(\mathbb{P}^{n,k}, g_{\mathbf{x}}^{\mathbb{P}}\right)`. |
| 148 | +:math:`\mathbb{P}^{n,k} = \left\{\mathbf{x} \in \mathbb{R}^{n}: \| \mathbf{x}\|<1 \right\}` is an open :math:`n`-demensionsional unit ball, |
| 149 | +where :math:`\|. \|` denotes the Euclidean norm. Its metric tensor is :math:`g_{\mathbf{x}}^{\mathbb{P}} = \lambda_{\mathbf{x}}^{2} g^{E}`, |
| 150 | +where :math:`\lambda_{\mathbf{x}} = \frac{2} {1- k\|\mathbf{x}\|^{2} }` is the conformal factor and :math:`g^{E}=\mathbf{I}_{n}` is the Euclidean metric tensor. |
| 151 | +For two points :math:`\mathbf{x}, \mathbf{y} \in \mathbb{P}^{n,k}`, we ues the Möbius addition :math:`\oplus` operate adding |
| 152 | +by connecting the gyrospace framework with Riemannian geometry: |
| 153 | + |
| 154 | +.. math:: |
| 155 | +
|
| 156 | + \mathbf{x} \oplus_{k} \mathbf{y} =\frac{\left(1+2k\langle\mathbf{x}, \mathbf{y}\rangle+k\|\mathbf{y}\|^{2}\right) \mathbf{x}+\left(1-k\|\mathbf{x}\|^{2}\right) \mathbf{y}}{1+2k\langle\mathbf{x}, \mathbf{y}\rangle+k^{2}\|\mathbf{x}\|^{2}\|\mathbf{y}\|^{2}} . |
| 157 | +
|
| 158 | +The distance between two points :math:`\mathbf{x}, \mathbf{y} \in \mathbb{P}^{n,k}` is calculated by integration of the metric tensor, which is given as: |
| 159 | + |
| 160 | +.. math:: |
| 161 | +
|
| 162 | + d_{\mathbb{P}}^{k} (\mathbf{x}, \mathbf{y}) = (2 / \sqrt{K}) \tanh ^{-1}\left(\sqrt{k}\left\|-x \oplus_{k} y\right\|\right) . |
| 163 | +
|
| 164 | +
|
| 165 | +Denote point :math:`\mathbf{z} \in \mathcal{T}_{\mathrm{x}} \mathbb{P}^{n,k}` the tangent (Euclidean) space centered at any point :math:`\mathbf{x}` in the hyperbolic space. |
| 166 | +For the tangent vector :math:`\mathbf{z} \neq \mathbf{0}` and the point :math:`\mathbf{y} \neq \mathbf{0}`, |
| 167 | +the exponential map :math:`\exp _{\mathbf{x}}: \mathcal{T}_{\mathbf{x}} \mathbb{P}^{n,k} \rightarrow \mathbb{P}^{n,k}` and |
| 168 | +the logarithmic map :math:`\log_{\mathbf{x}}: \mathbb{P}^{n,k} \rightarrow \mathcal{T}_{\mathbf{x}} \mathbb{P}^{n,k}` are given for |
| 169 | +:math:`\mathbf{y} \neq \mathbf{x}` by: |
| 170 | + |
| 171 | +.. math:: |
| 172 | +
|
| 173 | + \exp _{\mathbf{x}}^{k}(\mathbf{z})=\mathbf{x} \oplus_{k}\left(\tanh \left(\sqrt{k} \frac{\lambda_{\mathbf{x}}^{k}\|\mathbf{z}\|}{2}\right) \frac{\mathbf{z}}{\sqrt{k}\|\mathbf{z}\|}\right), |
| 174 | +
|
| 175 | +and |
| 176 | + |
| 177 | +.. math:: |
| 178 | +
|
| 179 | + \log _{\mathbf{x}}^{k}(\mathbf{y})=\frac{2}{\sqrt{k} \lambda_{\mathbf{x}}^{k}} \tanh ^{-1}\left(\sqrt{k}\left\|-\mathbf{x} \oplus_{k} \mathbf{y}\right\|\right) \frac{-\mathbf{x} \oplus_{k} \mathbf{y}}{\left\|-\mathbf{x} \oplus_{k} \mathbf{y}\right\|} . |
| 180 | +
|
| 181 | +It is noted that our initial data are on Euclidean space and need to be converted to embeddings on hyperbolic space, so first project the data on the previously obtained Euclidean space onto the hyperbolic manifold space |
| 182 | +in order to use the Spectral-based hypergraph hyperbolic convolutional network to learn the information to update the node embeddings. |
| 183 | +Set :math:`t:=\{\sqrt{K}, 0, 0, \dots, 0\}\in\mathbb{P}^{d, K}` as a reference point to perform tangent space operations, |
| 184 | +where :math:`-1/K` is the negative curvature of hyperbolic model. |
| 185 | +The above premise makes :math:`\langle(0, \mathbf{x}^{0, E}), t\rangle=0` hold, |
| 186 | +so :math:`(0, \mathbf{x}^{0, E})` can be regarded as the initial embedding representation of the hypergraph structure on the tangent plane |
| 187 | +of the hyperbolic manifold space :math:`\mathcal{T}_t\mathbb{P}^{d, K}`. The initial hypergraph structure embedding is |
| 188 | +then mapped onto the hyperbolic manifold space :math:`\mathbb{P}` using the following equation: |
| 189 | + |
| 190 | +.. math:: |
| 191 | +
|
| 192 | + \mathbf{x}^{0, \mathbb{P}} &=\exp _{t}^{K}\left(\left(0, \mathbf{x}^{0, \mathrm{E}}\right)\right) \\ |
| 193 | + &=\left(\sqrt{K} \cosh \left(\frac{\left\|\mathbf{x}^{0, \mathbb{E}}\right\|_{2}}{\sqrt{K}}\right), |
| 194 | + \sqrt{K} \sinh \left(\frac{\left\|\mathbf{x}^{0, \mathbb{E}}\right\|_{2}}{\sqrt{K}}\right) \frac{\mathbf{x}^{0, \mathbb{E}}}{\left\|\mathbf{x}^{0, \mathbb{E}}\right\|_{2}}\right). |
| 195 | +
|
| 196 | +The hyperbolic operation is accomplished by means of a feature mapping between Euclidean space and Hyperbolic space. |
14 | 197 |
|
15 | | -.. Mathamatical Principles |
16 | | -.. --------------------------- |
17 | 198 |
|
18 | | -.. hyperbolic space |
|
0 commit comments