Skip to content

graph_generation

Vishesh edited this page Oct 26, 2024 · 2 revisions

import vish_graph as vg

VishGraphs Module Documentation

The vishgraphs module provides functionalities for graph manipulation and visualization. It supports operations like generating random graphs, creating weight matrices, and visualizing graphs in 2D and 3D.

Functions

1. generate_random_graph

Generates a random adjacency matrix for a graph and saves it to a CSV file.

  • Parameters:
    • num_people (int): Number of nodes (people) in the graph.
    • file_path (str): Path to save the generated adjacency matrix (default: "graph_dataset.csv").
    • seed (int, optional): Seed for reproducibility.
  • Returns:
    • file_path (str): Path to the saved adjacency matrix file.
  • Usage:
    • Generates a random graph with connections between nodes based on a specified probability.

2. generate_large_random_graph

Generates a large random adjacency matrix using multiprocessing and saves it to a CSV file.

  • Parameters:
    • num_people (int): Number of nodes in the graph.
    • file_path (str): Path to save the generated adjacency matrix (default: "large_random_graph.csv").
    • seed (int, optional): Seed for reproducibility.
  • Returns:
    • file_path (str): Path to the saved adjacency matrix file.
  • Usage:
    • Optimized for generating large graphs using multiprocessing for faster performance.

3. generate_weight_matrix

Generates a random weight matrix for a given number of nodes.

  • Parameters:
    • num_nodes (int): Number of nodes in the graph.
    • weight_range (tuple): Range for the random weights (default: (1, 10)).
    • file_path (str): Path to save the weight matrix (default: "weight_matrix.csv").
    • seed (int, optional): Seed for reproducibility.
  • Returns:
    • file_path (str): Path to the saved weight matrix file.
  • Usage:
    • Generates random weights for the edges of a graph.

4. find_top_nodes

Finds the top nodes based on the number of strong correlations (mutual connections).

  • Parameters:
    • matrix (numpy.ndarray): Adjacency matrix of the graph.
    • num_nodes (int): Number of top nodes to return (default: 3).
  • Returns:
    • top_nodes (list): List of node indices with the highest correlations.
  • Usage:
    • Identifies the most connected nodes in a graph.

5. export_graph_data_to_csv

Exports the adjacency matrix and node labels to a CSV file.

  • Parameters:
    • adj_matrix (numpy.ndarray): Adjacency matrix of the graph.
    • node_labels (dict): Dictionary mapping node indices to labels.
    • csv_file (str): Path to the output CSV file.
  • Usage:
    • Saves the graph structure and node metadata for analysis or visualization.

6. draw_graph

Draws a 2D visualization of the graph.

  • Parameters:
    • adj_matrix (numpy.ndarray): Adjacency matrix of the graph.
    • top_nodes (list, optional): Nodes to highlight in red.
    • recommended_nodes (list, optional): Nodes to highlight in green.
    • node_labels (dict, optional): Labels for nodes.
    • transparent_labeled (bool): Controls the transparency of non-labeled nodes.
    • edge_weights (numpy.ndarray, optional): Edge weights for visualization.
  • Usage:
    • Visualizes the graph with node highlights and optional edge weights.

7. draw_graph_3d

Draws a 3D visualization of the graph.

  • Parameters:
    • adj_matrix (numpy.ndarray): Adjacency matrix of the graph.
    • top_nodes (list, optional): Nodes to highlight in red.
    • recommended_nodes (list, optional): Nodes to highlight in green.
    • node_labels (dict, optional): Labels for nodes.
    • transparent_labeled (bool): Controls the transparency of non-labeled nodes.
    • edge_weights (numpy.ndarray, optional): Edge weights for visualization.
  • Usage:
    • Provides a 3D representation of graph structure with color-coded nodes.

8. show_bipartite_relationship

Displays a bipartite relationship based on the adjacency matrix.

  • Parameters:
    • adj_matrix (numpy.ndarray): Adjacency matrix of the graph.
  • Usage:
    • Visualizes bipartite relationships in a graph.

9. show_bipartite_relationship_with_cosine

Displays a bipartite graph using cosine similarity-based communities.

  • Parameters:
    • adj_matrix (numpy.ndarray): Adjacency matrix of the graph.
  • Usage:
    • Creates a bipartite visualization based on similarity between nodes and highlights detected communities.

10. bipartite_matrix_maker

Creates an adjacency matrix from a CSV file for bipartite visualization.

  • Parameters:
    • csv_path (str): Path to the CSV file containing the adjacency matrix.
  • Returns:
    • adj_matrix (numpy.ndarray): Adjacency matrix loaded from the CSV file.
  • Usage:
    • Loads graph data from a CSV file for further analysis or visualization.

Notes

  • The module relies on networkx for graph operations and matplotlib for visualization.
  • For large graphs, the functions use sparse matrices (lil_matrix, csr_matrix) for efficient memory management.
  • 3D visualizations are particularly suitable for understanding the spatial relationships in large networks.