Title: | Network Sparsification |
---|---|
Description: | Network sparsification with a variety of novel and known network sparsification techniques. All network sparsification techniques reduce the number of edges, not the number of nodes. Network sparsification is sometimes referred to as network dimensionality reduction. This package is based on the work of Spielman, D., Srivastava, N. (2009)<arXiv:0803.0929>. Koutis I., Levin, A., Peng, R. (2013)<arXiv:1209.5821>. Toivonen, H., Mahler, S., Zhou, F. (2010)<doi:10.1007>. Foti, N., Hughes, J., Rockmore, D. (2011)<doi:10.1371>. |
Authors: | Andrew Kramer [aut], Alexander Mercier [aut, cre, trl], Shubhankar Tripathi [ctb], Tomlin Pulliam [ctb], John Drake [ctb] |
Maintainer: | Alexander Mercier <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.1 |
Built: | 2024-12-12 06:52:34 UTC |
Source: | CRAN |
Calculates network sparsifier from best path
bestpath(network, directed = FALSE, associative = TRUE)
bestpath(network, directed = FALSE, associative = TRUE)
network |
Weighted adjacency matrix, weighted |
directed |
If |
associative |
Designates if the network is associative where edge weight determines "similarity" or "strength" or dissociative where edge weight denotes "dissimilarity" or "distance". |
Edge list of sparsified network via best path.
Alexander Mercier
Andrew Kramer
Toivonen, H., Mahler, S., & Zhou, F. (2010, May). A framework for path-oriented network simplification. In International Symposium on Intelligent Data Analysis (pp. 220-231). Springer, Berlin, Heidelberg.
#Generate random ER graph with uniformly random edge weights g = igraph::erdos.renyi.game(50, 0.1) igraph::E(g)$weight <- runif(length(igraph::E(g))) #Sparsify g via bestpath S = simplifyNet::bestpath(g, directed = FALSE, associative = TRUE) #Show edge list conversion sg = simplifyNet::net.as(S, net.to="igraph", directed=FALSE) igraph::ecount(sg)/igraph::ecount(g)#fraction of edges in the sparsifier
#Generate random ER graph with uniformly random edge weights g = igraph::erdos.renyi.game(50, 0.1) igraph::E(g)$weight <- runif(length(igraph::E(g))) #Sparsify g via bestpath S = simplifyNet::bestpath(g, directed = FALSE, associative = TRUE) #Show edge list conversion sg = simplifyNet::net.as(S, net.to="igraph", directed=FALSE) igraph::ecount(sg)/igraph::ecount(g)#fraction of edges in the sparsifier
Calculate or approximate the effective resistances of an inputted, undirected graph. There are three methods.
(1) 'ext' which exactly calculates the effective resistances (WARNING! Not ideal for large graphs).
(2) 'spl' which approximates the effective resistances of the inputted graph using the original Spielman-Srivastava algorithm.
(3) 'kts' which approximates the effective resistances of the inputted graph using the implementation by Koutis et al. (ideal for large graphs where memory usage is a concern).
The relative fidelity of the approximation methods is governed by the variable epsilon.
EffR(network, epsilon = 0.1, type = "kts", tol = 1e-10)
EffR(network, epsilon = 0.1, type = "kts", tol = 1e-10)
network |
Weighted adjacency matrix, weighted |
epsilon |
Variable epsilon governs the relative fidelity of the approximation methods 'spl' and 'kts'. The smaller the value the greater the fidelity of the approximation. Default value is 0.1. |
type |
There are three methods. |
tol |
Tolerance for the linear algebra (conjugate gradient) solver to find the effective resistances. Default value is 1e-10. |
The fidelity of the effective resistance approximation decreases with a decrease in epsilon
. However, it is more important for sparsification by effective resistances that the approximations be roughly equivalent relative to one another, as they will be normalized in a probability distribution where exact values are not needed.
The number of edges contained in the sparsifier will be less than or equal to the number of samples taken, q
.
Return either exact or approximate effective resistances for each edge in the same order as "weight" in the edge list.
Alexander Mercier
Spielman, D. A., & Srivastava, N. (2011). Graph sparsification by effective resistances. SIAM Journal on Computing, 40(6), 1913-1926.
Koutis, I., Miller, G. L., & Peng, R. (2014). Approaching optimality for solving SDD linear systems. SIAM Journal on Computing, 43(1), 337-354.
E_List = matrix(c(1,1,2,2,3,3,1,1,1), 3, 3) #Triangle graph, \eqn{K_3}, with edge weights equal to 1 effR = simplifyNet::EffR(E_List, epsilon = 0.1, type = 'kts', tol = 1e-10)
E_List = matrix(c(1,1,2,2,3,3,1,1,1), 3, 3) #Triangle graph, \eqn{K_3}, with edge weights equal to 1 effR = simplifyNet::EffR(E_List, epsilon = 0.1, type = 'kts', tol = 1e-10)
Sparsify an undirected network by sampling edges proportional to where
is the weight of edge
and
is the effective resistance of edge
.
Approximately preserves the graph Laplacian, L
, with increasing fidelity as the number of samples taken increases.
EffRSparse(network, q, effR, seed, n)
EffRSparse(network, q, effR, seed, n)
network |
Weighted adjacency matrix, weighted |
q |
The numbers of samples taken. The fidelity to the original network increases as the number of samples increases, but decreases the sparseness. |
effR |
Effective resistances corresponding to each edge. Should be in the same order as "weight". |
seed |
Set the seed to reproduce results of random sampling. |
n |
The number of nodes in the network. Default is the max node index of the edge list. |
The performance of this method is dependent on the size of the network and fidelity of the effective resistance approximation. The network should be "sufficiently large."
For more details, see: https://epubs.siam.org/doi/epdf/10.1137/080734029
A sparsified network, H
, edge list where the number of edges is dependent on the number of samples taken, q
.
Daniel A. Spielman,
Alexander Mercier
Spielman, D. A., & Srivastava, N. (2011). Graph sparsification by effective resistances. SIAM Journal on Computing, 40(6), 1913-1926.
#Generate random ER graph with uniformly random edge weights g = igraph::erdos.renyi.game(100, 0.1) igraph::E(g)$weight <- runif(length(igraph::E(g))) #Approximate effective resistances effR = simplifyNet::EffR(g) #Use effective resistances to create spectral sparsifier by edge sampling S = simplifyNet::EffRSparse(g, q = 200, effR = effR, seed = 150) sg = simplifyNet::net.as(S, net.to="igraph", directed=FALSE) igraph::ecount(sg)/igraph::ecount(g)#fraction of edges in the sparsifier
#Generate random ER graph with uniformly random edge weights g = igraph::erdos.renyi.game(100, 0.1) igraph::E(g)$weight <- runif(length(igraph::E(g))) #Approximate effective resistances effR = simplifyNet::EffR(g) #Use effective resistances to create spectral sparsifier by edge sampling S = simplifyNet::EffRSparse(g, q = 200, effR = effR, seed = 150) sg = simplifyNet::net.as(S, net.to="igraph", directed=FALSE) igraph::ecount(sg)/igraph::ecount(g)#fraction of edges in the sparsifier
Convert an edge list to an adjacency matrix.
EList_Mtrx(E_List, directed = FALSE, n)
EList_Mtrx(E_List, directed = FALSE, n)
E_List |
Edge list formatted | n1 | n2 | weight |. |
directed |
Specifies if the network is directed or undirected. Default is set to undirected. |
n |
Specify number of nodes. Default is |
Adjacency matrix constructed from edge list, E_List
, of the class dgCMatrix.
Alexander Mercier
Remove all edges under certain edge weight threshold.
gns(network, remove.prop, cutoff, directed = FALSE)
gns(network, remove.prop, cutoff, directed = FALSE)
network |
Weighted adjacency matrix, weighted |
remove.prop |
The proportion of highest weighted edges to retain. A value between 0 and 1. |
cutoff |
Threshold value for edge weight thresholding. |
directed |
If |
Edge list of sparsified network
Andrew Kramer
Alexander Mercier
#Generate random ER graph with uniformly random edge weights g = igraph::erdos.renyi.game(100, 0.1) igraph::E(g)$weight <- runif(length(igraph::E(g))) #Sparsify g via GNS S = gns(g, remove.prop = 0.5) sg = simplifyNet::net.as(S, net.to="igraph", directed=FALSE) igraph::ecount(sg)/igraph::ecount(g)#fraction of edges in the sparsifier
#Generate random ER graph with uniformly random edge weights g = igraph::erdos.renyi.game(100, 0.1) igraph::E(g)$weight <- runif(length(igraph::E(g))) #Sparsify g via GNS S = gns(g, remove.prop = 0.5) sg = simplifyNet::net.as(S, net.to="igraph", directed=FALSE) igraph::ecount(sg)/igraph::ecount(g)#fraction of edges in the sparsifier
Iterative sparsifcation based refitting.
irefit( network, func, tol, rank = "none", connected = FALSE, directed = FALSE, per = 0.5 )
irefit( network, func, tol, rank = "none", connected = FALSE, directed = FALSE, per = 0.5 )
network |
Weighted adjacency matrix, weighted |
func |
Model function whose input is the network and whose output is a single real value or a list of reevaluated weights in the first index and a real value in the second. |
tol |
Allowed error around the original output of |
rank |
Ranking of edges. Lower ranked edges are removed first. Must be the same length as |
connected |
If TRUE, connectivity of the network is prioritized over scoring by |
directed |
If |
per |
Percentage of edges to add/remove from the sparsifier at each step. |
Sparsified network, H
, which still maintains evaluator function, func
, plus/minus tol
.
Alexander Mercier
Andrew Kramer
#Set scoring function mean.weight.degree <- function(graph){ graph.ob <- igraph::graph_from_edgelist(graph[,1:2]) igraph::E(graph.ob)$weight <- graph[,3] return(mean(igraph::strength(graph.ob))) } #Generate random graph g <- igraph::erdos.renyi.game(100, 0.1) igraph::E(g)$weight <- rexp(length(igraph::E(g)), rate=10) #random edge weights from exp(10) E_List <- cbind(igraph::as_edgelist(g), igraph::E(g)$weight) colnames(E_List) <- c("n1", "n2", "weight") sparse_dist <- simplifyNet::irefit(E_List, func=mean.weight.degree, tol = 0.1)
#Set scoring function mean.weight.degree <- function(graph){ graph.ob <- igraph::graph_from_edgelist(graph[,1:2]) igraph::E(graph.ob)$weight <- graph[,3] return(mean(igraph::strength(graph.ob))) } #Generate random graph g <- igraph::erdos.renyi.game(100, 0.1) igraph::E(g)$weight <- rexp(length(igraph::E(g)), rate=10) #random edge weights from exp(10) E_List <- cbind(igraph::as_edgelist(g), igraph::E(g)$weight) colnames(E_List) <- c("n1", "n2", "weight") sparse_dist <- simplifyNet::irefit(E_List, func=mean.weight.degree, tol = 0.1)
Remove all edges under certain probability of the fractional edge weight, alpha
.
lans(network, alpha, output, directed = FALSE)
lans(network, alpha, output, directed = FALSE)
network |
Weighted adjacency matrix, weighted |
alpha |
The |
output |
If the output should be directed or undirected. Default is that the output is the same as the input based on adjacency matrix symmetry. If the default is overridden, set as either "undirected" or "directed". |
directed |
If |
For more information on finding alpha values, see: https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0016431#s5
Weighted adjacency matrix of sparsified network.
Andrew Kramer
Alexander Mercier
Foti, N. J., Hughes, J. M., & Rockmore, D. N. (2011). Nonparametric sparsification of complex multiscale networks. PloS one, 6(2), e16431.
#Generate random ER graph with uniformly random edge weights g = igraph::erdos.renyi.game(100, 0.1) igraph::E(g)$weight <- runif(length(igraph::E(g))) #Sparsify g via LANS S = lans(g, alpha = 0.3, output = "undirected", directed = FALSE) #Convert sparsifier to edge list S_List = simplifyNet::Mtrx_EList(S, directed = FALSE) sg = simplifyNet::net.as(S_List, net.to="igraph", directed=FALSE) igraph::ecount(sg)/igraph::ecount(g)#fraction of edges in the sparsifier
#Generate random ER graph with uniformly random edge weights g = igraph::erdos.renyi.game(100, 0.1) igraph::E(g)$weight <- runif(length(igraph::E(g))) #Sparsify g via LANS S = lans(g, alpha = 0.3, output = "undirected", directed = FALSE) #Convert sparsifier to edge list S_List = simplifyNet::Mtrx_EList(S, directed = FALSE) sg = simplifyNet::net.as(S_List, net.to="igraph", directed=FALSE) igraph::ecount(sg)/igraph::ecount(g)#fraction of edges in the sparsifier
Convert an adjacency matrix to an edge list.
Mtrx_EList(A, directed = FALSE)
Mtrx_EList(A, directed = FALSE)
A |
Weighted adjacency matrix. |
directed |
Specifies if the network is directed or undirected. Default is set to undirected. |
An edge list, E_List
, of adjacency matrix, A
, of the form | n1 | n2 | weight |.
Alexander Mercier
Convert a network in weighted adjacency matrix, edge list, or igraph to a weighted adjacency matrix, edge list, or igraph format.
net.as(network, net.to = "E_List", directed = FALSE)
net.as(network, net.to = "E_List", directed = FALSE)
network |
Weighted adjacency matrix, weighted |
net.to |
Specifics to what format the imputed network is to be converted: |
directed |
If |
A network of the format specified by net.to
.
Alexander Mercier