R/zonotope_approximation.R

Defines functions zonotope_approximation

Documented in zonotope_approximation

#' A function to over-approximate a zonotope with PCA method and to evaluate the approximation by computing a ratio of fitness.
#' 
#' For the evaluation of the PCA method the exact volume of the approximation body is computed and the volume of the input zonotope is computed by CoolingBodies algorithm. The ratio of fitness is \eqn{R=vol(P) / vol(P_{red})}, where \eqn{P_{red}} is the approximate polytope.
#' 
#' @param Z A zonotope.
#' @param fit_ratio Optional. A boolean parameter to request the computation of the ratio of fitness.
#' @param settings Optional. A list that declares the values of the parameters of CB algorithm as follows:
#' \itemize{
#' \item{\code{error} }{ A numeric value to set the upper bound for the approximation error. The default value is \eqn{0.1}.}
#' \item{\code{walk_length} }{ An integer to set the number of the steps for the random walk. The default value is \eqn{1}.}
#' \item{\code{win_len} }{ The length of the sliding window for CB algorithm. The default value is \eqn{250}.}
#' \item{\code{hpoly} }{ A boolean parameter to use H-polytopes in MMC of CB algorithm. The default value is \code{TRUE} when the order of the zonotope is \eqn{<5}, otherwise it is \code{FALSE}.}
#' \item{\code{seed} }{ Optional. A fixed seed for the number generator.}
#' }
#' 
#' @return A list that contains the approximation body in H-representation and the ratio of fitness
#' 
#' @references \cite{A.K. Kopetzki and B. Schurmann and M. Althoff,
#' \dQuote{Methods for Order Reduction of Zonotopes,} \emph{IEEE Conference on Decision and Control,} 2017.}
#' 
#' @examples
#' # over-approximate a 2-dimensional zonotope with 10 generators and compute the ratio of fitness
#' Z = gen_rand_zonotope(2, 8)
#' retList = zonotope_approximation(Z = Z)
#' 
#' @export
zonotope_approximation <- function(Z, fit_ratio = FALSE, settings = list('error' = 0.1, 'walk_length' = 1, 'win_len' = 250, 'hpoly' = FALSE)){
  
  seed = NULL
  if (!is.null(settings$seed)) {
    seed = settings$seed
  }
  
  ret_list = zono_approx(Z, fit_ratio, settings, seed)
  
  Mat = ret_list$Mat
  
  # first column is the vector b
  b = Mat[, 1]
  
  # remove first column
  A = Mat[, -c(1), drop = FALSE]
  PP = list("P" = Hpolytope(A = A, b = b), "fit_ratio" = ret_list$fit_ratio)
  
  return(PP)
  
}

Try the volesti package in your browser

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

volesti documentation built on July 14, 2021, 5:11 p.m.