Transformed Latin hypercube with a multivariate distribution
Source:R/correlatedLHS.R
correlatedLHS.RdA method to create a transformed Latin Hypercube sample where the marginal distributions can be correlated according to an arbitrary set of criteria contained in a minimized cost function
Usage
correlatedLHS(
lhs,
marginal_transform_function,
cost_function,
debug = FALSE,
maxiter = 10000,
...
)Arguments
- lhs
a Latin hypercube sample that is uniformly distributed on the margins
- marginal_transform_function
a function that takes Latin hypercube sample as the first argument and other passed-through variables as desired.
...must be passed as a argument. For example,f <- function(W, second_argument, ...). Must return amatrixordata.frame- cost_function
a function that takes a transformed Latin hypercube sample as the first argument and other passed-through variables as desired.
...must be passed as a argument. For example,f <- function(W, second_argument, ...)- debug
Should debug messages be printed. Causes cost function output and iterations to be printed to aid in setting the maximum number of iterations
- maxiter
the maximum number of iterations. The algorithm proceeds by swapping one variable of two points at a time. Each swap is an iteration.
- ...
Additional arguments to be passed through to the
marginal_transform_functionandcost_function
Value
a list of the Latin hypercube with uniform margins, the transformed Latin hypercube, and the final cost
Examples
correlatedLHS(lhs::randomLHS(30, 2),
marginal_transform_function = function(W, ...) {
W[,1] <- qnorm(W[,1], 1, 3)
W[,2] <- qexp(W[,2], 2)
return(W)
},
cost_function = function(W, ...) {
(cor(W[,1], W[,2]) - 0.5)^2
},
debug = FALSE,
maxiter = 1000)
#> $lhs
#> [,1] [,2]
#> [1,] 0.83462142 0.147851035
#> [2,] 0.27611532 0.744146201
#> [3,] 0.67347321 0.664861771
#> [4,] 0.23669230 0.304115703
#> [5,] 0.90406059 0.731676831
#> [6,] 0.72657202 0.599819942
#> [7,] 0.50930521 0.783232206
#> [8,] 0.19719914 0.078566236
#> [9,] 0.36230528 0.470914447
#> [10,] 0.79807869 0.673988554
#> [11,] 0.04394819 0.382871180
#> [12,] 0.97752273 0.975051523
#> [13,] 0.60433207 0.804457963
#> [14,] 0.83278784 0.865407428
#> [15,] 0.44743490 0.524809241
#> [16,] 0.88271250 0.197143897
#> [17,] 0.15446998 0.130272305
#> [18,] 0.11886556 0.454391427
#> [19,] 0.02091592 0.283424994
#> [20,] 0.41992478 0.905168732
#> [21,] 0.49500883 0.057110052
#> [22,] 0.75256042 0.358053340
#> [23,] 0.95252926 0.966026217
#> [24,] 0.08225974 0.214634735
#> [25,] 0.23293891 0.869405269
#> [26,] 0.56662469 0.007822042
#> [27,] 0.58517089 0.553396585
#> [28,] 0.39710293 0.412519979
#> [29,] 0.30761999 0.614314799
#> [30,] 0.65010851 0.247750247
#>
#> $transformed_lhs
#> [,1] [,2]
#> [1,] 3.91776975 0.079996963
#> [2,] -0.78326269 0.681574547
#> [3,] 2.34857250 0.546606104
#> [4,] -1.15094892 0.181285936
#> [5,] 4.91512363 0.657781586
#> [6,] 2.80743415 0.457920343
#> [7,] 1.06998043 0.764464286
#> [8,] -1.55500457 0.040912191
#> [9,] -0.05691094 0.318302567
#> [10,] 3.50433451 0.560411394
#> [11,] -4.11980061 0.241338746
#> [12,] 7.01523879 1.845471258
#> [13,] 1.79372899 0.815989951
#> [14,] 3.89572174 1.002751523
#> [15,] 0.60356575 0.372019478
#> [16,] 4.56596844 0.109789890
#> [17,] -2.05234652 0.069787555
#> [18,] -2.54203055 0.302926730
#> [19,] -5.10556741 0.166636177
#> [20,] 0.39374223 1.177828048
#> [21,] 0.96246600 0.029402854
#> [22,] 3.04770737 0.221625031
#> [23,] 6.00966466 1.691083068
#> [24,] -3.17009275 0.120803182
#> [25,] -1.18760736 1.017828203
#> [26,] 1.50336190 0.003926397
#> [27,] 1.64541978 0.403042146
#> [28,] 0.21744092 0.265956520
#> [29,] -0.50782368 0.476366892
#> [30,] 2.15684028 0.142343446
#>
#> $cost
#> [1] 2.681008e-08
#>