-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentropy.r
executable file
·82 lines (74 loc) · 2.8 KB
/
entropy.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env Rscript
##
##
## This source code is part of
##
## M D S C T K
##
## Molecular Dynamics Spectral Clustering ToolKit
##
## VERSION 1.2.5
## Written by Joshua L. Phillips.
## Copyright (c) 2012-2016, Joshua L. Phillips.
## Check out http://www.cs.mtsu.edu/~jphillips/software.html for more
## information.
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## If you want to redistribute modifications, please consider that
## derived work must not be called official MDSCTK. Details are found
## in the README & LICENSE files - if they are missing, get the
## official version at github.com/jlphillipsphd/mdsctk/.
##
## To help us fund MDSCTK development, we humbly ask that you cite
## the papers on the package - you can find them in the top README file.
##
## For more info, check our website at
## http://www.cs.mtsu.edu/~jphillips/software.html
##
##
if (Sys.getenv("MDSCTK_HOME")=="") {
cat("\n")
cat("Please set the MDSCTK_HOME environment variable\n")
cat("before running this script.\n")
cat("\n")
q()
} else {
program.name <- "entropy.r"
source(paste(Sys.getenv("MDSCTK_HOME"),"/mdsctk.r",sep=""))
}
cat(" Computes the local entropy of the given sparse\n")
cat(" matrix with indices from indices.dat and the densities\n")
cat(" in density.dat. The number of nearest neighbors,\n")
cat(" k, is required.\n")
cat("\n")
cat(" Use -h or --help to see the complete list of options.\n")
cat("\n")
parser$add_argument("-k","--knn",type="integer",
help="Number of k-nearest neighbors",metavar="integer")
parser$add_argument("-i","--indices",default="indices.dat",
help="K-nn indices file [default %(default)s]")
parser$add_argument("-d","--densities",default="density.dat",
help="Density file [default %(default)s]")
parser$add_argument("-o","--output",default="entropy.dat",
help="(Output) Entropy file [default %(default)s]")
myargs <- parser$parse_args()
if (is.null(myargs$knn)) {
cat("ERROR: --knn not supplied.\n")
cat("\n")
q()
}
cat("Running with the following options:\n")
cat(paste("knn = ",myargs$knn,"\n"))
cat(paste("indices = ",myargs$indices,"\n"))
cat(paste("densities = ",myargs$densities,"\n"))
cat(paste("output = ",myargs$output,"\n"))
cat("\n")
myindexfile <- myargs$indices
mydensfile <- myargs$densities
myk <- myargs$knn
dens <- scan(mydensfile,quiet=TRUE)
write(entropy.pointwise(matrix(read.binary.int(myindexfile,length(dens)*myk)+1,ncol=myk,byrow=TRUE),dens),file=myargs$output,ncolumns=1)