R に N x K 行列があり、各行は観測値であり、各列は固定の下限と上限を持つ変数です。
私の行列は、最初は 0 から 1 の間の値で設定されています。この行列を非正規化する最良の方法は何ですか? 私は次の機能を使用しています:
denormalizeMult = function(m, lb, ub)
{
nobs = nrow(m)
nvars = ncol(m)
lbDiag = diag(lb, ncol = nvars)
rangeM = diag(ub - lb, ncol = nvars)
m%*%rangeM + matrix(rep(lb, nobs), nrow = nobs, byrow = TRUE)
}
# Example:
# 3 variables, 9 observations
x = matrix(runif(3*9), ncol = 3)
# to denormalize a variable xi, just do lb[i] + (ub[i] - lb[i])*xi
# ranges for each variable
lb = c(-1,-2,-3)
ub = c(1,2,3)
最初の変数の範囲は -1 から 1、2 番目の変数の範囲は -2 から 2 などです... 別の解決策は次のとおりです。
denormalize2 = function(population)
{
r = nrow(population)
c = ncol(population)
decm = matrix(rep(0, r*c), r, c)
for(i in 1:r)
decm[i,] = lb + (ub - lb) * population[i,]
decm
}
これを達成するための簡単な(そしてより速い)方法はありますか?ありがとう!
編集:以下の回答の結果: