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

[Issue 1242]complete implementation of struc2vec(local ver.) Zihan Li #1243

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
157 changes: 157 additions & 0 deletions data/bc/mirrored_karate_club_network.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 10
0 11
0 12
0 13
0 17
0 19
0 21
0 31
0 34
1 2
1 3
1 7
1 13
1 17
1 19
1 21
1 30
2 3
2 7
2 8
2 9
2 13
2 27
2 28
2 32
3 7
3 12
3 13
4 6
4 10
5 6
5 10
5 16
6 16
8 30
8 32
8 33
9 33
13 33
14 32
14 33
15 32
15 33
18 32
18 33
19 33
20 32
20 33
22 32
22 33
23 25
23 27
23 29
23 32
23 33
24 25
24 27
24 31
25 31
26 29
26 33
27 33
28 31
28 33
29 32
29 33
30 32
30 33
31 32
31 33
32 33
34 35
34 36
34 37
34 38
34 39
34 40
34 41
34 42
34 44
34 45
34 46
34 47
34 51
34 53
34 55
34 65
35 36
35 37
35 41
35 47
35 51
35 53
35 55
35 64
36 37
36 41
36 42
36 43
36 47
36 61
36 62
36 66
37 41
37 46
37 47
38 40
38 44
39 40
39 44
39 50
40 50
42 64
42 66
42 67
43 67
47 67
48 66
48 67
49 66
49 67
52 66
52 67
53 67
54 66
54 67
56 66
56 67
57 59
57 61
57 63
57 66
57 67
58 59
58 61
58 65
59 65
60 63
60 67
61 67
62 65
62 67
63 66
63 67
64 66
64 67
65 66
65 67
66 67
Empty file added data/output/output1/_SUCCESS
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
20 32 31 24 25 24 27 24 25 31
13 2 32 2 0 12 0 5 16 6
19 1 21 1 2 9 33 8 2 8
21 1 19 0 17 1 3 1 2 8
4 10 0 8 0 13 0 5 16 5
15 32 31 32 14 33 8 32 2 1
16 5 6 4 10 4 0 5 16 6
22 33 22 32 14 33 18 32 15 33
28 2 28 33 8 2 1 19 33 28
29 33 31 24 25 24 27 24 25 31
25 24 27 2 28 31 33 26 29 33
11 0 17 0 2 27 33 13 2 13
30 32 30 32 29 26 29 26 29 33
32 15 33 27 2 27 33 26 29 33
27 23 33 23 27 24 27 33 15 33
0 4 0 31 25 24 27 2 8 32
24 31 28 31 25 31 28 31 25 24
14 33 23 25 23 27 24 25 31 24
33 9 2 7 1 0 13 3 13 1
23 27 24 31 25 31 28 31 25 31
1 17 0 21 1 30 32 2 28 31
6 0 11 0 8 33 8 30 32 31
17 0 13 3 1 30 32 15 33 32
3 13 3 12 3 1 3 12 0 19
7 0 11 0 10 5 6 16 6 16
12 0 4 6 16 5 6 4 10 0
8 2 9 33 15 33 13 2 28 31
9 33 31 32 23 29 26 33 32 22
18 33 31 32 23 29 23 29 33 32
31 28 2 1 30 8 30 1 3 2
26 33 32 33 9 2 13 0 2 9
10 4 6 16 6 5 0 19 1 0
5 0 7 2 7 0 6 5 16 5
2 0 21 1 0 6 16 6 0 12
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
20 33 20 32 20 32 23 25 23 27
13 0 7 0 11 0 31 24 27 23
19 33 20 33 18 33 19 0 17 0
21 1 21 1 3 13 2 32 23 27
4 10 0 12 0 21 1 7 0 13
15 33 14 32 2 7 2 32 15 32
16 6 16 6 5 0 10 5 0 13
22 33 20 33 18 32 23 25 31 0
28 33 14 32 2 7 2 32 15 32
29 26 33 13 33 28 2 9 2 0
25 23 25 23 32 33 20 32 8 30
11 0 7 0 10 5 16 6 4 0
30 1 21 0 12 3 1 3 0 13
32 23 25 23 32 30 1 3 0 13
27 33 15 33 19 33 20 33 18 33
0 19 33 28 33 9 33 20 32 15
24 27 23 32 20 32 29 23 33 30
14 33 30 32 8 2 27 24 27 2
33 32 22 32 8 2 7 2 8 30
23 27 23 25 24 27 24 31 32 15
1 30 1 3 12 0 8 30 33 20
6 4 0 31 33 23 33 14 33 14
17 1 13 1 13 1 13 33 19 33
3 2 13 33 32 31 25 31 24 27
7 2 13 1 7 2 9 33 30 1
12 0 19 33 14 32 8 30 32 22
8 32 22 32 31 28 33 23 25 24
9 33 8 0 8 32 31 24 31 28
18 32 22 32 31 28 31 24 31 28
31 25 24 27 23 32 31 24 25 24
26 33 32 31 32 2 27 2 27 33
10 4 0 17 1 17 0 12 3 0
5 0 4 0 19 33 26 29 26 29
2 27 24 25 23 29 23 33 26 29
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.tencent.angel.graph.embedding.struc2vec

