Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hope Algorithm Implementation Question #158

Open
ahmedlebo opened this issue Jun 2, 2024 · 3 comments
Open

Hope Algorithm Implementation Question #158

ahmedlebo opened this issue Jun 2, 2024 · 3 comments

Comments

@ahmedlebo
Copy link

In the paper:Asymmetric Transitivity Preserving Graph Embedding,the authors state that they will not calculate S in this part
Screen Shot 2024-06-02 at 7 56 50 PM
so that in this algorithm, they do not explicitly perform the polynomial operation on adjacency matrix in Ml and Mg, but in the implementation the S matrix is calculated fully as this shows,
Screen Shot 2024-06-02 at 7 57 38 PM

I can't understand it so anyone please could explain this to me

@ahmedlebo
Copy link
Author

ahmedlebo commented Jun 5, 2024

Does anyone share the same problem or has a different point of view or there something i am missing in the paper

@VaradScript
Copy link

It seems like you're trying to describe a Python implementation of a method for generating a target similarity matrix and performing a rescaled decomposition, likely for a graph embedding or matrix factorization task.

@VaradScript
Copy link

import numpy as np
import scipy.sparse as sps
from scipy.sparse.linalg import svds

class GraphEmbedding:
def init(self, dimensions):
self.dimensions = dimensions
self._left_embedding = None
self._right_embedding = None

def create_target(self, graph):
    """
    Creates a target similarity matrix for the given graph.
    
    Parameters:
    graph : networkx.Graph
        Input graph for which the similarity matrix is created.
    
    Returns:
    S : scipy.sparse.coo_matrix
        Target similarity matrix.
    """
    number_of_nodes = graph.number_of_nodes()
    A = nx.adjacency_matrix(graph, nodelist=range(number_of_nodes))
    S = sps.coo_matrix(A.dot(A), dtype=np.float32)
    return S

def do_rescaled_decomposition(self, S):
    """
    Performs Singular Value Decomposition (SVD) on the similarity matrix
    and rescales the results to compute embeddings.
    
    Parameters:
    S : scipy.sparse.coo_matrix
        Input similarity matrix.
    """
    U, sigmas, Vt = svds(S, k=int(self.dimensions / 2))
    sigmas = np.diagflat(np.sqrt(sigmas))
    self._left_embedding = np.dot(U, sigmas)
    self._right_embedding = np.dot(Vt.T, sigmas)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants