venumML.graphs.venum_graph
Represents a Venum encrypted graph that supports encryption and decryption of the adjacency matrix for privacy-preserving computations.
Attributes
- use_hashing (bool): Indicates whether to use hashing for node identifiers.
- nodes (dict): Maps hashed node identifiers to integer indices.
- directed (bool): Specifies if the graph is directed.
- adjacency_matrix (np.ndarray): Encrypted adjacency matrix representing edge weights.
- boolean_matrix (np.ndarray): Encrypted adjacency matrix representing the presence of edges.
- inverse_outbound (np.ndarray): Encrypted array of inverse outbound degree counts for each node.
- boolean_outbound (np.ndarray): Encrypted boolean array indicating nodes with outbound edges.
Initialises an encrypted graph with optional hashing for node identifiers.
Parameters
- ctx (EncryptionContext): The encryption context used to initialise matrices.
- directed (bool, optional, default=True): Whether the graph is directed.
- use_hashing (bool, optional, default=True): Whether to use SHA-256 hashing for node identifiers.
Hashes a node using SHA-256.
Parameters
- node (any): The node identifier.
Returns
- str: The SHA-256 hexadecimal digest of the node.
Checks if the given value is a SHA-256 hash.
Parameters
- value (str): The value to check.
Returns
- bool: True if the value is a valid SHA-256 hash, False otherwise.
Adds a node to the graph after hashing and ensures the adjacency matrix is resized.
Parameters
- ctx (EncryptionContext): The encryption context used to encrypt values.
- node (any): The node identifier.
Adds a weighted edge between two nodes.
Parameters
- ctx (EncryptionContext): The encryption context used to encrypt values.
- from_node (any): The starting node of the edge.
- to_node (any): The ending node of the edge.
- weight (float, optional, default=1): The weight of the edge.
Removes an edge between two nodes by setting the matrix value to 0.
Parameters
- from_node (any): The starting node of the edge.
- to_node (any): The ending node of the edge.
Returns the weight of an edge between two nodes.
Parameters
- from_node (any): The starting node of the edge.
- to_node (any): The ending node of the edge.
Returns
- float or int: The weight of the edge, or 0 if no edge exists.
Retrieves the encrypted adjacency matrix.
Returns
- np.ndarray: The current encrypted adjacency matrix.
Converts a NetworkX graph to an encrypted custom Graph.
Parameters
- ctx (EncryptionContext): The encryption context used to encrypt node and edge data.
- nx_graph (networkx.Graph or networkx.DiGraph): The NetworkX graph to convert.
- use_hashing (bool, optional, default=True): Whether to hash node identifiers.
Returns
- Graph: An encrypted custom Graph with nodes, edges, and outbound counts encrypted.
Creates an encrypted custom Graph from a pandas DataFrame.
Parameters
- ctx (EncryptionContext): The encryption context used to encrypt node and edge data.
- df (pd.DataFrame): DataFrame containing the edge data.
- from_col (str): Column name representing the source node.
- to_col (str): Column name representing the target node.
- weight_col (str): Column name representing the edge weight.
- use_hashing (bool, optional, default=True): Whether to hash node identifiers.
Returns
- Graph: An encrypted custom Graph with nodes, edges, and outbound counts encrypted.
Decrypts an encrypted adjacency matrix of an encrypted Graph.
Parameters
- ctx (EncryptionContext): The encryption context used to decrypt values.
- custom_graph (Graph): The encrypted Graph to decrypt.
Returns
- networkx.Graph or networkx.DiGraph: A decrypted NetworkX graph with nodes and edges restored.
Computes PageRank scores for an encrypted Graph using the Power Method.
Parameters
- ctx (EncryptionContext): The encryption context used to handle encrypted values.
- encrypted_graph (Graph): The encrypted custom Graph on which to compute PageRank.
- damping_factor (float, optional, default=0.85): The probability of following an edge; 1 - damping_factor is the teleport probability.
- iters (int, optional, default=20): The number of iterations for the Power Method.
Returns
- dict: A dictionary mapping node identifiers to encrypted PageRank scores.
Decrypts encrypted PageRank scores.
Parameters
- ctx (EncryptionContext): The encryption context used to decrypt values.
- encrypted_pagerank (dict): A dictionary mapping node identifiers to encrypted PageRank scores.
Returns
- dict: A dictionary mapping node identifiers to decrypted PageRank scores.