Skip to content

Commit b0bd0bf

Browse files
authored
Merge pull request #32 from anespinosa/develop
Power matrix
2 parents 6af0812 + 0af7703 commit b0bd0bf

File tree

19 files changed

+626
-233
lines changed

19 files changed

+626
-233
lines changed

.Rproj.user/shared/notebooks/paths

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/Users/aespinos/Dropbox/ETH_projects/netmem/.Rbuildignore="A3A737FB"
22
/Users/aespinos/Dropbox/ETH_projects/netmem/.Rhistory="0D0BE554"
33
/Users/aespinos/Dropbox/ETH_projects/netmem/.github/.gitignore="F038E639"
4+
/Users/aespinos/Dropbox/ETH_projects/netmem/.github/workflows/R-CMD-check.yaml="A4C2AAC2"
45
/Users/aespinos/Dropbox/ETH_projects/netmem/.github/workflows/lint.yaml="A1438DC2"
56
/Users/aespinos/Dropbox/ETH_projects/netmem/.gitignore="5DCD065B"
67
/Users/aespinos/Dropbox/ETH_projects/netmem/DESCRIPTION="9606DCF0"

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export(multilevel_degree)
3939
export(multiplex_census)
4040
export(percolation_clique)
4141
export(posneg_index)
42+
export(power_function)
4243
export(q_analysis)
4344
export(recip_coef)
4445
export(redundancy)

R/utilities.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,3 +1236,37 @@ extract_component <- function(A, maximum = TRUE, position = NULL) {
12361236
}
12371237
return(components)
12381238
}
1239+
1240+
#' Power matrix
1241+
#'
1242+
#' Power of a matrix computed by succesive matrix multiplication.
1243+
#'
1244+
#' @param A A matrix
1245+
#' @param n Positive integer
1246+
#'
1247+
#' @return This function return the power of a matrix by repeating matrix multiplication.
1248+
#'
1249+
#' @references
1250+
#'
1251+
#' Wasserman, S. and Faust, K. (1994). Social network analysis: Methods and applications. Cambridge University Press.
1252+
#'
1253+
#' @author Alejandro Espinosa-Rada
1254+
#'
1255+
#' @examples
1256+
#' A <- matrix(c(1,0,0,0,
1257+
#' 1,1,0,0,
1258+
#' 1,0,1,0,
1259+
#' 0,1,1,1), byrow = TRUE, ncol = 4, nrow = 4)
1260+
#' power_function(A, 1000)
1261+
#'
1262+
#' @export
1263+
1264+
power_function<- function(A, n){
1265+
return(powA(n))
1266+
}
1267+
1268+
powA <- function(n){
1269+
if (n == 1) return(A)
1270+
if (n == 2) return(A %*% A)
1271+
if (n > 2) return(A %*% powA(n-1))
1272+
}

0 commit comments

Comments
 (0)