dhg.visualization

Structure Visualization

Graph

dhg.visualization.draw_graph(g, e_style='line', v_label=None, v_size=1.0, v_color='r', v_line_width=1.0, e_color='gray', e_fill_color='whitesmoke', e_line_width=1.0, font_size=1.0, font_family='sans-serif', push_v_strength=1.0, push_e_strength=1.0, pull_e_strength=1.0, pull_center_strength=1.0)[source]

Draw the graph structure. The supported edge styles are: 'line' and 'circle'.

Parameters
  • g (dhg.Graph) – The DHG’s graph object.

  • e_style (str) – The edge style. The supported edge styles are: 'line' and 'circle'. Defaults to 'line'.

  • v_label (list, optional) – A list of vertex labels. Defaults to None.

  • v_size (Union[float, list]) – The vertex size. If v_size is a float, all vertices will have the same size. If v_size is a list, the size of each vertex will be set according to the corresponding element in the list. Defaults to 1.0.

  • v_color (Union[str, list]) – The vertex color. If v_color is a str, all vertices will have the same color. If v_color is a list, the color of each vertex will be set according to the corresponding element in the list. Defaults to 'r'.

  • v_line_width (Union[str, list]) – The vertex line width. If v_line_width is a float, all vertices will have the same line width. If v_line_width is a list, the line width of each vertex will be set according to the corresponding element in the list. Defaults to 1.0.

  • e_color (Union[str, list]) –

    The edge color. If e_color is a str, all edges will have the same color. If e_color is a list, the color of each edge will be set according to the corresponding element in the list. Defaults to 'gray'.

  • e_fill_color (Union[str, list]) – The edge fill color. If e_fill_color is a str, all edges will have the same fill color. If e_fill_color is a list, the fill color of each edge will be set according to the corresponding element in the list. Defaults to 'whitesmoke'. This argument is only valid when e_style is 'circle'.

  • e_line_width (Union[str, list]) – The edge line width. If e_line_width is a float, all edges will have the same line width. If e_line_width is a list, the line width of each edge will be set according to the corresponding element in the list. Defaults to 1.0.

  • font_size (int) – The font size. Defaults to 1.0.

  • font_family (str) – The font family. Defaults to 'sans-serif'.

  • push_v_strength (float) – The vertex push strength. Defaults to 1.0.

  • push_e_strength (float) – The edge push strength. Defaults to 1.0.

  • pull_e_strength (float) – The edge pull strength. Defaults to 1.0.

  • pull_center_strength (float) – The center pull strength. Defaults to 1.0.

Directed Graph

dhg.visualization.draw_digraph(g, e_style='line', v_label=None, v_size=1.0, v_color='r', v_line_width=1.0, e_color='gray', e_line_width=1.0, font_size=1.0, font_family='sans-serif', push_v_strength=1.0, push_e_strength=1.0, pull_e_strength=1.0, pull_center_strength=1.0)[source]

Draw the directed graph structure.

Parameters
  • g (dhg.DiGraph) – The DHG’s directed graph object.

  • e_style (str) – The edge style. The supported styles are only 'line'. Defaults to 'line'.

  • v_label (list) – The vertex label. Defaults to None.

  • v_size (Union[str, list]) – The vertex size. If v_size is a float, all vertices will have the same size. If v_size is a list, the size of each vertex will be set according to the corresponding element in the list. Defaults to 1.0.

  • v_color (Union[str, list]) –

    The vertex color. If v_color is a str, all vertices will have the same color. If v_color is a list, the color of each vertex will be set according to the corresponding element in the list. Defaults to 'r'.

  • v_line_width (Union[str, list]) – The vertex line width. If v_line_width is a float, all vertices will have the same line width. If v_line_width is a list, the line width of each vertex will be set according to the corresponding element in the list. Defaults to 1.0.

  • e_color (Union[str, list]) –

    The edge color. If e_color is a str, all edges will have the same color. If e_color is a list, the color of each edge will be set according to the corresponding element in the list. Defaults to 'gray'.

  • e_line_width (Union[str, list]) – The edge line width. If e_line_width is a float, all edges will have the same line width. If e_line_width is a list, the line width of each edge will be set according to the corresponding element in the list. Defaults to 1.0.

  • font_size (int) – The font size. Defaults to 1.0.

  • font_family (str) – The font family. Defaults to 'sans-serif'.

  • push_v_strength (float) – The vertex push strength. Defaults to 1.0.

  • push_e_strength (float) – The edge push strength. Defaults to 1.0.

  • pull_e_strength (float) – The edge pull strength. Defaults to 1.0.

  • pull_center_strength (float) – The center pull strength. Defaults to 1.0.

