├── .gitignore
├── data
├── .m88-v2.csv.swp
├── maxKnownKs.csv
├── m88.csv
├── m88-v2.csv
├── m88-v3.csv
└── K-3x3.csv
├── scripts
├── listEdges.R
├── compressionLength.R
├── relabelTables.R
├── loadGraph.R
├── loadGraph.R~
├── BDM2D.R
├── BDM1D.R
└── edgeAndVertexKnockout.R
├── report.Rmd
├── README.md
├── BDM2D.R
├── ui.R
├── server.R
└── LICENSE.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rhistory
2 | ./scripts/.Rhistory
3 |
--------------------------------------------------------------------------------
/data/.m88-v2.csv.swp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/algorithmicnaturelab/OACC/HEAD/data/.m88-v2.csv.swp
--------------------------------------------------------------------------------
/data/maxKnownKs.csv:
--------------------------------------------------------------------------------
1 | "","K.2","K.4","K.5","K.6","K.9"
2 | "1",37.0641988031379,40.5065171208468,42.2639233189173,43.6574062551325,52.8978703506378
3 |
--------------------------------------------------------------------------------
/data/m88.csv:
--------------------------------------------------------------------------------
1 | 1,1,1,0,0,0,1,1
2 | 1,0,0,1,1,0,1,0
3 | 0,0,0,0,0,0,0,0
4 | 0,0,0,1,1,0,1,0
5 | 1,1,0,0,0,0,1,0
6 | 0,0,1,0,1,1,1,0
7 | 0,1,1,1,1,0,1,0
8 | 1,1,1,1,1,1,1,0
--------------------------------------------------------------------------------
/data/m88-v2.csv:
--------------------------------------------------------------------------------
1 | 0,1,0,0,0,0,1,0
2 | 1,0,0,1,1,0,1,0
3 | 0,0,0,0,0,0,0,0
4 | 0,0,0,1,0,0,0,0
5 | 1,1,0,0,0,0,0,0
6 | 0,0,1,0,0,1,1,0
7 | 0,1,1,1,0,0,0,0
8 | 1,1,1,1,0,1,1,0
9 |
--------------------------------------------------------------------------------
/data/m88-v3.csv:
--------------------------------------------------------------------------------
1 | 1,1,0,0,0,0,1,1
2 | 1,1,1,1,1,0,1,1
3 | 1,1,1,0,1,0,0,1
4 | 0,0,0,1,0,0,0,1
5 | 1,1,0,0,0,0,0,1
6 | 1,1,1,0,0,1,1,1
7 | 1,1,1,1,0,0,0,0
8 | 1,1,1,1,0,1,1,1
9 |
--------------------------------------------------------------------------------
/scripts/listEdges.R:
--------------------------------------------------------------------------------
1 | listEdges <- function(gra){
2 |
3 | edgeList <- as_edgelist(gra, names = TRUE)
4 |
5 | printableEdgeList <- character(nrow(edgeList))
6 |
7 | if (nrow(edgeList) > 0){
8 | for (i in 1:nrow(edgeList)) {
9 |
10 | printableEdgeList[i] <- paste0(edgeList[i,1],
11 | "|",
12 | edgeList[i, 2])
13 |
14 | }
15 |
16 | return(printableEdgeList)
17 | }
18 | return("no links")
19 | }
--------------------------------------------------------------------------------
/scripts/compressionLength.R:
--------------------------------------------------------------------------------
1 | compressionLength <- function(string, compressionType){
2 | len <- length(memCompress(string, compressionType))
3 | return(len)
4 | }
5 |
6 | ## https://en.wikipedia.org/wiki/Gzip
7 | #g <- compressionLength("0101010101010101", "gzip")
8 | #g
9 |
10 | ## https://en.wikipedia.org/wiki/Bzip2
11 | # b <- compressionLength("0101010101010101", "bzip")
12 | # b
13 | #
14 |
15 | ## https://en.wikipedia.org/wiki/Xz
16 | # x <- compressionLength("0101010101010101", "xz")
17 | # x
18 |
19 | #testList <- c("00000000001", "0000000000", "010101010101")
20 | #test <- lapply(testList, compressionLength, compressionType = "gzip")
21 | #test
22 |
23 | # if (!is.matrix(test)) {
24 | # test <- as.matrix(test)
25 | # colnames(test) <- "Compression length by gzip"
26 | # }
27 | # test
28 | #
29 | # test2 <- "000000000000000000000000111111111000"
30 | # len <- compressionLength(test2, "gzip")
31 | # len
32 | # gz1 <- gzfile("test2.gz", "w")
33 | # write.csv(test2, gz1)
34 | # close(gz1)
--------------------------------------------------------------------------------
/scripts/relabelTables.R:
--------------------------------------------------------------------------------
1 | relabelVertexTable <- function(oldVertexTable){
2 |
3 | vertexTable <- oldVertexTable
4 |
5 | vertexTable$name <- NULL
6 | vertexTable$color <- NULL
7 |
8 | #print(vertexTable)
9 |
10 | vertexTable$bdmIncrease[vertexTable$bdmIncrease] <- "positive"
11 | vertexTable$bdmIncrease[vertexTable$bdmIncrease == FALSE] <- "negative"
12 |
13 | colnames(vertexTable) <- c("Node label",
14 | "BDM of graph after node knockout",
15 | "BDM diff",
16 | "Information value",
17 | "Perturbation rank")
18 |
19 | return(vertexTable)
20 |
21 | }
22 |
23 | relabelEdgeTable <- function(oldEdgeTable){
24 |
25 | edgeTable <- oldEdgeTable
26 |
27 | edgeTable$color <- NULL
28 |
29 | edgeTable$bdmIncrease[edgeTable$bdmIncrease] <- "positive"
30 | edgeTable$bdmIncrease[edgeTable$bdmIncrease == FALSE] <- "negative"
31 | colnames(edgeTable) <- c("Link origin",
32 | "Link end",
33 | "BDM value after link knockout",
34 | "BDM diff",
35 | "Information value",
36 | "Perturbation rank")
37 | return (edgeTable)
38 | }
--------------------------------------------------------------------------------
/scripts/loadGraph.R:
--------------------------------------------------------------------------------
1 | require("igraph")
2 |
3 | #(PA for Perturbation Analysis)
4 | loadGraphPA <- function(dataPath)
5 | {
6 |
7 | loadedDF <- read.csv(dataPath,
8 | header=FALSE,
9 | sep=',', #separate by comma
10 | quote="'", # quote by '
11 | stringsAsFactors = FALSE,
12 | check.names = FALSE)
13 |
14 | #selects numeric values, drops the rest
15 | loadedDF <- loadedDF[sapply(loadedDF, is.numeric)]
16 |
17 | rownames(loadedDF) <- colnames(loadedDF)
18 | loadedMat <- as.matrix(loadedDF)
19 |
20 | g <- graph_from_adjacency_matrix(loadedMat) %>%
21 | set_vertex_attr("label", value = rownames(loadedDF) )
22 |
23 |
24 | return(g)
25 | }
26 |
27 |
28 | loadGraph <- function(dataPath,
29 | separator,
30 | quoteSymbol)
31 | {
32 |
33 | loadedDf <- read.csv(dataPath,
34 | header=FALSE,
35 | sep=separator,
36 | quote=quoteSymbol,
37 | stringsAsFactors = FALSE,
38 | check.names = FALSE)
39 |
40 | #selects numeric values, drops the rest
41 | loadedDf <- loadedDf[sapply(loadedDf, is.numeric)]
42 |
43 | rownames(loadedDf) <- colnames(loadedDf)
44 | loadedMat <- as.matrix(loadedDf)
45 | loadedMat
46 | }
47 |
48 |
49 | #### remember to test path
50 | #test <- loadGraphPA("./data/m88.csv")
51 | #plot(test, edge.arrow.size = 0.2)
52 |
--------------------------------------------------------------------------------
/scripts/loadGraph.R~:
--------------------------------------------------------------------------------
1 | require("igraph")
2 |
3 | #(PA for Perturbation Analysis)
4 | loadGraphPA <- function(dataPath)
5 | {
6 |
7 | loadedDF <- read.csv(dataPath,
8 | header=FALSE,
9 | sep=',', #separate by comma
10 | quote="'", # quote by '
11 | stringsAsFactors = FALSE,
12 | check.names = FALSE)
13 |
14 | #selects numeric values, drops the rest
15 | loadedDF <- loadedDF[sapply(loadedDF, is.numeric)]
16 |
17 | rownames(loadedDF) <- colnames(loadedDF)
18 | loadedMat <- as.matrix(loadedDF)
19 |
20 | g <- graph_from_adjacency_matrix(loadedMat) %>%
21 | set_vertex_attr("label", value = rownames(loadedDF) )
22 |
23 |
24 | return(g)
25 | }
26 |
27 |
28 | loadGraph <- function(dataPath,
29 | separator,
30 | quoteSymbol)
31 | {
32 |
33 | loadedDf <- read.csv(dataPath,
34 | header=FALSE,
35 | sep=separator,
36 | quote=quoteSymbol,
37 | stringsAsFactors = FALSE,
38 | check.names = FALSE)
39 |
40 | #selects numeric values, drops the rest
41 | loadedDf <- loadedDf[sapply(loadedDf, is.numeric)]
42 |
43 | rownames(loadedDf) <- colnames(loadedDf)
44 | loadedMat <- as.matrix(loadedDf)
45 | loadedMat
46 | }
47 |
48 |
49 | #### remember to test path
50 | #test <- loadGraphPA("./data/m88.csv")
51 | #plot(test, edge.arrow.size = 0.2)
52 |
--------------------------------------------------------------------------------
/report.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Perturbation Analysis Report"
3 | output: html_document
4 | params:
5 | perturbationCounter: NA
6 | graphHistory: !r list()
7 | pvHistory: !r list()
8 | peHistory: !r list()
9 | delEventHistory: !r list()
10 |
11 | ---
12 |
13 | ```{r eval = FALSE, echo = FALSE}
14 | # For PDF output, change the header to have "output: pdf_document".
15 | #
16 | # Note that due to an issue in rmarkdown, the default value of a parameter in
17 | # the header cannot be `NULL`, so I used a default of `NA` for the default value
18 | # of `n`.
19 | require(igraph)
20 | require(knitr)
21 | require(xtable)
22 | ```
23 |
24 |
25 |
26 | ```{r results= 'asis', echo = FALSE}
27 |
28 | # https://stackoverflow.com/questions/28313600/r-knitr-print-in-a-loop
29 | # https://github.com/yihui/knitr/issues/886
30 |
31 |
32 | #https://stackoverflow.com/questions/32418860/output-markdown-in-r-code-chunk
33 | for (i in 1:params$perturbationCounter){
34 |
35 | cat('\n')
36 |
37 | cat(paste0("### ",params$delEventHistory[[i]]))
38 |
39 | cat('\n')
40 |
41 | coords <- layout_(params$graphHistory[[i]], as_star())
42 |
43 | plot(params$graphHistory[[i]], layout = coords, edge.arrow.size = 0.4,
44 | vertex.size = 25, vertex.label.family = "Arial Black")
45 |
46 | cat('\n')
47 |
48 | print(knitr::kable(params$pvHistory[[i]], caption = "Possible node perturbations",
49 | row.names = FALSE))
50 | cat('\n')
51 |
52 | print(knitr::kable(params$peHistory[[i]], caption = "Possible link perturbations",
53 | row.names = FALSE))
54 |
55 | cat('\n')
56 |
57 | }
58 | ```
59 |
60 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # The Online Algorithmic Complexity Calculator v3.0
2 | ## R Shiny App
3 |
4 |
5 | [R Shiny](http://shiny.rstudio.com/) code for the [Online Algorithmic Complexity Calculator](http://complexitycalculator.com/) version 3.0 by the [Algorithmic Nature Group](http://algorithmicnaturelab.org/) and the [Algorithmic Dynamics Lab](http://www.algorithmicdynamics.net/).
6 |
7 | To run this app locally, download [R Studio](https://www.rstudio.com/) and follow the instructions [here](http://shiny.rstudio.com/tutorial/lesson1/).
8 |
9 |
10 | Our Block Decomposition Method to estimate [Kolmogorov complexity](http://www.scholarpedia.org/article/Algorithmic_complexity) in strings and graphs of arbitrary size is described in **[A Divide-and-Conquer Method for Local Estimations of Algorithmic Complexity Lower Bounded by Shannon Entropy](https://arxiv.org/pdf/1609.00110.pdf)** by H. Zenil, F. Soler-Toscano, N.A. Kiani, S. Hernández-Orozco, and A. Rueda-Toicen.
11 |
12 | The Coding Theorem Method and the Block Decomposition Method are also described in **[Calculating Kolmogorov Complexity from the Output Frequency Distributions of Small Turing Machines](http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0096223)** by F. Soler-Toscano, H. Zenil, J.-P. Delahaye and N. Gauvrit.
13 |
14 | If you make use of results from this calculator, please make sure to visit [How To Cite](http://complexitycalculator.com/HowToCite.html).
15 |
16 | This app uses the [acss package](https://cran.r-project.org/web/packages/acss/index.html) available at CRAN and maintained by Henrik Singmann.
17 |
18 | ## License
19 |
20 | [GNU Affero General Public License v3.0](http://choosealicense.com/licenses/agpl-3.0)
21 |
22 | #### Maintainer
23 |
24 | [Antonio Rueda-Toicen](http://www.digital-spaceti.me/)
25 |
26 | antonio.rueda.toicen " at " algorithmicnaturelab (-dot-) org
27 |
28 | #### [www.complexitycalculator.com](www.complexitycalculator.com)
29 |
30 | #### [www.algorithmicnaturelab.org](www.algorithmicnaturelab.org)
31 |
32 |
--------------------------------------------------------------------------------
/BDM2D.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #load 4 x 4 CTM values
4 | fourByFourCTM <- read.csv("./data/K-4x4.csv",
5 | stringsAsFactors=FALSE,
6 | colClasses =
7 | c("character", "numeric"),
8 | header = FALSE)
9 |
10 | colnames(fourByFourCTM) <- c("square", "CTM")
11 | rownames(fourByFourCTM) <- fourByFourCTM$square
12 | fourByFourCTM$square <- NULL
13 |
14 | #load 3 x 3 CTM values
15 | threeByThreeCTM <- read.csv("./data/K-3x3.csv",
16 | stringsAsFactors=FALSE,
17 | colClasses =
18 | c("character", "numeric"),
19 | header = FALSE)
20 |
21 | colnames(threeByThreeCTM) <- c("square", "CTM")
22 | rownames(threeByThreeCTM) <- threeByThreeCTM$square
23 | threeByThreeCTM$square <- NULL
24 |
25 |
26 | ##split matrices in blocks
27 | require(purrr)
28 | ind <- function(matDim, blockSize, offset) {
29 | Map(`:`, seq(1, matDim-blockSize+1, by = offset),
30 | seq(blockSize, matDim, by = offset))
31 | }
32 |
33 | # this is a helper function that generates subset indexing
34 | # according to dimension of the
35 | # matrix, the first sequence constructs the starting point of the subset index considering
36 | # the offset while the second sequence constructs
37 | # the ending point of the subset index
38 | myPartition <- function(mat, blockSize, offset) {
39 | lapply(cross2(ind(nrow(mat),blockSize,offset),
40 | ind(ncol(mat),blockSize,offset)),
41 | function(i) mat[i[[1]], i[[2]]])
42 | }
43 |
44 | #used to lookup entries in fourByFourCTM and threeByThreeCTM
45 | stringify <- function(smallBlock){
46 | paste0(c(t(smallBlock)), collapse ="")
47 | }
48 |
49 | blockEntropy <- function(mat, blockSize, offset){
50 |
51 | parts <- myPartition(mat, blockSize, offset)
52 |
53 | flatSquares <- unlist(lapply(parts, stringify))
54 |
55 | squaresTally <- as.data.frame(table(flatSquares))
56 |
57 | rownames(squaresTally) <- squaresTally$flatSquare
58 |
59 | squaresTally$flatSquares <- NULL
60 |
61 | probs = squaresTally[, 1]/nrow(squaresTally)
62 |
63 | return(-sum(probs*log2(probs)))
64 |
65 | }
66 |
67 | bdm2D <- function(mat, blockSize, offset){
68 |
69 | parts <- myPartition(mat, blockSize, offset)
70 |
71 | flatSquares <- unlist(lapply(parts, stringify))
72 |
73 | squaresTally <- as.data.frame(table(flatSquares))
74 |
75 | rownames(squaresTally) <- squaresTally$flatSquares
76 |
77 | squaresTally$flatSquares <- NULL
78 |
79 | if(blockSize == 4){
80 | bdm <- (sum(fourByFourCTM[rownames(squaresTally),])
81 | + sum(log2(squaresTally$Freq)))
82 | } else{
83 | bdm <- (sum(threeByThreeCTM[rownames(squaresTally),])
84 | + sum(log2(squaresTally$Freq)))
85 | }
86 |
87 | return(bdm)
88 | }
89 |
90 | ## tests
91 | # set.seed(42)
92 | # m99 <- apply(matrix(0, 9, 9), c(1,2), function(x) sample(c(0,1),1))
93 | # m99
94 |
95 | # testResult1 <- bdm2D(m88, 4, 4)
96 | # testResult1
97 | #
98 | #
99 | # testResult2 <- bdm2D(m99, 3, 3)
100 | # testResult2
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/scripts/BDM2D.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #load 4 x 4 CTM values
4 | fourByFourCTM <- read.csv("data/K-4x4.csv",
5 | stringsAsFactors=FALSE,
6 | colClasses =
7 | c("character", "numeric"),
8 | header = FALSE)
9 |
10 | colnames(fourByFourCTM) <- c("square", "CTM")
11 | rownames(fourByFourCTM) <- fourByFourCTM$square
12 | fourByFourCTM$square <- NULL
13 |
14 | #load 3 x 3 CTM values
15 | threeByThreeCTM <- read.csv("data/K-3x3.csv",
16 | stringsAsFactors=FALSE,
17 | colClasses =
18 | c("character", "numeric"),
19 | header = FALSE)
20 |
21 | colnames(threeByThreeCTM) <- c("square", "CTM")
22 | rownames(threeByThreeCTM) <- threeByThreeCTM$square
23 | threeByThreeCTM$square <- NULL
24 |
25 |
26 | ##split matrices in blocks
27 | require(purrr)
28 | ind <- function(matDim, blockSize, offset) {
29 | Map(`:`, seq(1, matDim-blockSize+1, by = offset),
30 | seq(blockSize, matDim, by = offset))
31 | }
32 |
33 | # this is a helper function that generates subset indexing
34 | # according to dimension of the
35 | # matrix, the first sequence constructs the starting point of the subset index considering
36 | # the offset while the second sequence constructs
37 | # the ending point of the subset index
38 | myPartition <- function(mat, blockSize, offset) {
39 | lapply(cross2(ind(nrow(mat),blockSize,offset),
40 | ind(ncol(mat),blockSize,offset)),
41 | function(i) mat[i[[1]], i[[2]]])
42 | }
43 |
44 | #used to lookup entries in fourByFourCTM and threeByThreeCTM
45 | stringify <- function(smallBlock){
46 | paste0(c(t(smallBlock)), collapse ="")
47 | }
48 |
49 | blockEntropy <- function(mat, blockSize, offset){
50 |
51 | parts <- myPartition(mat, blockSize, offset)
52 |
53 | flatSquares <- unlist(lapply(parts, stringify))
54 |
55 | squaresTally <- as.data.frame(table(flatSquares))
56 |
57 | rownames(squaresTally) <- squaresTally$flatSquare
58 |
59 | squaresTally$flatSquares <- NULL
60 |
61 | probs = squaresTally[, 1]/nrow(squaresTally)
62 |
63 | return(-sum(probs*log2(probs)))
64 |
65 | }
66 |
67 | bdm2D <- function(mat, blockSize, offset){
68 |
69 | parts <- myPartition(mat, blockSize, offset)
70 |
71 | flatSquares <- unlist(lapply(parts, stringify))
72 |
73 | squaresTally <- as.data.frame(table(flatSquares))
74 |
75 | rownames(squaresTally) <- squaresTally$flatSquares
76 |
77 | squaresTally$flatSquares <- NULL
78 |
79 | if(blockSize == 4){
80 | bdm <- (sum(fourByFourCTM[rownames(squaresTally),])
81 | + sum(log2(squaresTally$Freq)))
82 | } else{
83 | bdm <- (sum(threeByThreeCTM[rownames(squaresTally),])
84 | + sum(log2(squaresTally$Freq)))
85 | }
86 |
87 | return(bdm)
88 | }
89 |
90 | # tests
91 | # set.seed(42)
92 | # m99 <- apply(matrix(0, 9, 9), c(1,2), function(x) sample(c(0,1),1))
93 | # m99
94 | #
95 | # testResult1 <- bdm2D(m88, 4, 4)
96 | # testResult1
97 | #
98 | #
99 | # testResult2 <- bdm2D(m99, 3, 3)
100 | # testResult2
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/scripts/BDM1D.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | library(acss)
4 |
5 | maxKnownKs <- read.csv("data/maxKnownKs.csv")
6 | maxKnownKs$X <- NULL
7 |
8 | ldData <- read.csv("data/logicalDepthsBinaryStrings.csv",
9 | colClasses = c('character',"numeric"))
10 |
11 | colnames(ldData) <- c('string','ld')
12 | logicalDepths <- data.frame(ldData$ld)
13 | rownames(logicalDepths) <- ldData$string
14 |
15 |
16 | countSymbols <- function(string){
17 | return(length(table(strsplit(string, NULL))))
18 | }
19 |
20 | number2binary <- function(number, noBits) {
21 |
22 | binary_vector = rev(as.numeric(intToBits(number)))
23 |
24 | if(missing(noBits)) {
25 |
26 | return(binary_vector)
27 | }
28 | else {
29 |
30 | binary_vector[-(1:(length(binary_vector) - noBits))]
31 | }
32 | }
33 |
34 | getBinString <-function(string) {
35 |
36 | string <- utf8ToInt(string)
37 |
38 | bitList <- lapply(string, number2binary, noBits=8)
39 |
40 | bitList2 <- lapply(bitList, paste0, collapse="")
41 |
42 | binString <- paste0(bitList2, collapse="")
43 |
44 | return (binString)
45 | }
46 |
47 | splitString <- function(string, blockSize, offset){
48 |
49 | if(blockSize > nchar(string)){
50 | return (string)
51 | }
52 |
53 | if(offset > blockSize){
54 | return ("ERROR: offset cannot be greater than blockSize.")
55 | }
56 |
57 | subs <- character()
58 | startIndices <- seq(1, nchar(string), offset)
59 |
60 | for(i in startIndices){
61 |
62 | first <- i
63 |
64 | last <- -1
65 |
66 | if (last > nchar(string)){
67 | last <- nchar(string) -1
68 | } else{
69 | last <- i + blockSize -1
70 | }
71 |
72 | sub <- substr(string, first, last)
73 | subs <- append(subs, sub)
74 |
75 | lastStep = FALSE
76 | if (nchar(sub) == blockSize && last == nchar(string)){
77 | lastStep = TRUE
78 | }
79 | if(lastStep)break
80 | }
81 | return (subs)
82 | }
83 |
84 | #receives the already splitted vector of input strings
85 | stringBDM <- function (stringsVector, base) {
86 |
87 | stringCounts <- as.data.frame(table(stringsVector))
88 |
89 | #complexities
90 |
91 | stringCounts["ks"] <- acss(as.vector(stringCounts[["stringsVector"]]), base)[, 1]
92 |
93 | naIndices <- as.integer(which(is.na(stringCounts$ks)))
94 |
95 | naStrings <- as.vector(stringCounts$stringsVector[naIndices])
96 |
97 | naLengths <- unlist(lapply(naStrings, nchar))
98 |
99 | # more complex (+1) than the highest known values
100 | naKs <- maxKnownKs[, paste0("K.", toString(base))] + 1
101 |
102 | stringCounts[is.na(stringCounts)] <- naKs
103 |
104 | bdm <- sum(log2(stringCounts$Freq)) + sum(stringCounts$ks)
105 |
106 | return(bdm)
107 |
108 | }
109 |
110 | #receives the already splitted vector of input strings
111 | stringBDMLD <- function (stringsVector, base) {
112 |
113 | stringCounts <- as.data.frame(table(stringsVector))
114 |
115 | #stringCounts
116 | sum(logicalDepths[as.character(stringCounts$stringsVector), ] * (log2(stringCounts$Freq)+1))
117 | }
118 |
119 | # ## should print 80.12 bits
120 | #testBDM <- stringBDM(c("000110100111","111001011000"),2)
121 | #testBDM
122 |
123 | # ## should print 1002 steps
124 | # testLD <- stringBDMLD(c("000110100111","111001011000"),2)
125 | # testLD
126 |
127 | # ##should print 31 * (log2(3) + 1) = 80.13 steps
128 | #testLD2 <- stringBDMLD(c("010101010101", "010101010101", "010101010101"),2)
129 | #testLD2
130 |
--------------------------------------------------------------------------------
/scripts/edgeAndVertexKnockout.R:
--------------------------------------------------------------------------------
1 |
2 | require("igraph")
3 | source("BDM2D.R")
4 |
5 |
6 | calculatePerturbationByVertexDeletion <- function(origGraph, blockSize, offset){
7 |
8 | origMatrix <- as.matrix(as_adjacency_matrix(origGraph))
9 |
10 | bdmOrig <- bdm2D(origMatrix,
11 | blockSize = blockSize,
12 | offset = offset)
13 |
14 | vertexPerturbationsDF <- as_data_frame(origGraph,
15 | what = "vertices")
16 |
17 | computedCols <- c("bdmValue",
18 | "bdmDifferenceAfterDeletion",
19 | "bdmIncrease")
20 |
21 | vertexPerturbationsDF[, computedCols] <- NA
22 |
23 | for(i in 1:nrow(vertexPerturbationsDF)){
24 |
25 | delMat <- as.matrix(as_adjacency_matrix(
26 | delete_vertices(origGraph,
27 | V(origGraph)[i])))
28 |
29 | bdmValueDel <- bdm2D(delMat,
30 | blockSize = blockSize,
31 | offset = offset)
32 |
33 | vertexPerturbationsDF[i, ]$bdmValue <- bdmValueDel
34 |
35 | bdmDiff <- bdmOrig - bdmValueDel
36 | vertexPerturbationsDF[i, ]$bdmDifferenceAfterDeletion <- bdmDiff
37 |
38 | bdmIncrease <- (bdmValueDel > bdmOrig)
39 | vertexPerturbationsDF[i, ]$bdmIncrease <- bdmIncrease
40 | }
41 |
42 | vertexPerturbationsDF$perturbationsRank <-rank(
43 | -as.numeric(vertexPerturbationsDF$bdmDifferenceAfterDeletion),
44 | ties.method="min")
45 |
46 |
47 | return (vertexPerturbationsDF)
48 | }
49 |
50 | calculatePerturbationByEdgeDeletion <- function(origGraph, blockSize, offset){
51 |
52 | origMatrix <- as.matrix(as_adjacency_matrix(origGraph))
53 |
54 | bdmOrig <- bdm2D(origMatrix, blockSize = blockSize, offset = offset)
55 |
56 | edgePerturbationsDF <- as_data_frame(origGraph, what = "edges")
57 |
58 | computedCols <- c("bdmValue",
59 | "bdmDifferenceAfterDeletion",
60 | "bdmIncrease")
61 |
62 | edgePerturbationsDF[, computedCols] <- NA
63 |
64 | for(i in 1:nrow(edgePerturbationsDF)){
65 |
66 | deletedEdgeGraph <- delete_edges(origGraph,
67 | paste0(edgePerturbationsDF[i, ]$from,
68 | "|",edgePerturbationsDF[i, ]$to))
69 |
70 | deletedEdgeAdjMatrix <- as.matrix(as_adjacency_matrix(deletedEdgeGraph))
71 |
72 | #added $bdmValue
73 | deletedEdgeBDM <- bdm2D(deletedEdgeAdjMatrix,
74 | blockSize = blockSize,
75 | offset = offset)
76 |
77 | edgePerturbationsDF[i, ]$bdmValue <- deletedEdgeBDM
78 |
79 | edgePerturbationsDF[i, ]$bdmDifferenceAfterDeletion <- (bdmOrig - deletedEdgeBDM)
80 |
81 | edgePerturbationsDF[i, ]$bdmIncrease <- (deletedEdgeBDM > bdmOrig)
82 |
83 | }
84 |
85 | edgePerturbationsDF$perturbationsRank <- rank(
86 | -as.numeric(edgePerturbationsDF$bdmDiff), ties.method ="min"
87 | )
88 |
89 | return(edgePerturbationsDF)
90 | }
91 |
92 |
93 |
94 | getColorRampPalette <- function(perturbationsDF){
95 | if(min(perturbationsDF$bdmDifferenceAfterDeletion) >= 0 ){
96 | pal <- colorRampPalette(c("light gray", "light blue"))
97 | } else if (max(perturbationsDF$bdmDifferenceAfterDeletion) < 0){
98 | pal <- colorRampPalette(c("orangered", "red"))
99 | } else {
100 | pal <- colorRampPalette(rev(c("red", "orangered", "light gray", "light blue")))
101 | }
102 | return(pal)
103 |
104 | }
105 |
106 | setGraphColors <- function(evaluatedGraph, vertexPerturbationsDF, edgePerturbationsDF){
107 |
108 | vertexPal <- getColorRampPalette(vertexPerturbationsDF)
109 | edgePal <- getColorRampPalette(edgePerturbationsDF)
110 |
111 | E(evaluatedGraph)$color <- edgePal(ecount(evaluatedGraph))[edgePerturbationsDF$perturbationsRank]
112 | V(evaluatedGraph)$color <- vertexPal(vcount(evaluatedGraph))[vertexPerturbationsDF$perturbationsRank]
113 |
114 | return(evaluatedGraph)
115 | }
116 |
117 | ########################
118 |
119 |
120 | ## test matrix
121 | # ro <- 5
122 | # co <- 5
123 | #
124 | # set.seed(3)
125 | # testMatrix <- apply(matrix(0, ro, co), c(1, 2), function(x) sample(c(0, 1), 1))
126 | #
127 | # testGraph <- graph_from_adjacency_matrix(testMatrix) %>%
128 | # set_vertex_attr("label", value = LETTERS[1: 5])
129 |
130 | # i <-1
131 | # td <- delete_vertices(testGraph, V(testGraph)[i])
132 | # plot(td)
133 | #######################################
134 | #
135 | #edgePerturbationsDF <- calculatePerturbationByEdgeDeletion(testGraph, 4, 1)
136 | #
137 | # vertexPal <- getColorRampPalette(vertexPerturbationsDF)
138 | # edgePal <- getColorRampPalette(edgePerturbationsDF)
139 | #
140 | # E(testGraph)$color <- edgePal(ecount(testGraph))[edgePerturbationsDF$perturbationsRank]
141 | # V(testGraph)$color <- vertexPal(vcount(testGraph))[vertexPerturbationsDF$perturbationsRank]
142 | #
143 | # plot(testGraph, vertex.label.family = "Arial Black", edge.arrow.size = .1, vertex.size = 25,
144 | # vertex.label.color="black")
145 | #
146 |
147 |
148 | ###############
149 | # edgePerturbationsDF <- calculatePerturbationByEdgeDeletion(testGraph, 4, 1)
150 | # print(edgePerturbationsDF)
151 |
152 | # vertexPerturbationsDF <- calculatePerturbationByVertexDeletion(testGraph, 4, 1)
153 | # print(vertexPerturbationsDF)
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/ui.R:
--------------------------------------------------------------------------------
1 | library(shiny)
2 |
3 | shinyUI(
4 | fluidPage(
5 |
6 | #titlePanel("The Online Algorithmic Complexity Calculator"),
7 |
8 | sidebarLayout(
9 |
10 | column(6,
11 | tabsetPanel(
12 | tabPanel("For any string",
13 |
14 | value = 1,
15 |
16 | h3("Block Decomposition Method for Strings"),
17 |
18 | div(wellPanel(
19 |
20 | textInput(inputId = "bdmInputString",
21 | label = "Enter a string",
22 | value ="010101010101010101010101010101010101",
23 | width ="800px"),
24 |
25 |
26 | sliderInput(inputId = "blockSize",
27 | label = "Block size",
28 | min = 2, max = 12, value = 12, step = 1),
29 |
30 | #max becomes the current value of blockSize -1
31 | #dynamically
32 | sliderInput(inputId = "blockOverlap",
33 | label = "Block overlap",
34 | min = 0, max = 11, value = 0, step = 1),
35 |
36 | radioButtons(inputId = "bdmAlphabet",
37 | label = "Alphabet size",
38 | inline = TRUE,
39 | choices = list("2" = 2,
40 | "4" = 4,
41 | "5" = 5,
42 | "6" = 6,
43 | "9" = 9,
44 | "256 (utf-8)" = 256),
45 | selected = 2),
46 |
47 | br(),
48 | actionButton("goButtonBDM1D", "Evaluate")
49 |
50 | ), style="font-size:115%")
51 |
52 | ),
53 |
54 | tabPanel("For binary arrays",
55 | value = 2,
56 | h3(
57 | "Block Decomposition Method for Unweighted Adjacency Matrices"),
58 | div(wellPanel(
59 | fileInput(inputId = 'file1',
60 | label = "Choose a CSV file",
61 | accept = c('text/comma-separated-values',
62 | 'text/plain',
63 | 'text/csv', '.csv')
64 | ),
65 |
66 | radioButtons(inputId = 'bdm2DBlockSize',
67 | label = 'Block size',
68 | choices = c('4 x 4' = 4,
69 | '3 x 3' = 3),
70 | selected = 4),
71 |
72 | sliderInput(inputId = 'bdm2DOverlap',
73 | label = "Block overlap (rows and columns)",
74 | min = 0,
75 | max = 3,
76 | step = 1,
77 | value = 0),
78 |
79 | actionButton("goButtonBDM2D", "Evaluate")
80 |
81 | ) #end wellPanel BDM 2D
82 | , style="font-size: 115%")
83 | ), #end tabPanel BDM 2D
84 |
85 | tabPanel("For short strings",
86 | value = 3,
87 | h3("Algorithmic Complexity for Short Strings"),
88 |
89 | div(wellPanel(
90 |
91 |
92 | textInput(inputId = "ctmInputStrings",
93 | label = "Strings to evaluate",
94 | value ="AAAAAAAAAAAA ATATATATATAT ATTGCCGGCCTA",
95 | width = "800px")
96 |
97 | ,
98 |
99 | p("Use space to separate strings."),
100 | p("The length of each string must be shorter than 13 characters."),
101 |
102 |
103 | radioButtons(inputId = "ctmAlphabet",
104 | label = "Alphabet size",
105 | inline = TRUE,
106 | choices = list("2" = 2,
107 | "4" = 4,
108 | "5" = 5,
109 | "6" = 6,
110 | "9" = 9),
111 | selected = 4),
112 |
113 | selectInput(#inputId="shortStringsEvalFunction", #"argument is not interpretable as logical" error
114 | inputId="funct",
115 | label = "Function used to evaluate the strings",
116 | choices = list("CTM Kolmogorov complexity estimated by algorithmic probability " = "acss",
117 | "Shannon entropy" = "entropy",
118 | "Second order entropy" = "entropy2",
119 | "Compression length by gzip"="compression-gzip",
120 | "Compression length by bzip2" = "compression-bzip2",
121 | "Compression length by xz" = "compression-xz",
122 | "Likelihood of production by Turing machines (deterministic process)" = "likelihood_d",
123 | "Likelihood of production by Turing machines (random process)" = "likelihood_ratio",
124 | "Conditional probability of random appearance" = "prob_random"
125 | ),
126 | selected = "acss"),
127 |
128 |
129 | actionButton("goButtonCTM", "Evaluate")
130 |
131 | )), # end wellPanel "For short strings",
132 | style="font-size:115%"), #end tabPanel "For short strings"
133 |
134 | tabPanel("Network perturbation",
135 | value = 4,
136 | h3("Perturbation Analysis of Unweighted Networks"),
137 | div(wellPanel(
138 |
139 | fileInput(inputId = "file2",
140 | label = "Choose a CSV file",
141 | accept = c('text/comma-separated-values',
142 | 'text/plain',
143 | 'text/csv',
144 | '.csv')
145 | ),
146 |
147 | selectInput(inputId = "vertexToDelete",
148 | label = "Node to delete",
149 | choices = ""), # choices filled in by server
150 |
151 | actionButton(inputId = "goButtonDeleteVertex",
152 | label = "Delete node"),
153 |
154 | span(textOutput(outputId = "cantDeleteVertex"),
155 | style = "color:red"),
156 |
157 | hr(),
158 |
159 | selectInput(inputId = "edgeToDelete",
160 | label = "Edge to delete",
161 | choices = ""), # choices filled in by server
162 |
163 | actionButton(inputId = "goButtonDeleteEdge",
164 | label = "Delete link"),
165 |
166 |
167 | span(textOutput(outputId = "cantDeleteLink"),
168 | style="color:red"),
169 |
170 | hr(),
171 |
172 | radioButtons(inputId = "printTable",
173 | label = h4("Perturbation Table"),
174 | choices = list("Nodes" = "vertices",
175 | "Links" = "edges"),
176 | selected = "vertices"),
177 |
178 | hr(),
179 |
180 | downloadButton('report', # name of downloadHandler in server
181 | 'Download report')
182 |
183 | )),
184 | style = "font-size:115%"), # end tabPanel "Network Perturbation"
185 |
186 | id = "conditionedPanels"
187 | )
188 | ),
189 |
190 | mainPanel(
191 | withMathJax(),
192 | conditionalPanel(condition="input.conditionedPanels==1",
193 |
194 | br(),
195 |
196 | h3("Result of Evaluation"),
197 |
198 | br(),
199 |
200 | div(p(textOutput("evaluatedString")),
201 | style="font-size:120%",
202 | align="center"),
203 |
204 | br(),
205 |
206 | div(tableOutput("resultBDMTable"),
207 | style="font-size : 120%;
208 | font-family: Arial, Helvetica, sans-serif;",
209 | align="center"),
210 |
211 | hr(),
212 |
213 | div(p("$$\\textit{BDM} =
214 | \\sum_{i=1}^{n} \\textit{K}(\\textit{block}_{i})
215 | +\\textit{log}_{2}(|\\textit{block}_{i}|)$$"),
216 | style="font-size: 120%",
217 | align="center"),
218 |
219 | hr(),
220 |
221 | div(p("Strings that don't appear in the
222 | \\(D(\\#\\textit{of states}, \\#\\textit{ of symbols})\\)
223 | distribution have their
224 | \\(\\textit{K}\\) value estimated as"),
225 | style="font-size:110%"),
226 |
227 | div(p("$$ \\textit{Max}(K(\\#\\textit{ of states}, \\#\\textit{ of symbols}))
228 | + 1 $$"),
229 | style="font-size:110%")
230 | ), ##end BDM 1D tab
231 |
232 | conditionalPanel(condition="input.conditionedPanels==2",
233 | br(),
234 |
235 | h3("Adjacency Matrix"),
236 |
237 | div(tableOutput("loadedGraph"), align="center", style="font-size: 110%"),
238 |
239 | br(),
240 | h3("Result of Evaluation"),
241 | div(tableOutput("resultBDM2DTable"), style="font-size: 120%", align="center"),
242 |
243 | hr(),
244 |
245 | div(p("$$BDM =
246 | \\sum_{i=1}^{n} K(block_{i})+log_{2}(|block_{i}|)$$"),
247 | style ="font-size: 120%")
248 | ), ##end BDM 2D tab
249 |
250 | conditionalPanel(condition ="input.conditionedPanels==3",
251 | br(),
252 | h3("Result of Evaluation"),
253 | br(),
254 | div(tableOutput("resultCTM"),
255 | style = "font-size: 120%",
256 | align = "center"),
257 | hr(),
258 |
259 | conditionalPanel(condition = "input.funct == 'acss'",
260 |
261 | div(p("$$K(\\#\\textit{ of states}, \\#\\textit{ of symbols}) =
262 | -log_{2}(D(\\#\\textit{of states}, \\textit{# of symbols})$$"),
263 | style = "font-size: 120%"),
264 |
265 | hr(),
266 |
267 | div(p("\\(\\textit{}~\\)\\(K(\\#\\textit{ of states}, \\#\\textit{ of symbols})\\)
268 | indicates the estimated Kolmogorov complexity of
269 | the string by the Coding Theorem Method."),
270 | style="font-size:110%"),
271 |
272 | hr(),
273 |
274 | div(p("\\(D(\\#\\textit{of states}, \\#\\textit{ of symbols})\\) indicates the
275 | estimated algorithmic probability,
276 | which is the output frequency of the string
277 | by Turing machines with the same alphabet."),
278 | style="font-size:110%"),
279 |
280 | hr(),
281 |
282 | div(p("Strings that don't appear in the
283 | \\(D(\\#\\textit{of states}, \\#\\textit{ of symbols})\\)
284 | distribution have their
285 | \\(\\textit{K}\\) value estimated as"),
286 | style="font-size:110%"),
287 |
288 | div(p("$$ \\textit{Max}(K(\\#\\textit{ of states}, \\#\\textit{ of symbols}))
289 | + 1 $$"),
290 | style="font-size:110%"),
291 | hr(),
292 |
293 | div(p("More information on the other complexity
294 | functions is available in the ",
295 | a(href="https://cran.r-project.org/web/packages/acss/acss.pdf",
296 | "documentation of the ACSS package @ CRAN.")),
297 | style="font-size:110%", align="center")
298 | )
299 |
300 | ), ## #end conditionalPanel CTM chosen
301 |
302 | conditionalPanel(condition ="input.conditionedPanels==4",
303 | br(),
304 | plotOutput("graphPlot"),
305 | tableOutput("perturbationTable")
306 | )
307 |
308 | ) ## end mainPanel
309 |
310 | )
311 | ))
--------------------------------------------------------------------------------
/data/K-3x3.csv:
--------------------------------------------------------------------------------
1 | 000000000,13.713356989265955
2 | 000000001,14.914491375110648
3 | 000000010,14.815062288419652
4 | 000000011,15.941579969636367
5 | 000000100,14.914491375110648
6 | 000000101,16.900030404099436
7 | 000000110,15.941579969636367
8 | 000000111,16.95562693976486
9 | 000001000,14.815062288419652
10 | 000001001,15.941579969636367
11 | 000001010,15.696612950809524
12 | 000001011,17.62373085163188
13 | 000001100,15.78735242844744
14 | 000001101,17.854607164922214
15 | 000001110,16.261880476627034
16 | 000001111,17.79099027006017
17 | 000010000,14.366394383270709
18 | 000010001,15.4100416811352
19 | 000010010,15.32169282402135
20 | 000010011,16.49512736777431
21 | 000010100,15.4100416811352
22 | 000010101,18.3368731060255
23 | 000010110,16.49512736777431
24 | 000010111,18.327674281086303
25 | 000011000,15.32169282402135
26 | 000011001,16.49512736777431
27 | 000011010,16.149904887374973
28 | 000011011,17.616157737686187
29 | 000011100,15.970999378598538
30 | 000011101,18.92890357141047
31 | 000011110,16.476306662461006
32 | 000011111,17.79099027006017
33 | 000100000,14.815062288419652
34 | 000100001,15.78735242844744
35 | 000100010,15.696612950809524
36 | 000100011,16.261880476627034
37 | 000100100,15.941579969636367
38 | 000100101,17.854607164922214
39 | 000100110,17.62373085163188
40 | 000100111,17.79099027006017
41 | 000101000,16.255262060168807
42 | 000101001,17.104691927835958
43 | 000101010,16.73365644982906
44 | 000101011,18.45555102314149
45 | 000101100,17.104691927835958
46 | 000101101,18.580864438414107
47 | 000101110,18.45555102314149
48 | 000101111,18.327674281086303
49 | 000110000,15.32169282402135
50 | 000110001,15.970999378598538
51 | 000110010,16.149904887374973
52 | 000110011,16.476306662461006
53 | 000110100,16.49512736777431
54 | 000110101,18.92890357141047
55 | 000110110,17.616157737686187
56 | 000110111,17.79099027006017
57 | 000111000,16.16173099207288
58 | 000111001,17.018774218181772
59 | 000111010,16.719591645677742
60 | 000111011,17.491110914380187
61 | 000111100,17.018774218181772
62 | 000111101,18.680113095310837
63 | 000111110,17.491110914380187
64 | 000111111,16.95562693976486
65 | 001000000,14.914491375110648
66 | 001000001,16.900030404099436
67 | 001000010,15.78735242844744
68 | 001000011,17.854607164922214
69 | 001000100,15.49045504078404
70 | 001000101,17.316632891027243
71 | 001000110,16.27316424670126
72 | 001000111,17.491110914380187
73 | 001001000,15.941579969636367
74 | 001001001,16.95562693976486
75 | 001001010,16.261880476627034
76 | 001001011,17.79099027006017
77 | 001001100,16.27316424670126
78 | 001001101,17.491110914380187
79 | 001001110,16.85323886184152
80 | 001001111,17.616157737686187
81 | 001010000,15.4100416811352
82 | 001010001,18.3368731060255
83 | 001010010,15.970999378598538
84 | 001010011,18.92890357141047
85 | 001010100,15.601133845368501
86 | 001010101,18.13105140995317
87 | 001010110,16.36182798445243
88 | 001010111,18.45555102314149
89 | 001011000,16.49512736777431
90 | 001011001,18.327674281086303
91 | 001011010,16.476306662461006
92 | 001011011,17.79099027006017
93 | 001011100,16.36182798445243
94 | 001011101,18.45555102314149
95 | 001011110,16.81279391621911
96 | 001011111,17.62373085163188
97 | 001100000,15.78735242844744
98 | 001100001,18.38286372231791
99 | 001100010,17.212914516396264
100 | 001100011,18.980868502975127
101 | 001100100,16.27316424670126
102 | 001100101,17.231501378198235
103 | 001100110,16.81279391621911
104 | 001100111,16.476306662461006
105 | 001101000,17.104691927835958
106 | 001101001,18.680113095310837
107 | 001101010,17.39355468629877
108 | 001101011,18.92890357141047
109 | 001101100,16.21735754583781
110 | 001101101,17.018774218181772
111 | 001101110,16.36182798445243
112 | 001101111,16.49512736777431
113 | 001110000,15.970999378598538
114 | 001110001,18.59627095161859
115 | 001110010,17.165765197608998
116 | 001110011,18.980868502975127
117 | 001110100,16.36182798445243
118 | 001110101,17.39355468629877
119 | 001110110,16.85323886184152
120 | 001110111,16.261880476627034
121 | 001111000,17.018774218181772
122 | 001111001,18.580864438414107
123 | 001111010,17.231501378198235
124 | 001111011,17.854607164922214
125 | 001111100,16.21735754583781
126 | 001111101,17.104691927835958
127 | 001111110,16.27316424670126
128 | 001111111,15.941579969636367
129 | 010000000,14.815062288419652
130 | 010000001,15.78735242844744
131 | 010000010,16.255262060168807
132 | 010000011,17.104691927835958
133 | 010000100,15.78735242844744
134 | 010000101,18.38286372231791
135 | 010000110,17.104691927835958
136 | 010000111,18.680113095310837
137 | 010001000,15.696612950809524
138 | 010001001,16.261880476627034
139 | 010001010,16.73365644982906
140 | 010001011,18.45555102314149
141 | 010001100,17.212914516396264
142 | 010001101,18.980868502975127
143 | 010001110,17.39355468629877
144 | 010001111,18.92890357141047
145 | 010010000,15.32169282402135
146 | 010010001,15.970999378598538
147 | 010010010,16.16173099207288
148 | 010010011,17.018774218181772
149 | 010010100,15.970999378598538
150 | 010010101,18.59627095161859
151 | 010010110,17.018774218181772
152 | 010010111,18.580864438414107
153 | 010011000,16.149904887374973
154 | 010011001,16.476306662461006
155 | 010011010,16.719591645677742
156 | 010011011,17.491110914380187
157 | 010011100,17.165765197608998
158 | 010011101,18.980868502975127
159 | 010011110,17.231501378198235
160 | 010011111,17.854607164922214
161 | 010100000,15.696612950809524
162 | 010100001,17.212914516396264
163 | 010100010,16.73365644982906
164 | 010100011,17.39355468629877
165 | 010100100,16.261880476627034
166 | 010100101,18.980868502975127
167 | 010100110,18.45555102314149
168 | 010100111,18.92890357141047
169 | 010101000,16.73365644982906
170 | 010101001,17.39355468629877
171 | 010101010,17.082165127627736
172 | 010101011,18.13105140995317
173 | 010101100,17.39355468629877
174 | 010101101,18.59627095161859
175 | 010101110,18.13105140995317
176 | 010101111,18.3368731060255
177 | 010110000,16.149904887374973
178 | 010110001,17.165765197608998
179 | 010110010,16.719591645677742
180 | 010110011,17.231501378198235
181 | 010110100,16.476306662461006
182 | 010110101,18.980868502975127
183 | 010110110,17.491110914380187
184 | 010110111,17.854607164922214
185 | 010111000,16.719591645677742
186 | 010111001,17.231501378198235
187 | 010111010,17.355908321894567
188 | 010111011,17.316632891027243
189 | 010111100,17.231501378198235
190 | 010111101,18.38286372231791
191 | 010111110,17.316632891027243
192 | 010111111,16.900030404099436
193 | 011000000,15.941579969636367
194 | 011000001,17.854607164922214
195 | 011000010,17.104691927835958
196 | 011000011,18.580864438414107
197 | 011000100,16.27316424670126
198 | 011000101,17.231501378198235
199 | 011000110,16.21735754583781
200 | 011000111,17.018774218181772
201 | 011001000,17.62373085163188
202 | 011001001,17.79099027006017
203 | 011001010,18.45555102314149
204 | 011001011,18.327674281086303
205 | 011001100,16.81279391621911
206 | 011001101,16.476306662461006
207 | 011001110,16.36182798445243
208 | 011001111,16.49512736777431
209 | 011010000,16.49512736777431
210 | 011010001,18.92890357141047
211 | 011010010,17.018774218181772
212 | 011010011,18.680113095310837
213 | 011010100,16.36182798445243
214 | 011010101,17.39355468629877
215 | 011010110,16.21735754583781
216 | 011010111,17.104691927835958
217 | 011011000,17.616157737686187
218 | 011011001,17.79099027006017
219 | 011011010,17.491110914380187
220 | 011011011,16.95562693976486
221 | 011011100,16.85323886184152
222 | 011011101,16.261880476627034
223 | 011011110,16.27316424670126
224 | 011011111,15.941579969636367
225 | 011100000,16.261880476627034
226 | 011100001,18.980868502975127
227 | 011100010,17.39355468629877
228 | 011100011,18.59627095161859
229 | 011100100,16.85323886184152
230 | 011100101,17.165765197608998
231 | 011100110,16.36182798445243
232 | 011100111,15.970999378598538
233 | 011101000,18.45555102314149
234 | 011101001,18.92890357141047
235 | 011101010,18.13105140995317
236 | 011101011,18.3368731060255
237 | 011101100,16.36182798445243
238 | 011101101,15.970999378598538
239 | 011101110,15.601133845368501
240 | 011101111,15.4100416811352
241 | 011110000,16.476306662461006
242 | 011110001,18.980868502975127
243 | 011110010,17.231501378198235
244 | 011110011,18.38286372231791
245 | 011110100,16.81279391621911
246 | 011110101,17.212914516396264
247 | 011110110,16.27316424670126
248 | 011110111,15.78735242844744
249 | 011111000,17.491110914380187
250 | 011111001,17.854607164922214
251 | 011111010,17.316632891027243
252 | 011111011,16.900030404099436
253 | 011111100,16.27316424670126
254 | 011111101,15.78735242844744
255 | 011111110,15.49045504078404
256 | 011111111,14.914491375110648
257 | 100000000,14.914491375110648
258 | 100000001,15.49045504078404
259 | 100000010,15.78735242844744
260 | 100000011,16.27316424670126
261 | 100000100,16.900030404099436
262 | 100000101,17.316632891027243
263 | 100000110,17.854607164922214
264 | 100000111,17.491110914380187
265 | 100001000,15.78735242844744
266 | 100001001,16.27316424670126
267 | 100001010,17.212914516396264
268 | 100001011,16.81279391621911
269 | 100001100,18.38286372231791
270 | 100001101,17.231501378198235
271 | 100001110,18.980868502975127
272 | 100001111,16.476306662461006
273 | 100010000,15.4100416811352
274 | 100010001,15.601133845368501
275 | 100010010,15.970999378598538
276 | 100010011,16.36182798445243
277 | 100010100,18.3368731060255
278 | 100010101,18.13105140995317
279 | 100010110,18.92890357141047
280 | 100010111,18.45555102314149
281 | 100011000,15.970999378598538
282 | 100011001,16.36182798445243
283 | 100011010,17.165765197608998
284 | 100011011,16.85323886184152
285 | 100011100,18.59627095161859
286 | 100011101,17.39355468629877
287 | 100011110,18.980868502975127
288 | 100011111,16.261880476627034
289 | 100100000,15.941579969636367
290 | 100100001,16.27316424670126
291 | 100100010,16.261880476627034
292 | 100100011,16.85323886184152
293 | 100100100,16.95562693976486
294 | 100100101,17.491110914380187
295 | 100100110,17.79099027006017
296 | 100100111,17.616157737686187
297 | 100101000,17.104691927835958
298 | 100101001,16.21735754583781
299 | 100101010,17.39355468629877
300 | 100101011,16.36182798445243
301 | 100101100,18.680113095310837
302 | 100101101,17.018774218181772
303 | 100101110,18.92890357141047
304 | 100101111,16.49512736777431
305 | 100110000,16.49512736777431
306 | 100110001,16.36182798445243
307 | 100110010,16.476306662461006
308 | 100110011,16.81279391621911
309 | 100110100,18.327674281086303
310 | 100110101,18.45555102314149
311 | 100110110,17.79099027006017
312 | 100110111,17.62373085163188
313 | 100111000,17.018774218181772
314 | 100111001,16.21735754583781
315 | 100111010,17.231501378198235
316 | 100111011,16.27316424670126
317 | 100111100,18.580864438414107
318 | 100111101,17.104691927835958
319 | 100111110,17.854607164922214
320 | 100111111,15.941579969636367
321 | 101000000,16.900030404099436
322 | 101000001,17.316632891027243
323 | 101000010,18.38286372231791
324 | 101000011,17.231501378198235
325 | 101000100,17.316632891027243
326 | 101000101,17.355908321894567
327 | 101000110,17.231501378198235
328 | 101000111,16.719591645677742
329 | 101001000,17.854607164922214
330 | 101001001,17.491110914380187
331 | 101001010,18.980868502975127
332 | 101001011,16.476306662461006
333 | 101001100,17.231501378198235
334 | 101001101,16.719591645677742
335 | 101001110,17.165765197608998
336 | 101001111,16.149904887374973
337 | 101010000,18.3368731060255
338 | 101010001,18.13105140995317
339 | 101010010,18.59627095161859
340 | 101010011,17.39355468629877
341 | 101010100,18.13105140995317
342 | 101010101,17.082165127627736
343 | 101010110,17.39355468629877
344 | 101010111,16.73365644982906
345 | 101011000,18.92890357141047
346 | 101011001,18.45555102314149
347 | 101011010,18.980868502975127
348 | 101011011,16.261880476627034
349 | 101011100,17.39355468629877
350 | 101011101,16.73365644982906
351 | 101011110,17.212914516396264
352 | 101011111,15.696612950809524
353 | 101100000,17.854607164922214
354 | 101100001,17.231501378198235
355 | 101100010,18.980868502975127
356 | 101100011,17.165765197608998
357 | 101100100,17.491110914380187
358 | 101100101,16.719591645677742
359 | 101100110,16.476306662461006
360 | 101100111,16.149904887374973
361 | 101101000,18.580864438414107
362 | 101101001,17.018774218181772
363 | 101101010,18.59627095161859
364 | 101101011,15.970999378598538
365 | 101101100,17.018774218181772
366 | 101101101,16.16173099207288
367 | 101101110,15.970999378598538
368 | 101101111,15.32169282402135
369 | 101110000,18.92890357141047
370 | 101110001,17.39355468629877
371 | 101110010,18.980868502975127
372 | 101110011,17.212914516396264
373 | 101110100,18.45555102314149
374 | 101110101,16.73365644982906
375 | 101110110,16.261880476627034
376 | 101110111,15.696612950809524
377 | 101111000,18.680113095310837
378 | 101111001,17.104691927835958
379 | 101111010,18.38286372231791
380 | 101111011,15.78735242844744
381 | 101111100,17.104691927835958
382 | 101111101,16.255262060168807
383 | 101111110,15.78735242844744
384 | 101111111,14.815062288419652
385 | 110000000,15.941579969636367
386 | 110000001,16.27316424670126
387 | 110000010,17.104691927835958
388 | 110000011,16.21735754583781
389 | 110000100,17.854607164922214
390 | 110000101,17.231501378198235
391 | 110000110,18.580864438414107
392 | 110000111,17.018774218181772
393 | 110001000,16.261880476627034
394 | 110001001,16.85323886184152
395 | 110001010,17.39355468629877
396 | 110001011,16.36182798445243
397 | 110001100,18.980868502975127
398 | 110001101,17.165765197608998
399 | 110001110,18.59627095161859
400 | 110001111,15.970999378598538
401 | 110010000,16.49512736777431
402 | 110010001,16.36182798445243
403 | 110010010,17.018774218181772
404 | 110010011,16.21735754583781
405 | 110010100,18.92890357141047
406 | 110010101,17.39355468629877
407 | 110010110,18.680113095310837
408 | 110010111,17.104691927835958
409 | 110011000,16.476306662461006
410 | 110011001,16.81279391621911
411 | 110011010,17.231501378198235
412 | 110011011,16.27316424670126
413 | 110011100,18.980868502975127
414 | 110011101,17.212914516396264
415 | 110011110,18.38286372231791
416 | 110011111,15.78735242844744
417 | 110100000,17.62373085163188
418 | 110100001,16.81279391621911
419 | 110100010,18.45555102314149
420 | 110100011,16.36182798445243
421 | 110100100,17.79099027006017
422 | 110100101,16.476306662461006
423 | 110100110,18.327674281086303
424 | 110100111,16.49512736777431
425 | 110101000,18.45555102314149
426 | 110101001,16.36182798445243
427 | 110101010,18.13105140995317
428 | 110101011,15.601133845368501
429 | 110101100,18.92890357141047
430 | 110101101,15.970999378598538
431 | 110101110,18.3368731060255
432 | 110101111,15.4100416811352
433 | 110110000,17.616157737686187
434 | 110110001,16.85323886184152
435 | 110110010,17.491110914380187
436 | 110110011,16.27316424670126
437 | 110110100,17.79099027006017
438 | 110110101,16.261880476627034
439 | 110110110,16.95562693976486
440 | 110110111,15.941579969636367
441 | 110111000,17.491110914380187
442 | 110111001,16.27316424670126
443 | 110111010,17.316632891027243
444 | 110111011,15.49045504078404
445 | 110111100,17.854607164922214
446 | 110111101,15.78735242844744
447 | 110111110,16.900030404099436
448 | 110111111,14.914491375110648
449 | 111000000,16.95562693976486
450 | 111000001,17.491110914380187
451 | 111000010,18.680113095310837
452 | 111000011,17.018774218181772
453 | 111000100,17.491110914380187
454 | 111000101,16.719591645677742
455 | 111000110,17.018774218181772
456 | 111000111,16.16173099207288
457 | 111001000,17.79099027006017
458 | 111001001,17.616157737686187
459 | 111001010,18.92890357141047
460 | 111001011,16.49512736777431
461 | 111001100,16.476306662461006
462 | 111001101,16.149904887374973
463 | 111001110,15.970999378598538
464 | 111001111,15.32169282402135
465 | 111010000,18.327674281086303
466 | 111010001,18.45555102314149
467 | 111010010,18.580864438414107
468 | 111010011,17.104691927835958
469 | 111010100,18.45555102314149
470 | 111010101,16.73365644982906
471 | 111010110,17.104691927835958
472 | 111010111,16.255262060168807
473 | 111011000,17.79099027006017
474 | 111011001,17.62373085163188
475 | 111011010,17.854607164922214
476 | 111011011,15.941579969636367
477 | 111011100,16.261880476627034
478 | 111011101,15.696612950809524
479 | 111011110,15.78735242844744
480 | 111011111,14.815062288419652
481 | 111100000,17.79099027006017
482 | 111100001,16.476306662461006
483 | 111100010,18.92890357141047
484 | 111100011,15.970999378598538
485 | 111100100,17.616157737686187
486 | 111100101,16.149904887374973
487 | 111100110,16.49512736777431
488 | 111100111,15.32169282402135
489 | 111101000,18.327674281086303
490 | 111101001,16.49512736777431
491 | 111101010,18.3368731060255
492 | 111101011,15.4100416811352
493 | 111101100,16.49512736777431
494 | 111101101,15.32169282402135
495 | 111101110,15.4100416811352
496 | 111101111,14.366394383270709
497 | 111110000,17.79099027006017
498 | 111110001,16.261880476627034
499 | 111110010,17.854607164922214
500 | 111110011,15.78735242844744
501 | 111110100,17.62373085163188
502 | 111110101,15.696612950809524
503 | 111110110,15.941579969636367
504 | 111110111,14.815062288419652
505 | 111111000,16.95562693976486
506 | 111111001,15.941579969636367
507 | 111111010,16.900030404099436
508 | 111111011,14.914491375110648
509 | 111111100,15.941579969636367
510 | 111111101,14.815062288419652
511 | 111111110,14.914491375110648
512 | 111111111,13.713356989265955
--------------------------------------------------------------------------------
/server.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | require("igraph")
4 |
5 | source("scripts/BDM1D.R")
6 | source("scripts/BDM2D.R")
7 | source("scripts/compressionLength.R")
8 | source("scripts/loadGraph.R")
9 | source("scripts/edgeAndVertexKnockout.R")
10 | source("scripts/relabelTables.R")
11 |
12 | source("scripts/listEdges.R")
13 |
14 |
15 |
16 | shinyServer(function(input, output, session) {
17 |
18 | #updates the slider for overlap in BDM 1D dynamically
19 | observeEvent(input$blockSize, {
20 | updateSliderInput(session,
21 | "blockOverlap",
22 | max=input$blockSize-1)
23 | })
24 |
25 |
26 | output$symbolCount <- renderText({
27 |
28 | input$goButton
29 |
30 | y <- isolate(
31 | paste0(
32 | 'The string has length ',
33 | nchar(input$bdmInputString),
34 | ' and contains ',
35 | countSymbols(input$bdmInputString),
36 | ' different symbols. \n It has Shannon entropy = ',
37 | entropy(input$bdmInputString),
38 | ' bit(s), and compressed length in bytes = ',
39 | compressionLength(input$bdmInputString, "gzip"),
40 | ' (using gzip)'))
41 | })
42 |
43 | ### CTM Tab
44 | output$resultCTM <- renderTable({
45 | input$goButtonCTM
46 | isolate({
47 |
48 | if(input$funct == "entropy"){
49 | strings <- unlist(strsplit(input$ctmInputStrings, " "))
50 | z <- lapply(strings, entropy)
51 | if (!is.matrix(z)) {
52 | z <- as.matrix(z)
53 | colnames(z) <- "Shannon entropy"
54 | rownames(z) <- strings
55 | }
56 | }
57 |
58 | else if(input$funct == "entropy2"){
59 |
60 | strings <- unlist(strsplit(input$ctmInputStrings, " "))
61 | z <- lapply(strings, entropy2)
62 | if (!is.matrix(z)) {
63 | z <- as.matrix(z)
64 | colnames(z) <- "Second order entropy"
65 | rownames(z) <- strings
66 | }
67 | }
68 |
69 | else if(input$funct == "compression-gzip"){
70 |
71 | strings <- unlist(strsplit(input$ctmInputStrings, " "))
72 |
73 | z <- lapply(strings,
74 | compressionLength,
75 | compressionType = "gzip")
76 |
77 | if (!is.matrix(z)) {
78 | z <- as.matrix(z)
79 | colnames(z) <- "Compression length (bytes)"
80 | rownames(z) <- strings
81 | }
82 |
83 | }
84 |
85 | else if(input$funct == "compression-bzip2"){
86 |
87 | strings <- unlist(strsplit(input$ctmInputStrings, " "))
88 |
89 | z <- lapply(strings,
90 | compressionLength,
91 | compressionType = "bzip2")
92 |
93 | if (!is.matrix(z)) {
94 | z <- as.matrix(z)
95 | colnames(z) <- "Compression length (bytes)"
96 | rownames(z) <- strings
97 | }
98 |
99 | }
100 |
101 | else if(input$funct == "compression-xz"){
102 |
103 | strings <- unlist(strsplit(input$ctmInputStrings, " "))
104 |
105 | z <- lapply(strings,
106 | compressionLength,
107 | compressionType = "xz")
108 |
109 | if (!is.matrix(z)) {
110 | z <- as.matrix(z)
111 | colnames(z) <- "Compression length (bytes)"
112 | rownames(z) <- strings
113 | }
114 |
115 | }
116 |
117 | #call acss's CTM
118 | else if(input$funct == "acss"){
119 |
120 | z <- do.call(acss,
121 | args = list(string = unlist(strsplit(input$ctmInputStrings, " ")),
122 | alphabet = as.numeric(input$ctmAlphabet)))
123 |
124 | if (input$ctmAlphabet == "2"){
125 | colnames(z) <- c("K(5, 2)", "D(5, 2)")
126 | }
127 | else if (input$ctmAlphabet == "4"){
128 | colnames(z) <- c("K(4, 4)", "D(4, 4)")
129 | }
130 | else if (input$ctmAlphabet == "5"){
131 | colnames(z) <- c("K(4, 5)", "D(4, 5)")
132 | }
133 | else if (input$ctmAlphabet == "6"){
134 | colnames(z) <- c("K(4, 6)", "D(4, 6)")
135 | }
136 | else if (input$ctmAlphabet == "9"){
137 | colnames(z) <- c("K(4, 9)", "D(4, 9)")
138 | }
139 |
140 |
141 | }
142 |
143 | #call likelihood of production
144 | else{
145 | z <- do.call(input$funct,
146 | args = list(string = unlist(strsplit(input$ctmInputStrings, " ")),
147 | alphabet = as.numeric(input$ctmAlphabet)))
148 | if (!is.matrix(z)){
149 | z <- as.matrix(z)
150 |
151 |
152 | colnames(z) <- paste0(input$funct, ": ",
153 | input$ctmAlphabet)
154 | }
155 | }
156 | })
157 | z
158 | }, rownames = TRUE, digits = 16)
159 |
160 | #### BDM 1D Tab
161 |
162 | output$evaluatedString <- renderText({
163 |
164 | input$goButtonBDM1D
165 | isolate({
166 | x <- paste0("Evaluated string = \"",
167 | input$bdmInputString, "\"")
168 | })
169 | x
170 | })
171 |
172 |
173 | #BDM 1D table of results
174 | output$resultBDMTable <- renderTable({
175 |
176 | input$goButtonBDM1D
177 | isolate({
178 |
179 | values <- c ()
180 |
181 | if (input$bdmAlphabet == 256){
182 |
183 | # convert UTF-8 string to binary
184 | binString <- getBinString(input$bdmInputString)
185 |
186 | values[1] <- paste0(
187 | sprintf("%.4f",stringBDM(
188 | splitString(binString,
189 | blockSize = input$blockSize,
190 | offset = input$blockSize -input$blockOverlap),
191 | base = 2)),
192 | " bits")
193 |
194 | values[2] <- paste0(
195 | sprintf("%.4f",stringBDMLD(
196 | splitString(binString,
197 | blockSize = input$blockSize,
198 | offset = (input$blockSize -input$blockOverlap)),
199 | base = input$bdmAlphabet)),
200 | " steps")
201 | }
202 | else {
203 | values[1] <- paste0(
204 | sprintf("%.4f",stringBDM(
205 | splitString(input$bdmInputString,
206 | blockSize = input$blockSize,
207 | offset = input$blockSize -input$blockOverlap),
208 | base = input$bdmAlphabet)),
209 | " bits")
210 | }
211 |
212 | if (input$bdmAlphabet == 2){
213 | values[2] <- paste0(
214 | sprintf("%.4f",stringBDMLD(
215 | splitString(input$bdmInputString,
216 | blockSize = input$blockSize,
217 | offset = input$blockSize -input$blockOverlap),
218 | base = input$bdmAlphabet)),
219 | " steps")
220 | }
221 | #entropy
222 | values[3] <- paste0(sprintf("%.4f",
223 | entropy(input$bdmInputString)),
224 | " bit(s)")
225 |
226 | #second order entropy
227 | values[4] <- paste0(sprintf("%.4f",
228 | entropy2(input$bdmInputString)),
229 | " bit(s)")
230 |
231 | #compression length
232 | values[5] <- paste0(compressionLength(input$bdmInputString,
233 | "gzip") * 8,
234 | " bits")
235 |
236 | values[6] <- nchar(input$bdmInputString)
237 | values[7] <- countSymbols(input$bdmInputString)
238 | values[8] <- input$bdmAlphabet
239 | values[9] <- input$blockSize
240 | values[10] <- input$blockOverlap
241 |
242 |
243 |
244 | resultRowNames <- c("BDM algorithmic complexity estimation",
245 | "BDM logical depth estimation",
246 | "Shannon entropy",
247 | "Second order entropy",
248 | "Compression length (using gzip)",
249 | "String length",
250 | "# of symbols in string",
251 | "# of symbols in CTM alphabet",
252 | "Block size",
253 | "Block overlap")
254 |
255 | if (!(input$bdmAlphabet == 2 || input$bdmAlphabet == 256))
256 | {
257 | values <- values[-2]
258 | resultRowNames <- resultRowNames[-2]
259 | }
260 |
261 | result <- data.frame(values)
262 | rownames(result) <- resultRowNames
263 |
264 |
265 | })
266 | result},
267 | rownames = TRUE, colnames = FALSE)
268 |
269 |
270 | ##### BDM 2D Tab
271 | loadedGraph <- reactive({
272 |
273 | inFile <- input$file1
274 | if(input$goButtonBDM2D == 0 || is.null(inFile$datapath)){
275 | graph <- loadGraph("data/m88.csv", sep = ",", quote = '"' )
276 | return (graph)
277 | }
278 |
279 | graph <- loadGraph(inFile$datapath,
280 | sep = ",",
281 | quote = '"')
282 |
283 | graph
284 | })
285 |
286 | #render adjacency matrix as a dataframe
287 | output$loadedGraph <- renderTable({
288 |
289 | loadedGraph()
290 |
291 | })
292 |
293 | output$resultBDM2DTable <- renderTable({
294 |
295 | input$goButtonBDM2D
296 | isolate({
297 |
298 | #BDM2D
299 | values <- c ()
300 |
301 | values[1] <- paste0(
302 |
303 | sprintf("%.4f",
304 | bdm2D(loadedGraph(),
305 | blockSize = as.numeric(input$bdm2DBlockSize),
306 | offset = (as.numeric(input$bdm2DBlockSize) -
307 | as.numeric(input$bdm2DOverlap)) )),
308 | " bits")
309 |
310 | # Shannon entropy
311 | values[2] <- paste0(sprintf("%.4f",
312 | entropy(toString(loadedGraph()))[[1]]),
313 | " bit(s)")
314 |
315 | # Block entropy
316 | values[3] <- paste0(
317 |
318 | sprintf("%.4f", blockEntropy(loadedGraph(),
319 | blockSize = as.numeric(input$bdm2DBlockSize),
320 | offset = (as.numeric(input$bdm2DBlockSize) -
321 | as.numeric(input$bdm2DOverlap)) )),
322 | " bits")
323 |
324 | # compression length
325 | values[4] <- paste0(compressionLength(toString(loadedGraph()), "gzip") * 8,
326 | " bits")
327 |
328 | # matrix dimensions
329 | values[5] <- paste0(nrow(loadedGraph()), " x ", ncol(loadedGraph()))
330 |
331 |
332 | #2D block size
333 | values[6] <- paste0(input$bdm2DBlockSize, " x ", input$bdm2DBlockSize)
334 |
335 | #2D block overlap
336 | values[7] <- input$bdm2DOverlap
337 |
338 | result <- data.frame(values)
339 |
340 | rownames(result) <- c("BDM algorithmic complexity estimation",
341 | "Shannon entropy",
342 | "Block entropy",
343 | "Compression length (using gzip)",
344 | "Matrix dimensions",
345 | "Block size",
346 | "Block overlap (both rows and columns)")
347 |
348 |
349 | })
350 | result}, rownames = TRUE, colnames = FALSE)
351 |
352 |
353 | output$resultBDM2D <- renderText({
354 |
355 | input$goButtonBDM2D
356 | isolate({
357 |
358 | if(input$bdm2DOverlap >= input$bdm2DBlockSize){
359 | x <- "The maximum possible overlap is block size - 1."
360 | }
361 | else{
362 | x <- paste0('BDM of the evaluated adjacency matrix considering ',
363 | input$bdm2DBlockSize, ' x ',
364 | input$bdm2DBlockSize,
365 | " blocks, with overlap of ",
366 | input$bdm2DOverlap,
367 | ' rows and ',
368 | input$bdm2DOverlap,
369 | ' columns is \n',
370 | bdm2D(loadedGraph(),
371 | blockSize = as.numeric(input$bdm2DBlockSize),
372 | offset = (as.numeric(input$bdm2DBlockSize) -
373 | as.numeric(input$bdm2DOverlap)) ),
374 |
375 | ' bit(s).'
376 | )
377 | }
378 | x
379 | })
380 | })
381 |
382 | output$result2DEntropyAndCompLength <- renderText({
383 |
384 | input$goButtonBDM2D
385 | isolate({
386 |
387 |
388 |
389 | x <- paste0("The Shannon entropy of the adjacency matrix is ",
390 | entropy(toString(loadedGraph()))[[1]],
391 | " bit(s), and its compressed length is ",
392 | compressionLength(toString(loadedGraph()), "gzip"),
393 | ' bytes (using gzip).'
394 | )
395 |
396 | x
397 | })
398 |
399 | })
400 |
401 | ###### Perturbation Analysis Tab
402 |
403 | #runs once, when server starts
404 | g <- loadGraphPA("./data/m88.csv")
405 | pv <- calculatePerturbationByVertexDeletion(g, 4, 1)
406 | pe <- calculatePerturbationByEdgeDeletion(g, 4, 1)
407 | g <- setGraphColors(g, pv, pe)
408 |
409 | #all of these must be cleared and updated when a new graph is loaded
410 |
411 | sizeOfHistory <- vcount(g) + ecount(g)
412 |
413 | graphHistory <- list()
414 |
415 | pvHistory <- list()
416 |
417 | peHistory <- list()
418 |
419 | delEventHistory <- vector("list", sizeOfHistory)
420 |
421 | graphHistory[[1]] <- g
422 | pvHistory[[1]] <- relabelVertexTable(pv)
423 | peHistory[[1]] <- relabelEdgeTable(pe)
424 | delEventHistory[[1]] <- "Initial state of the network"
425 |
426 | #starts with 1 even though the network hasn't been changed at the start
427 | perturbationCounter <- as.integer(1)
428 |
429 | my <- reactiveValues(g = g,
430 | pv = pv,
431 | pe = pe,
432 | perturbationCounter = perturbationCounter,
433 | sizeOfHistory = sizeOfHistory,
434 | graphHistory = graphHistory,
435 | pvHistory = pvHistory,
436 | peHistory = peHistory,
437 | delEventHistory = delEventHistory)
438 |
439 | observe({
440 |
441 | updateSelectInput(session, "vertexToDelete",
442 | choices = V(my$g)$label)
443 |
444 | updateSelectInput(session, "edgeToDelete",
445 | choices = listEdges(my$g))
446 |
447 | })
448 |
449 | observeEvent(input$file2, {
450 |
451 | inFile <- input$file2
452 |
453 | if (is.null(inFile$datapath)){
454 |
455 |
456 | } else {
457 |
458 | g <- loadGraphPA(inFile$datapath)
459 | my$pv <- calculatePerturbationByVertexDeletion(g, 4, 1)
460 | my$pe <- calculatePerturbationByEdgeDeletion(g, 4, 1)
461 | my$g <- setGraphColors(g, my$pv, my$pe)
462 |
463 | my$sizeOfHistory <- vcount(my$g) + ecount(my$g)
464 |
465 | my$perturbationCounter <- as.integer(1)
466 |
467 | #todo: check if this vector("list", my$sizeOfHistory) works with list() in Report.Rmd
468 | graphHistory <- vector("list", my$sizeOfHistory)
469 | ptHistory <- vector("list", my$sizeOfHistory)
470 | pvHistory <- vector("list", my$sizeOfHistory)
471 | delEventHistory <- vector("list", my$sizeOfHistory)
472 |
473 | }
474 |
475 | }, ignoreInit = FALSE)
476 | # ignoreInit = FALSE is default behavior
477 | # these initializations run when the server is first set up
478 |
479 | observeEvent(input$goButtonDeleteVertex, {
480 |
481 | if(vcount(my$g) > 5){
482 |
483 | my$perturbationCounter <- my$perturbationCounter + 1
484 |
485 |
486 |
487 | my$g <- delete_vertices(my$g,
488 | input$vertexToDelete)
489 |
490 | my$pv <- calculatePerturbationByVertexDeletion(my$g, 4, 1)
491 | my$pe <- calculatePerturbationByEdgeDeletion(my$g, 4, 1)
492 |
493 | my$g <- setGraphColors(my$g, my$pv, my$pe)
494 |
495 | my$graphHistory[[my$perturbationCounter]] <- my$g
496 | my$pvHistory[[my$perturbationCounter]] <- relabelVertexTable(my$pv)
497 | my$peHistory[[my$perturbationCounter]] <- relabelEdgeTable(my$pe)
498 |
499 | my$delEventHistory[[my$perturbationCounter]] <- paste0("Deletion of node ",
500 | input$vertexToDelete)
501 |
502 |
503 | }
504 |
505 | else {
506 |
507 | output$cantDeleteVertex <- renderText({
508 |
509 | "can't delete more nodes"
510 |
511 | })
512 |
513 | }
514 |
515 | })
516 |
517 | observeEvent (input$goButtonDeleteEdge, {
518 |
519 | if(ecount(my$g) > 1){
520 |
521 | my$g <- delete_edges(my$g,
522 | input$edgeToDelete)
523 |
524 | my$pv <- calculatePerturbationByVertexDeletion(my$g, 4, 1)
525 | my$pe <- calculatePerturbationByEdgeDeletion(my$g, 4, 1)
526 |
527 | my$g <- setGraphColors(my$g, my$pv, my$pe)
528 |
529 | my$perturbationCounter <- my$perturbationCounter + 1
530 |
531 | my$graphHistory[[my$perturbationCounter]] <- my$g
532 | my$pvHistory[[my$perturbationCounter]] <- relabelVertexTable(my$pv)
533 | my$peHistory[[my$perturbationCounter]] <- relabelEdgeTable(my$pe)
534 |
535 |
536 | my$delEventHistory[[my$perturbationCounter]] <- paste0("Deletion of link ",
537 | input$edgeToDelete)
538 |
539 | } else {
540 |
541 | output$cantDeleteLink <- renderText("can't delete more links")
542 |
543 | }
544 |
545 | })
546 |
547 | output$graphPlot <- renderPlot({
548 |
549 | coords <- layout_(my$g, as_star())
550 |
551 | plot(my$g,
552 | layout = coords,
553 | edge.arrow.size = 0.4,
554 | vertex.size = 25,
555 | vertex.label.family = "Arial Black")
556 |
557 | })
558 |
559 | output$perturbationTable <- renderTable ({
560 |
561 | if(input$printTable == "edges"){
562 | edgeTable <- relabelEdgeTable(my$pe)
563 | return(edgeTable)
564 | }
565 | else {
566 |
567 | vertexTable <- relabelVertexTable(my$pv)
568 |
569 | return(vertexTable)
570 |
571 | }
572 |
573 | }, digits = 3)
574 |
575 |
576 | ### downloadHandler for HTML report
577 |
578 | output$report <- downloadHandler (
579 |
580 | filename = "report.html",
581 |
582 | content = function(file){
583 |
584 | tempReport <- file.path(tempdir(),
585 | "report.Rmd")
586 |
587 | file.copy("report.Rmd", tempReport,
588 | overwrite = TRUE)
589 |
590 | printG <- my$g
591 |
592 | printVT <- relabelVertexTable(my$pv)
593 |
594 | printET <- relabelEdgeTable(my$pe)
595 |
596 |
597 | params <- list(graphHistory = my$graphHistory,
598 | pvHistory = my$pvHistory,
599 | peHistory = my$peHistory,
600 | perturbationCounter = my$perturbationCounter,
601 | delEventHistory = my$delEventHistory)
602 |
603 | rmarkdown::render(tempReport,
604 | output_file = file,
605 | params = params,
606 | envir = new.env(globalenv()))
607 |
608 | }
609 |
610 | )
611 |
612 | })#end shinyServer function
613 |
614 |
615 |
616 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------