Skip to contents

The Laplacian of a signed graph.

Usage

laplacian_matrix_signed(g, norm = FALSE, sparse = FALSE)

Arguments

g

igraph object with a sign edge attribute.

norm

Whether to calculate the normalized Laplacian. See definitions below.

sparse

Logical scalar, whether to return the result as a sparse matrix. The Matrix package is required for sparse matrices.

Value

a numeric matrix

Details

See laplacian_matrix of igraph for more details. In the signed case, D is a diagonal matrix containing the absolute values of row sums of the signed adjacency matrix.

Author

David Schoch

Examples

library(igraph)
g <- sample_islands_signed(3, 10, 5 / 10, 1)
laplacian_matrix_signed(g)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,]    6    0   -1   -1    0   -1    0    0   -1    -1     0     0     0
#>  [2,]    0    4    0    0    0   -1   -1   -1    0    -1     0     0     0
#>  [3,]   -1    0    5   -1   -1    0   -1   -1    0     0     0     0     0
#>  [4,]   -1    0   -1    6   -1   -1    0    0   -1    -1     0     0     0
#>  [5,]    0    0   -1   -1    4    0   -1    0    0    -1     0     0     0
#>  [6,]   -1   -1    0   -1    0    5    0    0   -1    -1     0     0     0
#>  [7,]    0   -1   -1    0   -1    0    4   -1    0     0     0     0     0
#>  [8,]    0   -1   -1    0    0    0   -1    4   -1     0     0     0     0
#>  [9,]   -1    0    0   -1    0   -1    0   -1    6    -1     0     0     0
#> [10,]   -1   -1    0   -1   -1   -1    0    0   -1     6     0     0     0
#> [11,]    0    0    0    0    0    0    0    0    0     0     3     0    -1
#> [12,]    0    0    0    0    0    0    0    0    0     0     0     5     0
#> [13,]    0    0    0    0    0    0    0    0    0     0    -1     0     4
#> [14,]    0    0    0    0    0    0    0    0    0     0    -1     0     0
#> [15,]    0    0    0    0    0    0    0    0    0     0     0    -1    -1
#> [16,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [17,]    0    0    0    0    0    0    0    0    0     0     0    -1    -1
#> [18,]    1    0    0    0    0    0    0    0    0     0     0    -1    -1
#> [19,]    0    0    0    0    0    0    0    0    0     0     0    -1     0
#> [20,]    0    0    0    0    0    0    0    0    1     0    -1    -1     0
#> [21,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [22,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [23,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [24,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [25,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [26,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [27,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [28,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [29,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [30,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
#>  [1,]     0     0     0     0     1     0     0     0     0     0     0     0
#>  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [6,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [8,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [9,]     0     0     0     0     0     0     1     0     0     0     0     0
#> [10,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [11,]    -1     0     0     0     0     0    -1     0     0     0     0     0
#> [12,]     0    -1     0    -1    -1    -1    -1     0     0     0     0     0
#> [13,]     0    -1     0    -1    -1     0     0     0     0     0     0     0
#> [14,]     6    -1    -1     0    -1    -1    -1     0     0     0     0     0
#> [15,]    -1     5    -1     0     0    -1     0     0     0     0     0     0
#> [16,]    -1    -1     6     0    -1    -1    -1     0     0     0     0     0
#> [17,]     0     0     0     5    -1    -1    -1     0     0     0     0     0
#> [18,]    -1     0    -1    -1     8    -1    -1     0     0     0     0     0
#> [19,]    -1    -1    -1    -1    -1     7    -1     0     0     0     0     0
#> [20,]    -1     0    -1    -1    -1    -1     8     0     0     0     0     0
#> [21,]     0     0     0     0     0     0     0     3     0     0     0    -1
#> [22,]     0     0     0     0     0     0     0     0     4     0    -1    -1
#> [23,]     0     0     0     0     0     0     0     0     0     1     0    -1
#> [24,]     0     0     0     0     0     0     0     0    -1     0     3     0
#> [25,]     0     0     0     0     0     0     0    -1    -1    -1     0     6
#> [26,]     0     0     1     0     0     0     0    -1     0     0     0    -1
#> [27,]     0     0     0     0     0     0     0    -1    -1     0     0    -1
#> [28,]     0     0     0     0     0     0     0     0     0     0    -1     0
#> [29,]     0     0     0     0     0     0     0     0     0     0    -1     0
#> [30,]     0     0     0     0     0     0     0     0    -1     0     0    -1
#>       [,26] [,27] [,28] [,29] [,30]
#>  [1,]     0     0     0     0     0
#>  [2,]     0     0     0     0     0
#>  [3,]     0     0     0     0     0
#>  [4,]     0     0     0     0     0
#>  [5,]     0     0     0     0     0
#>  [6,]     0     0     0     0     0
#>  [7,]     0     0     0     0     0
#>  [8,]     0     0     0     0     0
#>  [9,]     0     0     0     0     0
#> [10,]     0     0     0     0     0
#> [11,]     0     0     0     0     0
#> [12,]     0     0     0     0     0
#> [13,]     0     0     0     0     0
#> [14,]     0     0     0     0     0
#> [15,]     0     0     0     0     0
#> [16,]     1     0     0     0     0
#> [17,]     0     0     0     0     0
#> [18,]     0     0     0     0     0
#> [19,]     0     0     0     0     0
#> [20,]     0     0     0     0     0
#> [21,]    -1    -1     0     0     0
#> [22,]     0    -1     0     0    -1
#> [23,]     0     0     0     0     0
#> [24,]     0     0    -1    -1     0
#> [25,]    -1    -1     0     0    -1
#> [26,]     3     0     0     0     0
#> [27,]     0     5     0    -1    -1
#> [28,]     0     0     2    -1     0
#> [29,]     0    -1    -1     3     0
#> [30,]     0    -1     0     0     3
laplacian_matrix_signed(g, norm = TRUE)
#>             [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#>  [1,]  1.0000000  0.0000000 -0.1825742 -0.1666667  0.0000000 -0.1825742
#>  [2,]  0.0000000  1.0000000  0.0000000  0.0000000  0.0000000 -0.2236068
#>  [3,] -0.1825742  0.0000000  1.0000000 -0.1825742 -0.2236068  0.0000000
#>  [4,] -0.1666667  0.0000000 -0.1825742  1.0000000 -0.2041241 -0.1825742
#>  [5,]  0.0000000  0.0000000 -0.2236068 -0.2041241  1.0000000  0.0000000
#>  [6,] -0.1825742 -0.2236068  0.0000000 -0.1825742  0.0000000  1.0000000
#>  [7,]  0.0000000 -0.2500000 -0.2236068  0.0000000 -0.2500000  0.0000000
#>  [8,]  0.0000000 -0.2500000 -0.2236068  0.0000000  0.0000000  0.0000000
#>  [9,] -0.1666667  0.0000000  0.0000000 -0.1666667  0.0000000 -0.1825742
#> [10,] -0.1666667 -0.2041241  0.0000000 -0.1666667 -0.2041241 -0.1825742
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [13,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [14,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [15,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [16,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [17,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [18,]  0.1443376  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [19,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [20,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [21,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [22,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [23,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [24,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [25,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [26,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [27,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [28,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [29,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [30,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>             [,7]       [,8]       [,9]      [,10]      [,11]      [,12]
#>  [1,]  0.0000000  0.0000000 -0.1666667 -0.1666667  0.0000000  0.0000000
#>  [2,] -0.2500000 -0.2500000  0.0000000 -0.2041241  0.0000000  0.0000000
#>  [3,] -0.2236068 -0.2236068  0.0000000  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000 -0.1666667 -0.1666667  0.0000000  0.0000000
#>  [5,] -0.2500000  0.0000000  0.0000000 -0.2041241  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000 -0.1825742 -0.1825742  0.0000000  0.0000000
#>  [7,]  1.0000000 -0.2500000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [8,] -0.2500000  1.0000000 -0.2041241  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000 -0.2041241  1.0000000 -0.1666667  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000 -0.1666667  1.0000000  0.0000000  0.0000000
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  1.0000000  0.0000000
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  1.0000000
#> [13,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.2886751  0.0000000
#> [14,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.2357023  0.0000000
#> [15,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.2000000
#> [16,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [17,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.2000000
#> [18,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.1581139
#> [19,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.1690309
#> [20,]  0.0000000  0.0000000  0.1443376  0.0000000 -0.2041241 -0.1581139
#> [21,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [22,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [23,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [24,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [25,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [26,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [27,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [28,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [29,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [30,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>            [,13]      [,14]      [,15]      [,16]      [,17]      [,18]
#>  [1,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.1443376
#>  [2,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [3,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [7,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [8,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [11,] -0.2886751 -0.2357023  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,]  0.0000000  0.0000000 -0.2000000  0.0000000 -0.2000000 -0.1581139
#> [13,]  1.0000000  0.0000000 -0.2236068  0.0000000 -0.2236068 -0.1767767
#> [14,]  0.0000000  1.0000000 -0.1825742 -0.1666667  0.0000000 -0.1443376
#> [15,] -0.2236068 -0.1825742  1.0000000 -0.1825742  0.0000000  0.0000000
#> [16,]  0.0000000 -0.1666667 -0.1825742  1.0000000  0.0000000 -0.1443376
#> [17,] -0.2236068  0.0000000  0.0000000  0.0000000  1.0000000 -0.1581139
#> [18,] -0.1767767 -0.1443376  0.0000000 -0.1443376 -0.1581139  1.0000000
#> [19,]  0.0000000 -0.1543033 -0.1690309 -0.1543033 -0.1690309 -0.1336306
#> [20,]  0.0000000 -0.1443376  0.0000000 -0.1443376 -0.1581139 -0.1250000
#> [21,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [22,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [23,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [24,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [25,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [26,]  0.0000000  0.0000000  0.0000000  0.2357023  0.0000000  0.0000000
#> [27,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [28,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [29,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [30,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>            [,19]      [,20]      [,21]      [,22]      [,23]      [,24]
#>  [1,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [2,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [3,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [7,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [8,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.1443376  0.0000000  0.0000000  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [11,]  0.0000000 -0.2041241  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,] -0.1690309 -0.1581139  0.0000000  0.0000000  0.0000000  0.0000000
#> [13,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [14,] -0.1543033 -0.1443376  0.0000000  0.0000000  0.0000000  0.0000000
#> [15,] -0.1690309  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [16,] -0.1543033 -0.1443376  0.0000000  0.0000000  0.0000000  0.0000000
#> [17,] -0.1690309 -0.1581139  0.0000000  0.0000000  0.0000000  0.0000000
#> [18,] -0.1336306 -0.1250000  0.0000000  0.0000000  0.0000000  0.0000000
#> [19,]  1.0000000 -0.1336306  0.0000000  0.0000000  0.0000000  0.0000000
#> [20,] -0.1336306  1.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [21,]  0.0000000  0.0000000  1.0000000  0.0000000  0.0000000  0.0000000
#> [22,]  0.0000000  0.0000000  0.0000000  1.0000000  0.0000000 -0.2886751
#> [23,]  0.0000000  0.0000000  0.0000000  0.0000000  1.0000000  0.0000000
#> [24,]  0.0000000  0.0000000  0.0000000 -0.2886751  0.0000000  1.0000000
#> [25,]  0.0000000  0.0000000 -0.2357023 -0.2041241 -0.4082483  0.0000000
#> [26,]  0.0000000  0.0000000 -0.3333333  0.0000000  0.0000000  0.0000000
#> [27,]  0.0000000  0.0000000 -0.2581989 -0.2236068  0.0000000  0.0000000
#> [28,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.4082483
#> [29,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.3333333
#> [30,]  0.0000000  0.0000000  0.0000000 -0.2886751  0.0000000  0.0000000
#>            [,25]      [,26]      [,27]      [,28]      [,29]      [,30]
#>  [1,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [2,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [3,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [7,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [8,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [13,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [14,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [15,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [16,]  0.0000000  0.2357023  0.0000000  0.0000000  0.0000000  0.0000000
#> [17,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [18,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [19,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [20,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [21,] -0.2357023 -0.3333333 -0.2581989  0.0000000  0.0000000  0.0000000
#> [22,] -0.2041241  0.0000000 -0.2236068  0.0000000  0.0000000 -0.2886751
#> [23,] -0.4082483  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [24,]  0.0000000  0.0000000  0.0000000 -0.4082483 -0.3333333  0.0000000
#> [25,]  1.0000000 -0.2357023 -0.1825742  0.0000000  0.0000000 -0.2357023
#> [26,] -0.2357023  1.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [27,] -0.1825742  0.0000000  1.0000000  0.0000000 -0.2581989 -0.2581989
#> [28,]  0.0000000  0.0000000  0.0000000  1.0000000 -0.4082483  0.0000000
#> [29,]  0.0000000  0.0000000 -0.2581989 -0.4082483  1.0000000  0.0000000
#> [30,] -0.2357023  0.0000000 -0.2581989  0.0000000  0.0000000  1.0000000