R/encodepop.R

Defines functions encodepop

Documented in encodepop

# Binary encoding of real number matrix
encodepop = function(x, lb, ub, eps, ...){
  n = nrow(x)
  if(missing(lb)) stop("lb, a lower boundary should be given.")
  if(missing(ub)) stop("ub, a upper boundary should be given.")
  if(missing(eps)) eps=0.1
  v = length(lb)
  if(length(eps)==1) eps = rep(eps, v)
  m = floor(log((ub-lb)/eps,2)+1)
  M = sum(m)
  binmat = matrix(NA, nrow=n, ncol=M)
  for(i in 1:n){
    binvec = c()
    for(j in 1:v){
      vbin = encode(x[i,j], lb[j], ub[j], m[j])
      binvec = c(binvec, vbin)
    }
    binmat[i,] = binvec
  }
  return(list(binmat=binmat, m=m))
}

Try the adana package in your browser

Any scripts or data that you put into this service are public.

adana documentation built on March 18, 2022, 6:03 p.m.