# Latin hypercube sampling for both float and integers

I am using Latin hypercube sampling to generate the combinations of 5 parameters. In these 5 parameters, the values of two parameters can be float numbers, while the values of three parameters must be integers in [0,10], [20,50], and [1,100]. Can anyone give an example for this?

Thank you! Kevin

If you are using R, this might be useful. See the lhs package for more information and other examples.

require(lhs)
set.seed(14958393)
N <- 100
X <- lhs::randomLHS(N, 5)
Y <- as.data.frame(X)
names(Y) <- c("f1","f2","i1", "i2", "i3")
# map the continuous samples into the right distribution
Y$$f1 <- qnorm(Y$$f1, 2, 1)
Y$$f2 <- qlnorm(Y$$f2, 0.5, 0.1)
# translate the integer marginals
map_to_integers <- function(p, a, b)
{
# p is a vector on (0,1)
# a and b are integers
floor(p*(b-a+1)) + a
}
Y$$i1 <- map_to_integers(Y$$i1, 0, 10)
Y$$i2 <- map_to_integers(Y$$i2, 20, 50)
Y$$i3 <- map_to_integers(Y$$i3, 1, 100)

# the distribution is not perfectly uniform because
N %% (10-0+1) != 0
#> [1] TRUE
table(Y$$i1) #> #> 0 1 2 3 4 5 6 7 8 9 10 #> 9 9 9 9 10 8 9 10 9 9 9 # same here N %% (50-20+1) != 0 #> [1] TRUE table(Y$$i2)
#>
#> 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#>  3  3  4  3  3  3  3  3  4  4  3  3  3  3  3  4  3  3  3  4  2  4  3  3  4  3
#> 46 47 48 49 50
#>  3  3  4  2  4
# but here, each one is sampled exactly once because
N %% (100-1+1) == 0
#> [1] TRUE
table(Y\$i3)
#>
#>   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
#>   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
#>  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40
#>   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
#>  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60
#>   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
#>  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80
#>   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
#>  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100
#>   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1

• Hi Rob, thanks a lot for your help. I just saw your post here cran.r-project.org/web/packages/lhs/vignettes/lhs_faq.html and was trying to contact you. Then, I found you replied me here. I am using Python but I think I can learn R and use your code. Thanks a lot again! Commented Nov 9, 2021 at 4:08