object DTW {
def compute(a:Array[Int],b:Array[Int]):Double = {

// DTW(Dynamic Time Warping)
// a fundamental implementation based on dynamic programming
// dp[i][j] = Dist(i,j) + min{dp[i-1][j],dp[i][j-1],dp[i-1][j-1]}

if(a.length==0||b.length==0)
Double.NaN
else{
val dp: Array[Array[Double]] = Array.ofDim(a.length, b.length)

// set the boundary condition
// the first column, dp[i][0] = Dist(i,0)+ dp[i-1][0];

dp(0)(0) = dist(a(0),b(0))
for(i <- 1 until a.length)
dp(i)(0) = dp(i-1)(0)+dist(a(i),b(0))

// the first row, dp[0][j] = Dist(0,j)+ dp[0][j-1];

for (j <- 1 until b.length)
dp(0)(j) = dp(0)(j - 1) + dist(b(j), a(0))

// fill up the whole dp matrix from left to right, from top to bottom

for(i<-1 until a.length;j<- 1 until b.length)
dp(i)(j) = dist(a(i),b(j))+minAmongThree(dp(i-1)(j),dp(i)(j-1),dp(i-1)(j-1))

dp(a.length-1)(b.length-1)
}
}

def dist(a:Int,b:Int):Double = {
// Assume that a, b are both positive (the node degrees )
Math.max(a,b)/Math.min(a,b)-1
}

def minAmongThree(a:Double,b:Double,c:Double):Double = {
if(a<b){
Math.min(a,c)
}else
Math.min(b,c)
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tencent.angel.graph.embedding.struc2vec

object Floyd {
val INF = Int.MaxValue
def hopCount(adj:Array[Array[Int]]):Array[Array[Int]] = {
// self implementation of hop-count demo based on Floyd algorithm
// Assume that adj is a square matrix
val len = adj.length
val result: Array[Array[Int]] = Array.ofDim(len, len)
adj.copyToArray(result)
for(k<- 0 until len;i <- 0 until len; j<- 0 until len )
if(!result(i)(k).equals(INF) && !result(k)(j).equals(INF))
result(i)(j) = Math.min(result(i)(j),result(i)(k)+result(k)(j))
result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.tencent.angel.graph.embedding.struc2vec

import com.tencent.angel.graph.embedding.struc2vec.test.TestStructSimi.INF

object MainEnter {

// Test Structure similarity
// By computing the structure similarity of Barbell graph b(1,1)
// Input graph adjacency matrix = [[0,1,INF],[1,0,1],[INF,1,0]]

def main(args:Array[String]): Unit ={
val adjMatrix = Array(Array(0, 1, INF), Array(1, 0, 1), Array(INF, 1, 0))
val structureSimilarity = new StructureSimilarity(adjMatrix)
structureSimilarity.compute()
val result: Array[Array[Array[Double]]] = structureSimilarity.structSimi
println("Layer1: ")
for (i <- 0 to result.length - 1; j <- 0 to result(0).length - 1) {
print((i,j) + " = " + result(0)(i)(j)+" ")
}
println()
println("Layer2: ")
for (i <- 0 to result.length - 1; j <- 0 to result(1).length - 1) {
print( (i, j) + " = " + result(1)(i)(j) + " ")
}
println()
println("Layer3: ")
for (i <- 0 to result.length - 1; j <- 0 to result(2).length - 1) {
print((i, j) + " = " + result(2)(i)(j) + " ")
}
}




}