Bipartite Graph

dhg.visualization.draw_bigraph(g, e_style='line', u_label=None, u_size=1.0, u_color='m', u_line_width=1.0, v_label=None, v_size=1.0, v_color='r', v_line_width=1.0, e_color='gray', e_line_width=1.0, u_font_size=1.0, v_font_size=1.0, font_family='sans-serif', push_u_strength=1.0, push_v_strength=1.0, push_e_strength=1.0, pull_e_strength=1.0, pull_u_center_strength=1.0, pull_v_center_strength=1.0)[source]

Draw the bipartite graph structure.

Parameters
  • g (dhg.BiGraph) – The DHG’s bipartite graph object.

  • e_style (str) – The edge style. The supported edge styles are only 'line'. Defaults to 'line'.

  • u_label (list) – The label of vertices in set \(\mathcal{U}\). Defaults to None.

  • u_size (Union[str, list]) – The size of vertices in set \(\mathcal{U}\). If u_size is a float, all vertices will have the same size. If u_size is a list, the size of each vertex will be set according to the corresponding element in the list. Defaults to 1.0.

  • u_color (Union[str, list]) –

    The color of vertices in set \(\mathcal{U}\). If u_color is a str, all vertices will have the same color. If u_color is a list, the color of each vertex will be set according to the corresponding element in the list. Defaults to 'm'.

  • u_line_width (Union[str, list]) – The line width of vertices in set \(\mathcal{U}\). If u_line_width is a float, all vertices will have the same line width. If u_line_width is a list, the line width of each vertex will be set according to the corresponding element in the list. Defaults to 1.0.

  • v_label (list) – The label of vertices in set \(\mathcal{V}\). Defaults to None.

  • v_size (Union[str, list]) – The size of vertices in set \(\mathcal{V}\). If v_size is a float, all vertices will have the same size. If v_size is a list, the size of each vertex will be set according to the corresponding element in the list. Defaults to 1.0.

  • v_color (Union[str, list]) –

    The color of vertices in set \(\mathcal{V}\). If v_color is a str, all vertices will have the same color. If v_color is a list, the color of each vertex will be set according to the corresponding element in the list. Defaults to 'r'.

  • v_line_width (Union[str, list]) – The line width of vertices in set \(\mathcal{V}\). If v_line_width is a float, all vertices will have the same line width. If v_line_width is a list, the line width of each vertex will be set according to the corresponding element in the list. Defaults to 1.0.

  • e_color (Union[str, list]) –

    The color of edges. If e_color is a str, all edges will have the same color. If e_color is a list, the color of each edge will be set according to the corresponding element in the list. Defaults to 'gray'.

  • e_line_width (Union[str, list]) – The line width of edges. If e_line_width is a float, all edges will have the same line width. If e_line_width is a list, the line width of each edge will be set according to the corresponding element in the list. Defaults to 1.0.

  • u_font_size (float) – The font size of vertex labels in set \(\mathcal{U}\). Defaults to 1.0.

  • v_font_size (float) – The font size of vertex labels in set \(\mathcal{V}\). Defaults to 1.0.

  • font_family (str) – The font family of vertex labels. Defaults to 'sans-serif'.

  • push_u_strength (float) – The strength of pushing vertices in set \(\mathcal{U}\). Defaults to 1.0.

  • push_v_strength (float) – The strength of pushing vertices in set \(\mathcal{V}\). Defaults to 1.0.

  • push_e_strength (float) – The strength of pushing edges. Defaults to 1.0.

  • pull_e_strength (float) – The strength of pulling edges. Defaults to 1.0.

  • pull_u_center_strength (float) – The strength of pulling vertices in set \(\mathcal{U}\) to the center. Defaults to 1.0.

  • pull_v_center_strength (float) – The strength of pulling vertices in set \(\mathcal{V}\) to the center. Defaults to 1.0.

Hypergraph

dhg.visualization.draw_hypergraph(hg, e_style='circle', v_label=None, v_size=1.0, v_color='r', v_line_width=1.0, e_color='gray', e_fill_color='whitesmoke', e_line_width=1.0, font_size=1.0, font_family='sans-serif', push_v_strength=1.0, push_e_strength=1.0, pull_e_strength=1.0, pull_center_strength=1.0)[source]

Draw the hypergraph structure.

