apple2373 / metapath2vec

185 stars 59 forks source link

It seems like no implementation of metapath-based random walks. #2

Open skx300 opened 6 years ago

skx300 commented 6 years ago

It seems like no implementation of metapath-based random walks. Any help for finding it? or is it quit easy to implement it ?

apple2373 commented 6 years ago

I think it is easy to implement or modify existing random walk implementation. An easy (but not most efficient) way is to store node-type matrix whose size is (number of nodes) x (number of node types). It's a binary matrix. Then, every time you need to sample a specific node of a type, you can use a row as a binary mask to the corresponding row of the adjacent matrix.

For example, let A adjacent matrix and let T as type matrix. so

Assume that the random walker is at the node 10, and you need to sample an adjacent node whose type is 4. If you ignore about the node type requirement, you usually do

Sample a non-zero index from the 10th row vector of A (say, A[10,:]).

Right?

Then when you need to limit to type 4, you use 4th row vector of T (say, T[4,:]). Then multiply to A[10,:] in a element wise manner.

Then,

Sample a non zero index from A[10,:]*T[4,:] .

This will automatically meet the type requirements.

Does this make sense?

skx300 commented 6 years ago

Thank you. I understand that. But should sample the A[10, :] * T[:4], right? The T is in shape (number of nodes) x (number of node types). The column of T does the mask, instead of the row.

apple2373 commented 6 years ago

opps, yes you are right. Thank you for catching up the error!

On Tue, Apr 3, 2018, 02:53 skx300 notifications@github.com wrote:

Thank you. I understand that. But should sample the A[10, :] * T[:4], right? The T is in shape (number of nodes) x (number of node types). The column of T does the mask, instead of the row.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apple2373/metapath2vec/issues/2#issuecomment-378147041, or mute the thread https://github.com/notifications/unsubscribe-auth/AH4D42LwbTKgmv9TbdUDX_jWIvIFlxcoks5tkxxngaJpZM4TEYrS .