Skip to contents

Formula: biased random walks + skip-gram

Usage

Comemb(
  G,
  p = 1,
  q = 1,
  dim = 8,
  walk_len = 10,
  n_walks = 4,
  window = 3,
  epochs = 1,
  lr = 0.05,
  neg = 2,
  seed = 42
)

Arguments

G

An n x n adjacency matrix.

p

Return parameter, strictly positive.

q

In-out parameter, strictly positive.

dim

Embedding dimension.

walk_len, n_walks, window, epochs, lr, neg

As in Deepw.

seed

Seed of the deterministic stream.

Value

List with estimate, embedding, walks, degree, n, dim, p, q, method.

Details

The second-order walk interpolates between breadth-first and depth-first exploration: the return parameter p penalises stepping straight back, the in-out parameter q penalises leaving the neighbourhood of the previous node. At p = q = 1 all weights are equal and the walk degenerates to DeepWalk.

References

Grover & Leskovec (2016), node2vec, KDD 2016:855-864.

Examples

G <- matrix(c(0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0), 4, 4, byrow = TRUE)
Comemb(G, dim = 4, walk_len = 5, n_walks = 2)
#> $estimate
#> [1] 0.003179637
#> 
#> $embedding
#>             [,1]        [,2]        [,3]        [,4]
#> [1,]  0.03001782  0.06103993  0.03431656 -0.04528434
#> [2,] -0.12270361 -0.07729287  0.06482800 -0.12935236
#> [3,]  0.01029798 -0.09519040 -0.06580563  0.05562667
#> [4,]  0.03453990 -0.06140595 -0.10860119 -0.10971831
#> 
#> $walks
#> $walks[[1]]
#> [1] 1 4 1 2 1
#> 
#> $walks[[2]]
#> [1] 2 1 4 1 4
#> 
#> $walks[[3]]
#> [1] 3 2 3 2 1
#> 
#> $walks[[4]]
#> [1] 4 3 4 3 2
#> 
#> $walks[[5]]
#> [1] 1 2 1 2 3
#> 
#> $walks[[6]]
#> [1] 2 3 2 3 4
#> 
#> $walks[[7]]
#> [1] 3 2 1 4 3
#> 
#> $walks[[8]]
#> [1] 4 3 4 3 4
#> 
#> 
#> $degree
#> [1] 2 2 2 2
#> 
#> $n
#> [1] 4
#> 
#> $dim
#> [1] 4
#> 
#> $p
#> [1] 1
#> 
#> $q
#> [1] 1
#> 
#> $method
#> [1] "node2vec biased-walk embeddings"
#> 
#> attr(,"class")
#> [1] "morie_rich_result" "list"