-
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.
Merge pull request #250 from bockthom/thomas-updates
Enable simplification of multi-relation edges & make multi-network construction work with igraph version 2.0.1.1 Reviewed-by: Christian Hechtl <[email protected]>
- Loading branch information
Showing
6 changed files
with
42 additions
and
18 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 2023 by Maximilian Löffler <[email protected]> | ||
## Copyright 2024 by Thomas Bock <[email protected]> | ||
## All Rights Reserved. | ||
|
||
name: Build Status | ||
|
@@ -29,17 +30,17 @@ permissions: | |
jobs: | ||
build: | ||
name: Build | ||
|
||
# change to 'runs-on: self-hosted' to run on self-hosted runners (https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job) | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
r-version: ['3.6', '4.0', '4.1', '4.2', 'latest'] | ||
r-version: ['3.6', '4.0', '4.1', '4.2', '4.3', 'latest'] | ||
|
||
steps: | ||
- name: Checkout Repo | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Update system | ||
|
@@ -56,7 +57,7 @@ jobs: | |
uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: ${{ matrix.r-version }} | ||
|
||
- name: Install dependencies | ||
run: Rscript install.R | ||
|
||
|
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
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
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
## Copyright 2020-2021 by Christian Hechtl <[email protected]> | ||
## Copyright 2017 by Felix Prasse <[email protected]> | ||
## Copyright 2017-2019 by Thomas Bock <[email protected]> | ||
## Copyright 2021, 2023 by Thomas Bock <[email protected]> | ||
## Copyright 2021, 2023-2024 by Thomas Bock <[email protected]> | ||
## Copyright 2018 by Barbara Eckl <[email protected]> | ||
## Copyright 2018-2019 by Jakob Kronawitter <[email protected]> | ||
## Copyright 2019 by Anselm Fehnker <[email protected]> | ||
|
@@ -863,6 +863,12 @@ NetworkConf = R6::R6Class("NetworkConf", inherit = Conf, | |
allowed = c(TRUE, FALSE), | ||
allowed.number = 1 | ||
), | ||
simplify.multiple.relations = list( | ||
default = FALSE, | ||
type = "logical", | ||
allowed = c(TRUE, FALSE), | ||
allowed.number = 1 | ||
), | ||
skip.threshold = list( | ||
default = Inf, | ||
type = "numeric", | ||
|
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,7 +12,7 @@ | |
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
## | ||
## Copyright 2015, 2019 by Thomas Bock <[email protected]> | ||
## Copyright 2021, 2023 by Thomas Bock <[email protected]> | ||
## Copyright 2021, 2023-2024 by Thomas Bock <[email protected]> | ||
## Copyright 2017 by Raphael Nömmer <[email protected]> | ||
## Copyright 2017-2019 by Claus Hunsen <[email protected]> | ||
## Copyright 2017-2018 by Christian Hechtl <[email protected]> | ||
|
@@ -167,7 +167,7 @@ metrics.smallworldness = function(network) { | |
if (!is.simple(network)) { | ||
## if this is not the case, raise an error and stop the execution | ||
error.message = "The input network has too many edges. Try again with a simplified network." | ||
logging::error(error.message) | ||
logging::logerror(error.message) | ||
stop(error.message) | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
## Copyright 2017 by Raphael Nömmer <[email protected]> | ||
## Copyright 2017-2018 by Christian Hechtl <[email protected]> | ||
## Copyright 2017-2019 by Thomas Bock <[email protected]> | ||
## Copyright 2021, 2023 by Thomas Bock <[email protected]> | ||
## Copyright 2021, 2023-2024 by Thomas Bock <[email protected]> | ||
## Copyright 2018 by Barbara Eckl <[email protected]> | ||
## Copyright 2018-2019 by Jakob Kronawitter <[email protected]> | ||
## Copyright 2020 by Anselm Fehnker <[email protected]> | ||
|
@@ -958,8 +958,10 @@ NetworkBuilder = R6::R6Class("NetworkBuilder", | |
## to be consistent with bipartite networks | ||
artifacts.to.add.kind[artifacts.to.add.kind == "IssueEvent"] = "Issue" | ||
|
||
artifacts.net = artifacts.net + igraph::vertices(artifacts.to.add, type = TYPE.ARTIFACT, | ||
kind = artifacts.to.add.kind) | ||
if (length(artifacts.to.add) > 0) { | ||
artifacts.net = artifacts.net + igraph::vertices(artifacts.to.add, type = TYPE.ARTIFACT, | ||
kind = artifacts.to.add.kind) | ||
} | ||
|
||
## check directedness and adapt artifact network if needed | ||
if (igraph::is.directed(authors.net) && !igraph::is.directed(artifacts.net)) { | ||
|
@@ -1260,7 +1262,8 @@ construct.network.from.edge.list = function(vertices, edge.list, network.conf, d | |
|
||
## transform multiple edges to edge weights | ||
if (network.conf$get.value("simplify")) { | ||
net = simplify.network(net) | ||
net = simplify.network(net, | ||
simplify.multiple.relations = network.conf$get.value("simplify.multiple.relations")) | ||
} | ||
|
||
logging::logdebug("construct.network.from.edge.list: finished.") | ||
|
@@ -1536,16 +1539,19 @@ add.attributes.to.network = function(network, type = c("vertex", "edge"), attrib | |
#' @param network the given network | ||
#' @param remove.multiple whether to contract multiple edges between the same pair of vertices [default: TRUE] | ||
#' @param remove.loops whether to remove loops [default: TRUE] | ||
#' @param simplify.multiple.relations whether to combine edges of multiple relations into | ||
#' one simplified edge [default: FALSE] | ||
#' | ||
#' @return the simplified network | ||
simplify.network = function(network, remove.multiple = TRUE, remove.loops = TRUE) { | ||
simplify.network = function(network, remove.multiple = TRUE, remove.loops = TRUE, | ||
simplify.multiple.relations = FALSE) { | ||
logging::logdebug("simplify.network: starting.") | ||
logging::loginfo("Simplifying network.") | ||
|
||
## save network attributes, otherwise they get lost | ||
network.attributes = igraph::get.graph.attribute(network) | ||
|
||
if (length(unique(igraph::get.edge.attribute(network, "relation"))) > 1) { | ||
if (!simplify.multiple.relations && length(unique(igraph::get.edge.attribute(network, "relation"))) > 1) { | ||
## data frame of the network | ||
edge.data = igraph::as_data_frame(network, what = "edges") | ||
vertex.data = igraph::as_data_frame(network, what = "vertices") | ||
|
@@ -1587,17 +1593,20 @@ simplify.network = function(network, remove.multiple = TRUE, remove.loops = TRUE | |
#' @param networks the list of networks | ||
#' @param remove.multiple whether to contract multiple edges between the same pair of vertices [default: TRUE] | ||
#' @param remove.loops whether to remove loops [default: TRUE] | ||
#' @param simplify.multiple.relations whether to combine edges of multiple relations into | ||
#' one simplified edge [default: FALSE] | ||
#' | ||
#' @return the simplified networks | ||
simplify.networks = function(networks, remove.multiple = TRUE, remove.loops = TRUE) { | ||
simplify.networks = function(networks, remove.multiple = TRUE, remove.loops = TRUE, | ||
simplify.multiple.relations = FALSE) { | ||
logging::logdebug("simplify.networks: starting.") | ||
logging::loginfo( | ||
"Simplifying networks (names = [%s]).", | ||
paste(names(networks), collapse = ", ") | ||
) | ||
|
||
nets = parallel::mclapply(networks, simplify.network, remove.multiple = remove.multiple, | ||
remove.loops = remove.loops) | ||
remove.loops = remove.loops, simplify.multiple.relations = simplify.multiple.relations) | ||
|
||
logging::logdebug("simplify.networks: finished.") | ||
return(nets) | ||
|