metapath2vec icon indicating copy to clipboard operation
metapath2vec copied to clipboard

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

Open skx300 opened this issue 6 years ago • 3 comments

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

skx300 avatar Apr 03 '18 03:04 skx300

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

  • A is the (number of nodes) x (number of nodes) matrix.
  • T is the (number of nodes) x (number of node types) matrix.

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?

apple2373 avatar Apr 03 '18 03:04 apple2373

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.

skx300 avatar Apr 03 '18 06:04 skx300

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

On Tue, Apr 3, 2018, 02:53 skx300 [email protected] 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 .

apple2373 avatar Apr 03 '18 19:04 apple2373