These methods provide functionality to view, inspect, and convert graphMatch objects.
Usage
# S4 method for graphMatch
as.data.frame(x)
# S4 method for graphMatch
show(object)
# S4 method for graphMatch
print(x)
# S4 method for graphMatch,missing,missing,missing
[(x, i = NULL, j = NULL, drop = NULL)
# S4 method for graphMatch
dim(x)
# S4 method for graphMatch
length(x)
# S4 method for graphMatch
t(x)
# S4 method for graphMatch
rev(x)
# S4 method for graphMatch,ANY,ANY,ANY
[(x, i = NULL, j = NULL, drop = NULL)
# S4 method for graphMatch
str(object)
# S4 method for graphMatch
$(x, name)
Arguments
- x
graphMatch object
- object
graphMatch object
- i
row index for the correspondence data.frame
- j
col index for the correspondence data.frame
- drop
ignored
- name
name of element in the list
Value
dim
returns a vector of length two indicating the number of
vertices in each original graph. length
returns the number of found
vertex-pair matches. m[i,j]
will index the 2 x length data.frame of
vertex-pair matches. This is true for any i,j unless both are missing. In
that case, m[]
returns a sparse matrix of dimension dim(m) where
m[][i,j]
is 0 unless m matches node i with node j. (Note this is not
guaranteed to be a permutation matrix unless dim(m)[1] = dim(m)[2] =
length(m)
.
Examples
# sample a pair of correlated random graphs from G(n,p)
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')
# print graphMatch object
match
#> gm(A = g1, B = g2, seeds = 1:3, method = "indefinite")
#>
#> Match (10 x 10):
#> corr_A corr_B
#> 1 1 1
#> 2 2 2
#> 3 3 3
#> 4 4 6
#> 5 5 5
#> 6 6 8
#> 7 7 10
#> 8 8 7
#> 9 9 4
#> 10 10 9
print(match)
#> gm(A = g1, B = g2, seeds = 1:3, method = "indefinite")
#>
#> Match (10 x 10):
#> corr_A corr_B
#> 1 1 1
#> 2 2 2
#> 3 3 3
#> 4 4 6
#> 5 5 5
#> 6 6 8
#> 7 7 10
#> 8 8 7
#> 9 9 4
#> 10 10 9
show(match)
#> gm(A = g1, B = g2, seeds = 1:3, method = "indefinite")
#>
#> Match (10 x 10):
#> corr_A corr_B
#> 1 1 1
#> 2 2 2
#> 3 3 3
#> 4 4 6
#> 5 5 5
#> 6 6 8
#> 7 7 10
#> 8 8 7
#> 9 9 4
#> 10 10 9
# print matching correspondence
match$corr_A # matching correspondence in the first graph
#> [1] 1 2 3 4 5 6 7 8 9 10
match$corr_B # matching correspondence in the second graph
#> [1] 1 2 3 6 5 8 10 7 4 9
# get nonseed matching correspondence
match[!match$seeds]
#> corr_A corr_B
#> 4 4 6
#> 5 5 5
#> 6 6 8
#> 7 7 10
#> 8 8 7
#> 9 9 4
#> 10 10 9
# create graphMatch object from a vector
as.graphMatch(sample(10))
#> asMethod(from = object)
#>
#> Match (10 x 10):
#> corr_A corr_B
#> 1 1 1
#> 2 2 8
#> 3 3 6
#> 4 4 9
#> 5 5 4
#> 6 6 10
#> 7 7 7
#> 8 8 2
#> 9 9 5
#> 10 10 3
# or data.frame
as.graphMatch(data.frame(a = 1:10, b = sample(1000, 10)))
#> asMethod(from = object)
#>
#> Match (10 x 876):
#> corr_A corr_B
#> 1 1 20
#> 2 2 872
#> 3 3 195
#> 4 4 861
#> 5 5 164
#> 6 6 52
#> 7 7 876
#> 8 8 534
#> 9 9 177
#> 10 10 554
# get corresponding permutation matrix for the match result
match[] # preferred approach
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1 . . . . . . . . .
#> [2,] . 1 . . . . . . . .
#> [3,] . . 1 . . . . . . .
#> [4,] . . . . . 1 . . . .
#> [5,] . . . . 1 . . . . .
#> [6,] . . . . . . . 1 . .
#> [7,] . . . . . . . . . 1
#> [8,] . . . . . . 1 . . .
#> [9,] . . . 1 . . . . . .
#> [10,] . . . . . . . . 1 .
# or equivalently
get_perm_mat(match)
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1 . . . . . . . . .
#> [2,] . 1 . . . . . . . .
#> [3,] . . 1 . . . . . . .
#> [4,] . . . . . 1 . . . .
#> [5,] . . . . 1 . . . . .
#> [6,] . . . . . . . 1 . .
#> [7,] . . . . . . . . . 1
#> [8,] . . . . . . 1 . . .
#> [9,] . . . 1 . . . . . .
#> [10,] . . . . . . . . 1 .
# sizes of two graphs
dim(match)
#> [1] 10 10
# number of matched node pairs
length(match)
#> [1] 10
# reverse the matching correspondence between two graphs
t(match)
#> gm(A = g1, B = g2, seeds = 1:3, method = "indefinite")
#>
#> Match (10 x 10):
#> corr_B corr_A
#> 1 1 1
#> 2 2 2
#> 3 3 3
#> 4 6 4
#> 5 5 5
#> 6 8 6
#> 7 10 7
#> 8 7 8
#> 9 4 9
#> 10 9 10
rev(match)
#> corr_A corr_B
#> 10 10 9
#> 9 9 4
#> 8 8 7
#> 7 7 10
#> 6 6 8
#> 5 5 5
#> 4 4 6
#> 3 3 3
#> 2 2 2
#> 1 1 1