R/helper-functions-scaling.R

Defines functions decode_orthogonal encode_orthogonal

# Encode using the orthogonal convention
#
# @param Xi numeric matrix of shape (N, k); Xi specifies the points in
#           original units
# @inheritParams GloptiPolyRegion
# @return numeric matrix of shape (N, k); it specifies the points in the
#         (-1, 1) coded units
encode_orthogonal <- function(Xi, lb, ub) {
  Xi <- t(Xi) # put data in columns for vectorized implementation
  M <- (lb + ub) / 2
  dim(M) <- c(nrow(Xi), 1)
  res <- sweep(Xi, 1, M, "-")
  R <- ub - lb
  S <- diag(R) / 2
  res <- solve(S, res)
  # return
  t(res)
}
# Decode using the orthogonal convention
#
# @param X numeric matrix of shape (N, k); X specifies the points in
#          original units
# @inheritParams GloptiPolyRegion
# @return numeric matrix of shape (N, k); res specifies the points in
#         original units
decode_orthogonal <- function(X, lb, ub) {
  X <- t(X)
  M <- (lb + ub) / 2
  dim(M) <- c(nrow(X), 1)
  R <- ub - lb
  S <- diag(R) / 2
  res <- S %*% X
  res <- sweep(res, 1, M, "+")
  # return
  t(res)
}

Try the OptimaRegion package in your browser

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

OptimaRegion documentation built on March 7, 2023, 6:22 p.m.