PageRenderTime 394ms CodeModel.GetById 192ms app.highlight 2ms RepoModel.GetById 199ms app.codeStats 0ms

/fingerprint/R/bitspec.R

http://github.com/rajarshi/cdkr
R | 22 lines | 20 code | 2 blank | 0 comment | 10 complexity | 0c94477e5334b69df55f95f0e5b86afc MD5 | raw file
 1bit.spectrum <- function(fplist) {
 2  if (class(fplist) != 'list') stop("Must provide a list of fingerprint objects")
 3  if (any(unlist(lapply(fplist, class)) != 'fingerprint'))
 4    stop("Must provide a list of fingerprint objects");
 5  nbit <- length(fplist[[1]])
 6  spec <- numeric(nbit)
 7  for (i in 1:length(fplist)) {
 8    bits <- fplist[[i]]@bits
 9    spec[bits] <- spec[bits]+1
10  }
11  spec / length(fplist)
12}
13
14shannon <- function(fplist) {
15  if (class(fplist) != 'list') stop("Must provide a list of fingerprint objects")
16  if (any(unlist(lapply(fplist, class)) != 'fingerprint'))
17    stop("Must provide a list of fingerprint objects");
18
19  bs <- bit.spectrum(fplist)
20  bs <- bs[ bs != 0 ]
21  -1 * sum( bs * log2(bs) )
22}