Skip to contents

Methods to use graphMatch objects as operators on igraph and matrix-like objects.

Usage

# S4 method for graphMatch,ANY
%*%(x, y)

# S4 method for ANY,graphMatch
%*%(x, y)

# S4 method for graphMatch,Matrix
%*%(x, y)

# S4 method for Matrix,graphMatch
%*%(x, y)

# S4 method for graphMatch,igraph
%*%(x, y)

# S4 method for igraph,graphMatch
%*%(x, y)

Arguments

x

Either graphMatch object or a matrix-like object

y

Either graphMatch object or a matrix-like object

Value

These methods return an object of the same type as the non-graphMatch object. If m is the match of g1 to g2 (both igraph objects), then m

permuted so as to match with g1. Conversely, g1

returns g1 permuted so as to match with g2.

Examples


set.seed(123)
cgnp_pair <- sample_correlated_gnp_pair(n = 10, corr =  0.3, p =  0.5)
g1 <- cgnp_pair$graph1
g2 <- cgnp_pair$graph2

# match g1 & g2 using FW methodology with indefinite relaxation
match <- gm(A = g1, B = g2, seeds = 1:3, method = 'indefinite')

# permute the second graph according to the match result: P %*% g2 %*% P^T
match %*% g2 # return an igraph object
#> IGRAPH 0fa4349 UN-- 10 19 -- Erdos-Renyi (gnp) graph
#> + attr: name_1 (g/c), name_2 (g/c), type_1 (g/c), type_2 (g/c), loops_1
#> | (g/l), loops_2 (g/l), p_1 (g/n), p_2 (g/n), name (g/c), type (g/c),
#> | loops (g/l), p (g/n), name (v/n)
#> + edges from 0fa4349 (vertex names):
#>  [1] 8--10 5-- 6 4--10 9-- 4 4-- 7 5-- 4 3--10 3-- 9 3-- 7 3-- 6 3-- 5 3-- 4
#> [13] 2-- 9 2-- 7 2-- 5 2-- 4 1-- 8 1-- 5 1-- 3
# equivalent to the matrix operation
match[] %*% g2[] %*% t(match[])
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                          
#>  [1,] . . 1 . 1 1 . . . .
#>  [2,] . . . . 1 . . 1 1 1
#>  [3,] 1 . . 1 1 . 1 1 1 1
#>  [4,] . . 1 . 1 . . . . .
#>  [5,] 1 1 1 1 . . . . 1 .
#>  [6,] 1 . . . . . 1 . . .
#>  [7,] . . 1 . . 1 . . 1 .
#>  [8,] . 1 1 . . . . . 1 .
#>  [9,] . 1 1 . 1 . 1 1 . 1
#> [10,] . 1 1 . . . . . 1 .

match %*% g2[] # return a matrix
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                          
#>  [1,] . . 1 . 1 1 . . . .
#>  [2,] . . . . 1 . . 1 1 1
#>  [3,] 1 . . 1 1 . 1 1 1 1
#>  [4,] . . 1 . 1 . . . . .
#>  [5,] 1 1 1 1 . . . . 1 .
#>  [6,] 1 . . . . . 1 . . .
#>  [7,] . . 1 . . 1 . . 1 .
#>  [8,] . 1 1 . . . . . 1 .
#>  [9,] . 1 1 . 1 . 1 1 . 1
#> [10,] . 1 1 . . . . . 1 .
# equivalent to:
P <- match[]
P %*% g2[] %*% Matrix::t(P)
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                          
#>  [1,] . . 1 . 1 1 . . . .
#>  [2,] . . . . 1 . . 1 1 1
#>  [3,] 1 . . 1 1 . 1 1 1 1
#>  [4,] . . 1 . 1 . . . . .
#>  [5,] 1 1 1 1 . . . . 1 .
#>  [6,] 1 . . . . . 1 . . .
#>  [7,] . . 1 . . 1 . . 1 .
#>  [8,] . 1 1 . . . . . 1 .
#>  [9,] . 1 1 . 1 . 1 1 . 1
#> [10,] . 1 1 . . . . . 1 .

# the inverse operations are performed via right multiplication
all(g1[] %*% match == t(P) %*% g1[] %*% P)
#> [1] TRUE