Skip to content

Commit

Permalink
removed deprecated igraph functions
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics committed Feb 1, 2025
1 parent 5c1fa83 commit ae706ee
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: netrankr
Type: Package
Title: Analyzing Partial Rankings in Networks
Version: 1.2.3
Version: 1.2.3.9000
Authors@R: c(
person("David", "Schoch", email = "david@schochastics.net", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2952-4812")),
Expand Down
20 changes: 10 additions & 10 deletions R/approximate.ranks.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ approx_rank_expected <- function(P, method = "lpom") {
if (length(MSE) >= 1) {
MSE <- t(apply(MSE, 1, sort))
MSE <- MSE[!duplicated(MSE), ]
g <- igraph::graph.empty()
g <- igraph::add.vertices(g, nrow(P))
g <- igraph::add.edges(g, c(t(MSE)))
g <- igraph::as.undirected(g)
MSE <- igraph::clusters(g)$membership
g <- igraph::make_empty_graph()
g <- igraph::add_vertices(g, nrow(P))
g <- igraph::add_edges(g, c(t(MSE)))
g <- igraph::as_undirected(g)
MSE <- igraph::components(g)$membership
equi <- which(duplicated(MSE))
P <- P[-equi, -equi]
} else {
Expand Down Expand Up @@ -168,11 +168,11 @@ approx_rank_relative <- function(P, iterative = TRUE, num.iter = 10) {
if (length(MSE) >= 1) {
MSE <- t(apply(MSE, 1, sort))
MSE <- MSE[!duplicated(MSE), ]
g <- igraph::graph.empty()
g <- igraph::add.vertices(g, nrow(P))
g <- igraph::add.edges(g, c(t(MSE)))
g <- igraph::as.undirected(g)
MSE <- igraph::clusters(g)$membership
g <- igraph::make_empty_graph()
g <- igraph::add_vertices(g, nrow(P))
g <- igraph::add_edges(g, c(t(MSE)))
g <- igraph::as_undirected(g)
MSE <- igraph::components(g)$membership
equi <- which(duplicated(MSE))
P <- P[-equi, -equi]
} else {
Expand Down
4 changes: 2 additions & 2 deletions R/comparable.pairs.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ comparable_pairs <- function(P) {
if (!is.binary(P)) {
stop("P is not a binary matrix")
}
igraph::graph.density(igraph::graph_from_adjacency_matrix(P, "max"))
igraph::edge_density(igraph::graph_from_adjacency_matrix(P, "max"))
}

#' @title Incomparable pairs in a partial order
Expand All @@ -49,5 +49,5 @@ incomparable_pairs <- function(P) {
if (!is.binary(P)) {
stop("P is not a binary matrix")
}
igraph::graph.density(igraph::graph.complementer(igraph::graph_from_adjacency_matrix(P, "max")))
igraph::edge_density(igraph::complementer(igraph::graph_from_adjacency_matrix(P, "max")))
}
12 changes: 6 additions & 6 deletions R/hyperbolic.index.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ hyperbolic_index <- function(g, type = "odd") {
ENW <- rep(0, n)
for (v in 1:n) {
Nv <- igraph::neighborhood(g, 1, v)[[1]]
g1 <- igraph::induced.subgraph(g, Nv)
C <- igraph::get.adjacency(g1, type = "both")
g1 <- igraph::induced_subgraph(g, Nv)
C <- igraph::as_adjacency_matrix(g1, type = "both")
eig.decomp <- eigen(C, symmetric = TRUE)
V <- (eig.decomp$vectors)^2
lambda <- eig.decomp$values
ENW[v] <- sum(V %*% cosh(lambda)) * igraph::graph.density(g1) # cosh(x)
ENW[v] <- sum(V %*% cosh(lambda)) * igraph::edge_density(g1) # cosh(x)
}
} else if (type == "odd") {
ENW <- rep(0, n)
for (v in 1:n) {
Nv <- igraph::neighborhood(g, 1, v)[[1]]
g1 <- igraph::induced.subgraph(g, Nv)
C <- igraph::get.adjacency(g1, type = "both")
g1 <- igraph::induced_subgraph(g, Nv)
C <- igraph::as_adjacency_matrix(g1, type = "both")
eig.decomp <- eigen(C, symmetric = TRUE)
V <- (eig.decomp$vectors)^2
lambda <- eig.decomp$values
ENW[v] <- sum(V %*% sinh(lambda)) * igraph::graph.density(g1) # sinh(x)
ENW[v] <- sum(V %*% sinh(lambda)) * igraph::edge_density(g1) # sinh(x)
}
} else {
stop("type must be even or odd")
Expand Down
36 changes: 18 additions & 18 deletions R/indirect.relations.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,28 +160,28 @@ indirect_relations <- function(g,
} else if (type == "weights") {
if (is.null(igraph::get.edge.attribute(g, "weight"))) {
warning('no weight attribute present. using "adjacency" instead.\n')
rel <- igraph::get.adjacency(g, type = "both", sparse = FALSE, attr = NULL)
rel <- igraph::as_adjacency_matrix(g, type = "both", sparse = FALSE, attr = NULL)
rel <- FUN(rel, ...)
diag(rel) <- 0
} else {
rel <- igraph::get.adjacency(g, type = "both", sparse = FALSE, attr = "weight")
rel <- igraph::as_adjacency_matrix(g, type = "both", sparse = FALSE, attr = "weight")
rel <- FUN(rel, ...)
diag(rel) <- 0
}
} else if (type == "adjacency") {
rel <- igraph::get.adjacency(g, type = "both", sparse = FALSE, attr = NULL)
rel <- igraph::as_adjacency_matrix(g, type = "both", sparse = FALSE, attr = NULL)
rel <- FUN(rel, ...)
diag(rel) <- 0
} else if (type == "depend_sp") {
adj <- lapply(igraph::get.adjlist(g), function(x) x - 1)
adj <- lapply(igraph::as_adj_list(g), function(x) x - 1)
rel <- dependency(adj)
} else if (type == "walks") {
eigen.decomp <- eigen(igraph::get.adjacency(g, type = "both"))
eigen.decomp <- eigen(igraph::as_adjacency_matrix(g, type = "both"))
lambda <- eigen.decomp$values
X <- eigen.decomp$vectors
rel <- X %*% diag(FUN(lambda, ...)) %*% t(X)
} else if (type == "dist_resist") {
L <- igraph::graph.laplacian(g, sparse = FALSE)
L <- igraph::laplacian_matrix(g, sparse = FALSE)
n <- igraph::vcount(g)
A <- L + matrix(1 / n, n, n)
C <- solve(A)
Expand Down Expand Up @@ -246,7 +246,7 @@ log_forest_fct <- function(g, lfparam) {
n <- igraph::vcount(g)
gamma <- log(exp(1) + lfparam^(2 / n))

L <- igraph::graph.laplacian(g, sparse = FALSE)
L <- igraph::laplacian_matrix(g, sparse = FALSE)
I <- diag(1, n)
Q <- solve(I + lfparam * L)

Expand All @@ -266,7 +266,7 @@ depend_netflow_fct <- function(g, netflowmode) {
for (s in 1:n) {
for (t in 1:n) {
if (s != t) {
mflow[s, t] <- igraph::graph.maxflow(g, s, t)$value
mflow[s, t] <- igraph::max_flow(g, s, t)$value
}
}
}
Expand All @@ -278,11 +278,11 @@ depend_netflow_fct <- function(g, netflowmode) {
}
flow_smat <- matrix(0, n, n)
for (i in 1:n) {
g_i <- igraph::delete.vertices(g, i)
g_i <- igraph::delete_vertices(g, i)
for (s in 1:n) {
for (t in 1:n) {
if (i != s & s != t & i != t) {
flow <- igraph::graph.maxflow(g_i, s - (s > i), t - (t > i))$value
flow <- igraph::max_flow(g_i, s - (s > i), t - (t > i))$value
flow_smat[i, s] <- switch(netflowmode,
raw = flow_smat[i, s] + mflow[s, t] - flow,
norm = flow_smat[i, s] + mflow[s, t] - flow,
Expand All @@ -299,7 +299,7 @@ depend_netflow_fct <- function(g, netflowmode) {
}

depend_exp_fct <- function(g) {
A <- igraph::get.adjacency(g, "both", sparse = FALSE)
A <- igraph::as_adjacency_matrix(g, "both", sparse = FALSE)
eigen_A <- eigen(A)
n <- nrow(A)
expA <- eigen_A$vectors %*% diag(exp(eigen_A$values)) %*% t(eigen_A$vectors)
Expand All @@ -326,7 +326,7 @@ depend_rsps_fct <- function(g, rspxparam) {
n <- igraph::vcount(g)
I <- diag(1, n)

A <- igraph::get.adjacency(g, sparse = FALSE)
A <- igraph::as_adjacency_matrix(g, sparse = FALSE)
D <- diag(1 / igraph::degree(g))
P_ref <- D %*% A
C <- 1 / A
Expand All @@ -347,7 +347,7 @@ depend_rspn_fct <- function(g, rspxparam) {
n <- igraph::vcount(g)
I <- diag(1, n)

A <- igraph::get.adjacency(g, sparse = FALSE)
A <- igraph::as_adjacency_matrix(g, sparse = FALSE)
D <- diag(1 / igraph::degree(g))
P_ref <- D %*% A
C <- 1 / A
Expand All @@ -356,7 +356,7 @@ depend_rspn_fct <- function(g, rspxparam) {

Z <- solve((I - W), I)
Zdiv <- 1 / Z
adj <- igraph::get.adjlist(g, "all")
adj <- igraph::as_adj_list(g, "all")
A <- lapply(adj, function(x) as.vector(x) - 1)
bet.mat <- dependRspn(A, Z, Zdiv, W, n)
return(bet.mat)
Expand All @@ -365,13 +365,13 @@ depend_rspn_fct <- function(g, rspxparam) {
depend_curflow_fct <- function(g) {
n <- igraph::vcount(g)
D <- diag(igraph::degree(g))
A <- igraph::get.adjacency(g, sparse = FALSE)
A <- igraph::as_adjacency_matrix(g, sparse = FALSE)
L <- D - A

Tmat <- solve(L[1:(n - 1), 1:(n - 1)])
Tmat <- rbind(cbind(Tmat, 0), 0)

el <- igraph::get.edgelist(g, names = FALSE)
el <- igraph::as_edgelist(g, names = FALSE)
m <- igraph::ecount(g)
el <- el - 1L

Expand All @@ -381,7 +381,7 @@ depend_curflow_fct <- function(g) {

dist_rwalk_fct <- function(g) {
n <- igraph::vcount(g)
A <- igraph::get.adjacency(g, sparse = FALSE)
A <- igraph::as_adjacency_matrix(g, sparse = FALSE)
M <- A / rowSums(A)
e <- rep(1, n - 1)
H <- matrix(0, n, n)
Expand All @@ -395,7 +395,7 @@ dist_rwalk_fct <- function(g) {

dist_walk_fct <- function(g, dwparam) {
n <- igraph::vcount(g)
A <- igraph::get.adjacency(g, sparse = FALSE)
A <- igraph::as_adjacency_matrix(g, sparse = FALSE)
bigeig <- eigen(A, only.values = TRUE)$values[1]
t <- (1 / dwparam + bigeig)^(-1)
# if(dwparam > (1/bigeig)){
Expand Down
2 changes: 1 addition & 1 deletion R/majorization.gap.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#'
#' @examples
#' library(igraph)
#' g <- graph.star(5, "undirected")
#' g <- make_star(5, "undirected")
#' majorization_gap(g) # 0 since star graphs are threshold graphs
#'
#' g <- sample_gnp(100, 0.15)
Expand Down
12 changes: 6 additions & 6 deletions R/mcmc.rank.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ mcmc_rank_prob <- function(P, rp = nrow(P)^3) {
if (length(MSE) >= 1) {
MSE <- t(apply(MSE, 1, sort))
MSE <- MSE[!duplicated(MSE), ]
g <- igraph::graph.empty()
g <- igraph::add.vertices(g, nrow(P))
g <- igraph::add.edges(g, c(t(MSE)))
g <- igraph::as.undirected(g)
MSE <- igraph::clusters(g)$membership
g <- igraph::make_empty_graph()
g <- igraph::add_vertices(g, nrow(P))
g <- igraph::add_edges(g, c(t(MSE)))
g <- igraph::as_undirected(g)
MSE <- igraph::components(g)$membership
equi <- which(duplicated(MSE))
P <- P[-equi, -equi]
} else {
Expand All @@ -61,7 +61,7 @@ mcmc_rank_prob <- function(P, rp = nrow(P)^3) {
stop("all elements are structurally equivalent and have the same rank")
}

init.rank <- as.vector(igraph::topological.sort(igraph::graph_from_adjacency_matrix(P, "directed")))
init.rank <- as.vector(igraph::topo_sort(igraph::graph_from_adjacency_matrix(P, "directed")))
if (inherits(P, "Matrix")) {
res <- mcmc_rank_sparse(P, init.rank - 1, rp)
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/neighborhood.inclusion.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' @examples
#' library(igraph)
#' # the neighborhood inclusion preorder of a star graph is complete
#' g <- graph.star(5, "undirected")
#' g <- make_star(5, "undirected")
#' P <- neighborhood_inclusion(g)
#' comparable_pairs(P)
#'
Expand Down
16 changes: 8 additions & 8 deletions R/rank.analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ exact_rank_prob <- function(P, only.results = TRUE, verbose = FALSE, force = FAL
if (length(MSE) >= 1) {
MSE <- t(apply(MSE, 1, sort))
MSE <- MSE[!duplicated(MSE), ]
g <- igraph::graph.empty()
g <- igraph::add.vertices(g, nrow(P))
g <- igraph::add.edges(g, c(t(MSE)))
g <- igraph::as.undirected(g)
MSE <- igraph::clusters(g)$membership
g <- igraph::make_empty_graph()
g <- igraph::add_vertices(g, nrow(P))
g <- igraph::add_edges(g, c(t(MSE)))
g <- igraph::as_undirected(g)
MSE <- igraph::components(g)$membership
equi <- which(duplicated(MSE))
P <- P[-equi, -equi]
} else {
Expand Down Expand Up @@ -126,13 +126,13 @@ exact_rank_prob <- function(P, only.results = TRUE, verbose = FALSE, force = FAL
stop("Input data too big. Use approximations or set `force=TRUE` if you know what you are doing")
}
# Prepare Data structures---------------------
topo.order <- as.vector(igraph::topological.sort(igraph::graph_from_adjacency_matrix(P, "directed")))
topo.order <- as.vector(igraph::topo_sort(igraph::graph_from_adjacency_matrix(P, "directed")))

P <- P[topo.order, topo.order]
ImPred <- igraph::get.adjlist(igraph::graph_from_adjacency_matrix(P, "directed"), "in")
ImPred <- igraph::as_adj_list(igraph::graph_from_adjacency_matrix(P, "directed"), "in")
ImPred <- lapply(ImPred, function(x) as.vector(x) - 1)

ImSucc <- igraph::get.adjlist(igraph::graph_from_adjacency_matrix(P, "directed"), "out")
ImSucc <- igraph::as_adj_list(igraph::graph_from_adjacency_matrix(P, "directed"), "out")
ImSucc <- lapply(ImSucc, function(x) as.vector(x) - 1)
# TREEOFIDEALS ----------------------------------------------------
if (verbose == TRUE) {
Expand Down
2 changes: 1 addition & 1 deletion R/spectral.gap.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @export
#'
spectral_gap <- function(g, method = "frac") {
spec_decomp <- eigen(igraph::get.adjacency(g, "both"))$values[c(1, 2)]
spec_decomp <- eigen(igraph::as_adjacency_matrix(g, "both"))$values[c(1, 2)]
if (method == "frac") {
return(1 - spec_decomp[2] / spec_decomp[1])
} else if (method == "abs") {
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-hyperbolic.index.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("hyperbolic index works", {
skip_on_cran()
g <- igraph::make_full_graph(2)
expect_true(all(hyperbolic_index(g, "odd") == 0))
expect_true(all(hyperbolic_index(g, "even") != 0))
expect_error(hyperbolic_index(g, "wrong"))
skip_on_cran()
g <- igraph::make_full_graph(2)
expect_true(all(round(hyperbolic_index(g, "odd"), 6) == 0))
expect_true(all(hyperbolic_index(g, "even") != 0))
expect_error(hyperbolic_index(g, "wrong"))
})
4 changes: 2 additions & 2 deletions tests/testthat/test_dominance.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("neighborhood-inclusion is correct", {
})

test_that("positional dominance is correct", {
g <- graph.empty(n = 11, directed = FALSE)
g <- make_empty_graph(n = 11, directed = FALSE)
g <- add_edges(g, c(
1, 11, 2, 4, 3, 5, 3, 11, 4, 8, 5, 9, 5, 11, 6, 7, 6, 8,
6, 10, 6, 11, 7, 9, 7, 10, 7, 11, 8, 9, 8, 10, 9, 10
Expand Down Expand Up @@ -61,7 +61,7 @@ test_that("dominance_graph is correct", {
library(igraph)
library(magrittr)

g <- graph.empty(n = 11, directed = FALSE)
g <- make_empty_graph(n = 11, directed = FALSE)
g <- add_edges(g, c(
1, 11, 2, 4, 3, 5, 3, 11, 4, 8, 5, 9, 5, 11, 6, 7, 6, 8,
6, 10, 6, 11, 7, 9, 7, 10, 7, 11, 8, 9, 8, 10, 9, 10
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library(igraph)
library(magrittr)
library(Matrix)
test_that("majorization gap is correct", {
g <- graph.empty(n = 11, directed = FALSE)
g <- make_empty_graph(n = 11, directed = FALSE)
g <- add_edges(g, c(
1, 11, 2, 4, 3, 5, 3, 11, 4, 8, 5, 9, 5, 11, 6, 7, 6, 8,
6, 10, 6, 11, 7, 9, 7, 10, 7, 11, 8, 9, 8, 10, 9, 10
Expand All @@ -16,12 +16,12 @@ test_that("majorization gap is correct", {
expect_equal(round(majorization_gap(tg), 7), 0)
expect_equal(majorization_gap(tg, norm = FALSE), 0)
expect_error(majorization_gap("a"))
expect_error(majorization_gap(igraph::graph.full(2, directed = TRUE)))
expect_warning(majorization_gap(igraph::graph.full(3) + igraph::graph.full(3)))
expect_error(majorization_gap(igraph::make_full_graph(2, directed = TRUE)))
expect_warning(majorization_gap(igraph::make_full_graph(3) + igraph::make_full_graph(3)))
})

test_that("spectral gap is correct", {
g <- graph.star(10, "undirected")
g <- make_star(10, "undirected")

expect_equal(spectral_gap(g, method = "frac"), 1)
expect_equal(spectral_gap(g, method = "abs"), 3)
Expand Down Expand Up @@ -50,7 +50,7 @@ test_that("transitive_reduction is correct", {

test_that("is_preserved is correct", {
library(igraph)
g <- graph.empty(n = 11, directed = FALSE)
g <- make_empty_graph(n = 11, directed = FALSE)
g <- add_edges(g, c(
1, 11, 2, 4, 3, 5, 3, 11, 4, 8, 5, 9, 5, 11, 6, 7, 6, 8,
6, 10, 6, 11, 7, 9, 7, 10, 7, 11, 8, 9, 8, 10, 9, 10
Expand Down
Loading

0 comments on commit ae706ee

Please sign in to comment.