-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the behavior of
get.expanded.adjacency.matrices
In commit e72eff8, the function `get.expanded.adjacency.matrices` has been refactored. Unfortunately, the author names have only be extracted from each network individually instead of globally over all networks. This way, the functionality of the function has been changed inadvertently. With this commit, we follow-up on this and restore the previous behavior. As `get.author.names.from.networks(networks)` now always returns a list, accessing the first element is necessary (although this was not necessary in previous implementations). Moreover, this commit also fixes a wrong test with respect to get.expanded.adjacency.matrices`. Signed-off-by: Thomas Bock <[email protected]>
- Loading branch information
Showing
2 changed files
with
25 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
## | ||
## Copyright 2024 by Leo Sendelbach <[email protected]> | ||
## Copyright 2024 by Thomas Bock <[email protected]> | ||
## All Rights Reserved. | ||
|
||
|
||
|
@@ -576,19 +577,6 @@ test_that("getting a sparse adjacency matrix per network, two networks", { | |
to = c("Dieter", "Klaus", "Heinz") | ||
) | ||
network.in.one = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices) | ||
authors.in.one = sort(c("Heinz", "Dieter", "Klaus")) | ||
|
||
matrix.out.one = Matrix::sparseMatrix(i = c(), j = c(), x = 0, dims = c(length(authors.in.one), | ||
length(authors.in.one)), repr = "T") | ||
rownames(matrix.out.one) = authors.in.one | ||
colnames(matrix.out.one) = authors.in.one | ||
|
||
# order these statements so that the second arguments are ordered alphabetically | ||
# or use the helper function as used below | ||
matrix.out.one["Heinz", "Dieter"] = 1 | ||
matrix.out.one["Klaus", "Dieter"] = 1 | ||
matrix.out.one["Dieter", "Heinz"] = 1 | ||
matrix.out.one["Dieter", "Klaus"] = 1 | ||
|
||
vertices = data.frame( | ||
name = c("Klaus", "Tobias"), | ||
|
@@ -600,14 +588,27 @@ test_that("getting a sparse adjacency matrix per network, two networks", { | |
to = c("Tobias") | ||
) | ||
network.in.two = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices) | ||
authors.in.two = sort(c("Klaus", "Tobias")) | ||
|
||
matrix.out.two = Matrix::sparseMatrix(i = c(), j = c(), x = 0, dims = c(length(authors.in.two), | ||
length(authors.in.two)), repr = "T") | ||
rownames(matrix.out.two) = authors.in.two | ||
colnames(matrix.out.two) = authors.in.two | ||
all.authors = sort(c("Heinz", "Dieter", "Klaus", "Tobias")) | ||
|
||
matrix.out.one = Matrix::sparseMatrix(i = c(), j = c(), x = 0, dims = c(length(all.authors), | ||
length(all.authors)), repr = "T") | ||
rownames(matrix.out.one) = all.authors | ||
colnames(matrix.out.one) = all.authors | ||
|
||
# order these statements so that the second arguments are ordered alphabetically | ||
# order these statements so that the second arguments are ordered alphabetically | ||
# or use the helper function as used below | ||
matrix.out.one["Heinz", "Dieter"] = 1 | ||
matrix.out.one["Klaus", "Dieter"] = 1 | ||
matrix.out.one["Dieter", "Heinz"] = 1 | ||
matrix.out.one["Dieter", "Klaus"] = 1 | ||
|
||
matrix.out.two = Matrix::sparseMatrix(i = c(), j = c(), x = 0, dims = c(length(all.authors), | ||
length(all.authors)), repr = "T") | ||
rownames(matrix.out.two) = all.authors | ||
colnames(matrix.out.two) = all.authors | ||
|
||
# order these statements so that the second arguments are ordered alphabetically | ||
# or use the helper function as used below | ||
matrix.out.two["Tobias", "Klaus"] = 1 | ||
matrix.out.two["Klaus", "Tobias"] = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
## Copyright 2016-2017 by Sofie Kemper <[email protected]> | ||
## Copyright 2016-2017 by Claus Hunsen <[email protected]> | ||
## Copyright 2016-2018 by Thomas Bock <[email protected]> | ||
## Copyright 2020, 2023 by Thomas Bock <[email protected]> | ||
## Copyright 2020, 2023-2024 by Thomas Bock <[email protected]> | ||
## Copyright 2017 by Angelika Schmid <[email protected]> | ||
## Copyright 2019 by Jakob Kronawitter <[email protected]> | ||
## Copyright 2019-2020 by Anselm Fehnker <[email protected]> | ||
|
@@ -169,7 +169,7 @@ get.expanded.adjacency = function(network, authors, weighted = FALSE) { | |
} | ||
|
||
#' Calculates a sparse adjacency matrix for each network in the list. | ||
#' All adjacency matrices are expanded in such a way that the use the same set | ||
#' All adjacency matrices are expanded in such a way that they use the same set | ||
#' of authors derived from all networks in the list. | ||
#' | ||
#' @param networks list of networks | ||
|
@@ -178,10 +178,9 @@ get.expanded.adjacency = function(network, authors, weighted = FALSE) { | |
#' @return the list of adjacency matrices | ||
get.expanded.adjacency.matrices = function(networks, weighted = FALSE){ | ||
|
||
adjacency.matrices = parallel::mclapply(networks, function(network) { | ||
active.authors = sort(igraph::V(network)$name) | ||
return(get.expanded.adjacency(network = network, authors = active.authors, weighted = weighted)) | ||
}) | ||
authors = get.author.names.from.networks(networks)[[1]] | ||
|
||
adjacency.matrices = parallel::mclapply(networks, get.expanded.adjacency, authors, weighted) | ||
|
||
return(adjacency.matrices) | ||
} | ||
|