Parameters
  • hg (dhg.Hypergraph) – The DHG’s hypergraph object.

  • e_style (str) – The style of hyperedges. The available styles are only 'circle'. Defaults to 'circle'.

  • v_label (list) – The labels of vertices. Defaults to None.

  • v_size (float or list) – The size of vertices. Defaults to 1.0.

  • v_color (str or list) –

    The color of vertices. Defaults to 'r'.

  • v_line_width (float or list) – The line width of vertices. Defaults to 1.0.

  • e_color (str or list) –

    The color of hyperedges. Defaults to 'gray'.

  • e_fill_color (str or list) –

    The fill color of hyperedges. Defaults to 'whitesmoke'.

  • e_line_width (float or list) – The line width of hyperedges. Defaults to 1.0.

  • font_size (float) – The font size of labels. Defaults to 1.0.

  • font_family (str) – The font family of labels. Defaults to 'sans-serif'.

  • push_v_strength (float) – The strength of pushing vertices. Defaults to 1.0.

  • push_e_strength (float) – The strength of pushing hyperedges. Defaults to 1.0.

  • pull_e_strength (float) – The strength of pulling hyperedges. Defaults to 1.0.

  • pull_center_strength (float) – The strength of pulling vertices to the center. Defaults to 1.0.

Feature Visualization

Feature Visualization in Euclidean Space

dhg.visualization.draw_in_euclidean_space(embeddings, label=None, dim=2, cmap='viridis')[source]

Visualize embeddings in Eulidean Space with t-SNE algorithm.

Parameters
  • feature (np.ndarray) – The feature matrix. Size \((N, C)\).

  • label (np.ndarray, optional) – The label matrix. Size \((N, )\).

  • dim (int) – Project the embedding into dim-dimensional space, which is 2 or 3. Defaults to 2.

  • cmap (str, optional) – The color map. Defaults to "viridis".

Feature Visualization in Poincare Ball

dhg.visualization.project_to_poincare_ball(embeddings, dim=2, reduce_method='pca')[source]

Project embeddings from Euclidean space to Hyperbolic space.

Parameters
  • feature (np.ndarray) – The feature matrix. Size \((N, C)\).

  • dim (int) – Project the embedding into dim-dimensional space, which is 2 or 3. Defaults to 2.

  • reduce_method (str) – The method to project the embedding into low-dimensional space. It can be pca or tsne. Defaults to pca.

dhg.visualization.draw_in_poincare_ball(embeddings, label=None, dim=2, reduce_method='pca', cmap='viridis')[source]

Visualize embeddings in Poincare Ball.

Parameters
  • feature (np.ndarray) – The feature matrix. Size \((N, C)\).

  • label (np.ndarray, optional) – The label matrix. Size \((N, )\). Defaults to None.

  • dim (int) – Project the embedding into dim-dimensional space, which is 2 or 3. Defaults to 2.

  • reduce_method (str) – The method to project the embedding into low-dimensional space. It can be pca or tsne. Defaults to pca.

  • cmap (str, optional) –

    The color map. Defaults to "viridis".

Make Animations

dhg.visualization.animation_of_3d_euclidean_space(embeddings, label=None, cmap='viridis')[source]

Make 3D animation of embeddings visualization of tSNE algorithm. This function will return the animation object ani. You can save the animation by ani.save("animation.gif").

Parameters
  • feature (np.ndarray) – The feature matrix. Size \((N, C)\).

  • label (np.ndarray, optional) – The label matrix. Size \((N, )\). Defaults to None.

  • cmap (str, optional) –

    The color map. Defaults to "viridis".

Example

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from dhg.visualization import animation_of_3d_euclidean_space
>>> x = np.random.rand(100, 32)
>>> ani = animation_of_3d_euclidean_space(x)
>>> plt.show()
>>> ani.save('a.gif')
dhg.visualization.animation_of_3d_poincare_ball(embeddings, label=None, reduce_method='pca', cmap='viridis')[source]

Make 3D animation of embeddings visualization on Poincare Ball. This function will return the animation object ani. You can save the animation by ani.save("animation.gif").

Parameters
  • feature (np.ndarray) – The feature matrix. Size \((N, C)\).

  • label (np.ndarray, optional) – The label matrix. Size \((N, )\). Defaults to None.

  • reduce_method (str) – The method to project the embedding into low-dimensional space. It can be pca or tsne. Defaults to pca.

  • cmap (str, optional) –

    The color map. Defaults to "viridis".

Example

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from dhg.visualization import animation_of_3d_poincare_ball
>>> x = np.random.rand(100, 32)
>>> ani = animation_of_3d_poincare_ball(x)
>>> plt.show()
>>> ani.save('a.gif')