|
1 | 1 | Feature Visualization |
2 | 2 | ========================= |
3 | 3 |
|
4 | | -Coming soon! |
| 4 | +Basic Usage |
| 5 | +--------------- |
| 6 | +DHG provides an interface to visualize the distribution of feaures: |
5 | 7 |
|
6 | | -.. Basic Usage |
7 | | -.. --------------- |
| 8 | +1. Load data of features and lable by specifying the corresponding path; |
| 9 | +2. Specify parameters (*i.e.*, `the dimensionality of the visualisation`, `the storage path` and `the method of dimensionality reduction`); |
| 10 | +3. Call our funtion to show or save the figure . |
8 | 11 |
|
9 | | -.. draw feature in Euclidean space, draw feature in manifold space |
10 | 12 |
|
11 | | -.. Make Animation |
12 | | -.. ------------------------- |
13 | 13 |
|
| 14 | +Visualization of Features in Euclidean Space |
| 15 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 16 | + |
| 17 | +.. image:: ../_static/img/vis_ft_euclidean.png |
| 18 | + :align: center |
| 19 | + :alt: Visualization of Features in Euclidean Space |
| 20 | + :height: 400px |
| 21 | + |
| 22 | + |
| 23 | +.. code-block:: python |
| 24 | +
|
| 25 | + >>> import numpy as np |
| 26 | + >>> from dhg.visualization.feature import draw_in_euclidean_space |
| 27 | + >>> ile_dir = "data/modelnet40/test_img_feat_4.npy" |
| 28 | + >>> save_dir = None # None for show now or file name to save |
| 29 | + >>> label = np.load("data/modelnet40/test_label.npy") |
| 30 | + >>> ft = np.load(file_dir) |
| 31 | + >>> d = 2 |
| 32 | + >>> low_demen_method = "tsne" # vis for poincare_ball: pca or tsne |
| 33 | + >>> show_method = None # None for 2d or Rotation and Drag for 3d |
| 34 | + >>> draw_in_euclidean_ball( |
| 35 | + ft, save_dir, d, label, reduce_method=low_demen_method, auto_play=show_method |
| 36 | + ) |
| 37 | +
|
| 38 | +Visualization of Features in Poincare Space |
| 39 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 40 | + |
| 41 | +.. image:: ../_static/img/vis_ft_poincare.png |
| 42 | + :align: center |
| 43 | + :alt: Visualization of Features in Poincare Space |
| 44 | + :height: 400px |
| 45 | + |
| 46 | + |
| 47 | +.. code-block:: python |
| 48 | +
|
| 49 | + >>> import numpy as np |
| 50 | + >>> from dhg.visualization.feature import draw_in_poincare_space |
| 51 | + >>> file_dir = "data/modelnet40/test_img_feat_4.npy" #This varies depending on the situation |
| 52 | + >>> save_dir = None # None for show now or file name to save |
| 53 | + >>> label = np.load("data/modelnet40/test_label.npy") |
| 54 | + >>> ft = np.load(file_dir) |
| 55 | + >>> d = 2 |
| 56 | + >>> low_demen_method = "tsne" # vis for poincare_ball, pca or tsne |
| 57 | + >>> show_method = None # None for 2d or Rotation and Drag for 3d |
| 58 | + >>> draw_in_poincare_ball( |
| 59 | + ft, save_dir, d, label, reduce_method=low_demen_method, auto_play=show_method |
| 60 | + ) |
| 61 | +
|
| 62 | +
|
| 63 | +Make Animation |
| 64 | +------------------------- |
| 65 | +Furthermore, we also offer interfaces for the visual presentation of |
| 66 | +rotation on three-dimensional visualisations with the option of `Rotation` in Euclidean and Poincare Space. |
| 67 | + |
| 68 | +Rotating Visualization of Features in Euclidean Space |
| 69 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 70 | + |
| 71 | +.. .. image:: ../_static/img/vis_ft_euclidean.png |
| 72 | +.. :align: center |
| 73 | +.. :alt: Rotating Visualization of Features in Euclidean Space |
| 74 | +.. :height: 400px |
| 75 | +
|
| 76 | +
|
| 77 | +.. code-block:: python |
| 78 | +
|
| 79 | + >>> import numpy as np |
| 80 | + >>> from dhg.visualization.feature import animation_of_3d_euclidean_ball |
| 81 | + >>> ile_dir = "data/modelnet40/test_img_feat_4.npy" |
| 82 | + >>> save_dir = None # None for show now or file name to save |
| 83 | + >>> label = np.load("data/modelnet40/test_label.npy") |
| 84 | + >>> ft = np.load(file_dir) |
| 85 | + >>> d = 3 |
| 86 | + >>> low_demen_method = "tsne" # vis for poincare_ball: pca or tsne |
| 87 | + >>> show_method = "Rotation" # None for 2d or Rotation and Drag for 3d |
| 88 | + >>> animation_of_3d_euclidean_ball( |
| 89 | + ft, save_dir, d, label, reduce_method=low_demen_method, auto_play=show_method |
| 90 | + ) |
| 91 | +
|
| 92 | +Rotating Visualization of Features in Poincare Space |
| 93 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 94 | + |
| 95 | +.. .. image:: ../_static/img/vis_ft_euclidean.png |
| 96 | +.. :align: center |
| 97 | +.. :alt: Rotating Visualization of Features in Poincare Space |
| 98 | +.. :height: 400px |
| 99 | +
|
| 100 | +
|
| 101 | +.. code-block:: python |
| 102 | +
|
| 103 | + >>> import numpy as np |
| 104 | + >>> from dhg.visualization.feature import animation_of_3d_poincare_ball |
| 105 | + >>> file_dir = "data/modelnet40/test_img_feat_4.npy" #This varies depending on the situation |
| 106 | + >>> save_dir = None # None for show now or file name to save |
| 107 | + >>> label = np.load("data/modelnet40/test_label.npy") |
| 108 | + >>> ft = np.load(file_dir) |
| 109 | + >>> d = 3 |
| 110 | + >>> low_demen_method = "tsne" # vis for poincare_ball, pca or tsne |
| 111 | + >>> show_method = "Rotation" # None for 2d or Rotation and Drag for 3d |
| 112 | + >>> animation_of_3d_poincare_ball( |
| 113 | + ft, save_dir, d, label, reduce_method=low_demen_method, auto_play=show_method |
| 114 | + ) |
| 115 | +
|
| 116 | +
|
| 117 | +
|
| 118 | +Mathamatical Principles of Hyperbolic Space |
| 119 | +--------------------------- |
| 120 | +The hyperbolic space is a manifold with constant Gaussian constant negative curvature everywhere, |
| 121 | +which has several models. We base our work on the Poincaré ball model for its well-suited for gradient-based optimization. |
| 122 | + |
| 123 | +The Poincaré ball model with constant negative curvature :math:`-1 / k(k>0)` corresponds to the |
| 124 | +Riemannian manifold |
| 125 | +:math:`\left(\mathbb{P}^{n,k}, g_{\mathbf{x}}^{\mathbb{P}}\right)`. |
| 126 | +:math:`\mathbb{P}^{n,k} = \left\{\mathbf{x} \in \mathbb{R}^{n}: \| \mathbf{x}\|<1 \right\}` is an open :math:`n`-demensionsional unit ball, |
| 127 | +where :math:`\|. \|` denotes the Euclidean norm. Its metric tensor is :math:`g_{\mathbf{x}}^{\mathbb{P}} = \lambda_{\mathbf{x}}^{2} g^{E}`, |
| 128 | +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. |
| 129 | +For two points :math:`\mathbf{x}, \mathbf{y} \in \mathbb{P}^{n,k}`, we ues the Möbius addition :math:`\oplus` operate adding |
| 130 | +by connecting the gyrospace framework with Riemannian geometry: |
| 131 | + |
| 132 | +.. math:: |
| 133 | +
|
| 134 | + \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}} . |
| 135 | +
|
| 136 | +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: |
| 137 | + |
| 138 | +.. math:: |
| 139 | +
|
| 140 | + d_{\mathbb{P}}^{k} (\mathbf{x}, \mathbf{y}) = (2 / \sqrt{K}) \tanh ^{-1}\left(\sqrt{k}\left\|-x \oplus_{k} y\right\|\right) . |
| 141 | + % \operatorname{arcosh} \left(1+2 \frac{\|\mathbf{x}-\mathbf{y}\|^{2}}{ \left(1- \|\mathbf{x}\|^{2} \right) \left(1- \|\mathbf{y}\|^{2} \right)} \right) |
| 142 | +
|
| 143 | +
|
| 144 | +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. |
| 145 | +For the tangent vector :math:`\mathbf{z} \neq \mathbf{0}` and the point :math:`\mathbf{y} \neq \mathbf{0}`, |
| 146 | +the exponential map :math:`\exp _{\mathbf{x}}: \mathcal{T}_{\mathbf{x}} \mathbb{P}^{n,k} \rightarrow \mathbb{P}^{n,k}` and |
| 147 | +the logarithmic map :math:`\log_{\mathbf{x}}: \mathbb{P}^{n,k} \rightarrow \mathcal{T}_{\mathbf{x}} \mathbb{P}^{n,k}` are given for |
| 148 | +:math:`\mathbf{y} \neq \mathbf{x}` by: |
| 149 | + |
| 150 | +.. math:: |
| 151 | +
|
| 152 | + % \exp_{\mathbf{x}} (\mathbf{v}) = \mathbf{x} \oplus \left( \tanh \left(\frac{\lambda_{\mathbf{x}} \|\mathbf{v}\|}{2} \right) \frac{\mathbf{v}} {\|\mathbf{v}\|} \right) |
| 153 | + \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), |
| 154 | +
|
| 155 | +and |
| 156 | + |
| 157 | +.. math:: |
| 158 | +
|
| 159 | + % \log_{\mathbf{x}} (\mathbf{y}) = \frac{2} {\lambda_{\mathbf{x}}} \operatorname{arctanh}(\|-\mathbf{x} \oplus \mathbf{y}\|) \frac{-\mathbf{x} \oplus \mathbf{y}}{\|-\mathbf{x} \oplus \mathbf{y}\|} |
| 160 | + \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\|} . |
| 161 | +
|
| 162 | +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 |
| 163 | +in order to use the Spectral-based hypergraph hyperbolic convolutional network to learn the information to update the node embeddings. |
| 164 | +Set :math:`t:=\{\sqrt{K}, 0, 0, \dots, 0\}\in\mathbb{P}^{d, K}` as a reference point to perform tangent space operations, |
| 165 | +where :math:`-1/K` is the negative curvature of hyperbolic model. |
| 166 | +The above premise makes :math:`\langle(0, \mathbf{x}^{0, E}), t\rangle=0` hold, |
| 167 | +so :math:`(0, \mathbf{x}^{0, E})` can be regarded as the initial embedding representation of the hypergraph structure on the tangent plane |
| 168 | +of the hyperbolic manifold space :math:`\mathcal{T}_t\mathbb{P}^{d, K}`. The initial hypergraph structure embedding is |
| 169 | +then mapped onto the hyperbolic manifold space :math:`\mathbb{P}` using the following equation: |
| 170 | + |
| 171 | +.. math:: |
| 172 | +
|
| 173 | + &\mathbf{x}^{0, \mathbb{P}} =\exp _{t}^{K}\left(\left(0, \mathbf{x}^{0, \mathrm{E}}\right)\right) \\ |
| 174 | + &=\left(\sqrt{K} \cosh \left(\frac{\left\|\mathbf{x}^{0, \mathbb{E}}\right\|_{2}}{\sqrt{K}}\right), |
| 175 | + \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). |
| 176 | +
|
| 177 | +The hyperbolic operation is accomplished by means of a feature mapping between Euclidean space and Hyperbolic space. |
14 | 178 |
|
15 | | -.. Mathamatical Principles |
16 | | -.. --------------------------- |
17 | 179 |
|
18 | | -.. hyperbolic space |
|
0 commit comments