Title: | Latin Hypercube Samples |
---|---|
Description: | Provides a number of methods for creating and augmenting Latin Hypercube Samples and Orthogonal Array Latin Hypercube Samples. |
Authors: | Rob Carnell [aut, cre] |
Maintainer: | Rob Carnell <[email protected]> |
License: | GPL-3 |
Version: | 1.2.0 |
Built: | 2024-10-28 05:21:59 UTC |
Source: | https://github.com/bertcarnell/lhs |
Augments an existing Latin Hypercube Sample, adding points to the design, while maintaining the latin properties of the design.
augmentLHS(lhs, m = 1)
augmentLHS(lhs, m = 1)
lhs |
The Latin Hypercube Design to which points are to be added. Contains an existing latin hypercube design with a number of rows equal to the points in the design (simulations) and a number of columns equal to the number of variables (parameters). The values of each cell must be between 0 and 1 and uniformly distributed |
m |
The number of additional points to add to matrix |
Augments an existing Latin Hypercube Sample, adding points to the design, while maintaining the latin properties of the design. Augmentation is perfomed in a random manner.
The algorithm used by this function has the following steps.
First, create a new matrix to hold the candidate points after the design has
been re-partitioned into cells, where n is number of
points in the original
lhs
matrix. Then randomly sweep through each
column (1...k
) in the repartitioned design to find the missing cells.
For each column (variable), randomly search for an empty row, generate a
random value that fits in that row, record the value in the new matrix.
The new matrix can contain more filled cells than m
unles ,
in which case the new matrix will contain exactly
m
filled cells.
Finally, keep only the first m rows of the new matrix. It is guaranteed to
have m
full rows in the new matrix. The deleted rows are partially full.
The additional candidate points are selected randomly due to the random search
for empty cells.
An n
by k
Latin Hypercube Sample matrix with values
uniformly distributed on [0,1]
Rob Carnell
Stein, M. (1987) Large Sample Properties of Simulations Using Latin Hypercube Sampling. Technometrics. 29, 143–151.
[randomLHS()], [geneticLHS()], [improvedLHS()], [maximinLHS()], and [optimumLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()] and [optSeededLHS()] to modify and augment existing designs.
set.seed(1234) a <- randomLHS(4,3) b <- augmentLHS(a, 2)
set.seed(1234) a <- randomLHS(4,3) b <- augmentLHS(a, 2)
Create a Galois field
create_galois_field(q)
create_galois_field(q)
q |
The order of the Galois Field q = p^n |
a GaloisField object containing
q = p^n
The prime modulus of the field q=p^n
The order of the Galois Field q = p^n. q
must be a prime power.
coefficients of the characteristic polynomial where the first coefficient is on $x^0$, the second is on $x^1$ and so on
An index for which row of poly
(zero based) is the multiplicative inverse of this row. An NA
indicates that this row of poly
has no inverse. e.g. c(3, 4) means that row 4=3+1 is the inverse of row 1 and row 5=4+1 is the inverse of row 2
An index for which row of poly
(zero based) is the negative or additive inverse of this row. An NA
indicates that this row of poly
has no negative. e.g. c(3, 4) means that row 4=3+1 is the negative of row 1 and row 5=4+1 is the negative of row 2
An index for which row of poly
(zero based) is the square root of this row. An NA
indicates that this row of poly
has no square root. e.g. c(3, 4) means that row 4=3+1 is the square root of row 1 and row 5=4+1 is the square root of row 2
sum table of the Galois Field
multiplication table of the Galois Field
rows are polynomials of the Galois Field where the entries are the coefficients of the polynomial where the first coefficient is on $x^0$, the second is on $x^1$ and so on
gf <- create_galois_field(4);
gf <- create_galois_field(4);
Create an orthogonal array Latin hypercube
create_oalhs(n, k, bChooseLargerDesign, bverbose)
create_oalhs(n, k, bChooseLargerDesign, bverbose)
n |
the number of samples or rows in the LHS (integer) |
k |
the number of parameters or columns in the LHS (integer) |
bChooseLargerDesign |
should a larger oa design be chosen than the n and k requested? |
bverbose |
should information be printed with execution |
a numeric matrix which is an orthogonal array Latin hypercube sample
set.seed(34) A <- create_oalhs(9, 4, TRUE, FALSE) B <- create_oalhs(9, 4, TRUE, FALSE)
set.seed(34) A <- create_oalhs(9, 4, TRUE, FALSE) B <- create_oalhs(9, 4, TRUE, FALSE)
The addelkemp
program produces OA( 2q^2, k, q, 2 )
, k <= 2q+1
,
for odd prime powers q
.
createAddelKemp(q, ncol, bRandom = TRUE)
createAddelKemp(q, ncol, bRandom = TRUE)
q |
the number of symbols in the array |
ncol |
number of parameters or columns |
bRandom |
should the array be randomized |
From Owen: An orthogonal array A
is a matrix of n
rows, k
columns with every element being one of q
symbols
0,...,q-1
. The array has strength t
if, in every n
by t
submatrix, the q^t
possible distinct rows, all appear
the same number of times. This number is the index
of the array, commonly denoted lambda
. Clearly,
lambda*q^t=n
. The notation for such an array is OA( n, k, q, t )
.
an orthogonal array
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, and Integration in high dimensions. https://lib.stat.cmu.edu/designs/oa.c. 1994 S. Addelman and O. Kempthorne (1961) Annals of Mathematical Statistics, Vol 32 pp 1167-1176.
Other methods to create orthogonal arrays [createBoseBush()], [createBose()], [createAddelKemp3()], [createAddelKempN()], [createBusht()], [createBoseBushl()]
A <- createAddelKemp(3, 3, TRUE) B <- createAddelKemp(3, 5, FALSE)
A <- createAddelKemp(3, 3, TRUE) B <- createAddelKemp(3, 5, FALSE)
2q^3
rows.The addelkemp3
program produces
OA( 2*q^3, k, q, 2 )
, k <= 2q^2+2q+1
, for prime powers q
.
q
may be an odd prime power, or q
may be 2 or 4.
createAddelKemp3(q, ncol, bRandom = TRUE)
createAddelKemp3(q, ncol, bRandom = TRUE)
q |
the number of symbols in the array |
ncol |
number of parameters or columns |
bRandom |
should the array be randomized |
From Owen: An orthogonal array A
is a matrix of n
rows, k
columns with every element being one of q
symbols
0,...,q-1
. The array has strength t
if, in every n
by t
submatrix, the q^t
possible distinct rows, all appear
the same number of times. This number is the index
of the array, commonly denoted lambda
. Clearly,
lambda*q^t=n
. The notation for such an array is OA( n, k, q, t )
.
an orthogonal array
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, and Integration in high dimensions. https://lib.stat.cmu.edu/designs/oa.c. 1994 S. Addelman and O. Kempthorne (1961) Annals of Mathematical Statistics, Vol 32 pp 1167-1176.
Other methods to create orthogonal arrays [createBushBush()], [createBose()], [createAddelKemp()], [createAddelKempN()], [createBusht()], [createBoseBushl()]
A <- createAddelKemp3(3, 3, TRUE) B <- createAddelKemp3(3, 5, FALSE)
A <- createAddelKemp3(3, 3, TRUE) B <- createAddelKemp3(3, 5, FALSE)
2q^n
rows.The addelkempn
program produces
OA( 2*q^n, k, q, 2 )
, k <= 2(q^n - 1)/(q-1)-1
, for prime powers q
.
q
may be an odd prime power, or q
may be 2 or 4.
createAddelKempN(q, ncol, exponent, bRandom = TRUE)
createAddelKempN(q, ncol, exponent, bRandom = TRUE)
q |
the number of symbols in the array |
ncol |
number of parameters or columns |
exponent |
the exponent on q |
bRandom |
should the array be randomized |
From Owen: An orthogonal array A
is a matrix of n
rows, k
columns with every element being one of q
symbols
0,...,q-1
. The array has strength t
if, in every n
by t
submatrix, the q^t
possible distinct rows, all appear
the same number of times. This number is the index
of the array, commonly denoted lambda
. Clearly,
lambda*q^t=n
. The notation for such an array is OA( n, k, q, t )
.
an orthogonal array
Other methods to create orthogonal arrays [createBoseBush()], [createBose()], [createBush()], [createAddelKemp()], [createAddelKemp3()], [createBusht()], [createBoseBushl()]
A <- createAddelKempN(3, 4, 3, TRUE) B <- createAddelKempN(3, 4, 4, TRUE)
A <- createAddelKempN(3, 4, 3, TRUE) B <- createAddelKempN(3, 4, 4, TRUE)
The bose
program
produces OA( q^2, k, q, 2 )
, k <= q+1
for prime powers q
.
createBose(q, ncol, bRandom = TRUE)
createBose(q, ncol, bRandom = TRUE)
q |
the number of symbols in the array |
ncol |
number of parameters or columns |
bRandom |
should the array be randomized |
From Owen: An orthogonal array A
is a matrix of n
rows, k
columns with every element being one of q
symbols
0,...,q-1
. The array has strength t
if, in every n
by t
submatrix, the q^t
possible distinct rows, all appear
the same number of times. This number is the index
of the array, commonly denoted lambda
. Clearly,
lambda*q^t=n
. The notation for such an array is OA( n, k, q, t )
.
an orthogonal array
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, and Integration in high dimensions. https://lib.stat.cmu.edu/designs/oa.c. 1994 R.C. Bose (1938) Sankhya Vol 3 pp 323-338
Other methods to create orthogonal arrays [createBush()], [createBoseBush()], [createAddelKemp()], [createAddelKemp3()], [createAddelKempN()], [createBusht()], [createBoseBushl()]
A <- createBose(3, 3, FALSE) B <- createBose(5, 4, TRUE)
A <- createBose(3, 3, FALSE) B <- createBose(5, 4, TRUE)
The bosebush
program
produces OA( 2q^2, k, q, 2 )
, k <= 2q+1
, for powers of 2, q=2^r
.
createBoseBush(q, ncol, bRandom = TRUE)
createBoseBush(q, ncol, bRandom = TRUE)
q |
the number of symbols in the array |
ncol |
number of parameters or columns |
bRandom |
should the array be randomized |
From Owen: An orthogonal array A
is a matrix of n
rows, k
columns with every element being one of q
symbols
0,...,q-1
. The array has strength t
if, in every n
by t
submatrix, the q^t
possible distinct rows, all appear
the same number of times. This number is the index
of the array, commonly denoted lambda
. Clearly,
lambda*q^t=n
. The notation for such an array is OA( n, k, q, t )
.
an orthogonal array
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, and Integration in high dimensions. https://lib.stat.cmu.edu/designs/oa.c. 1994 R.C. Bose and K.A. Bush (1952) Annals of Mathematical Statistics, Vol 23 pp 508-524.
Other methods to create orthogonal arrays [createBush()], [createBose()], [createAddelKemp()], [createAddelKemp3()], [createAddelKempN()], [createBusht()], [createBoseBushl()]
A <- createBoseBush(4, 3, FALSE) B <- createBoseBush(8, 3, TRUE)
A <- createBoseBush(4, 3, FALSE) B <- createBoseBush(8, 3, TRUE)
The bosebushl
program produces OA( lambda*q^2, k, q, 2 )
,
k <= lambda*q+1
, for prime powers q
and lambda > 1
. Both q
and
lambda
must be powers of the same prime.
createBoseBushl(q, ncol, lambda, bRandom = TRUE)
createBoseBushl(q, ncol, lambda, bRandom = TRUE)
q |
the number of symbols in the array |
ncol |
number of parameters or columns |
lambda |
the lambda of the BoseBush algorithm |
bRandom |
should the array be randomized |
From Owen: An orthogonal array A
is a matrix of n
rows, k
columns with every element being one of q
symbols
0,...,q-1
. The array has strength t
if, in every n
by t
submatrix, the q^t
possible distinct rows, all appear
the same number of times. This number is the index
of the array, commonly denoted lambda
. Clearly,
lambda*q^t=n
. The notation for such an array is OA( n, k, q, t )
.
an orthogonal array
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, and Integration in high dimensions. https://lib.stat.cmu.edu/designs/oa.c. 1994 R.C. Bose and K.A. Bush (1952) Annals of Mathematical Statistics, Vol 23 pp 508-524.
Other methods to create orthogonal arrays [createBoseBush()], [createBose()], [createBush()], [createAddelKemp()], [createAddelKemp3()], [createAddelKempN()], [createBusht()]
A <- createBoseBushl(3, 3, 3, TRUE) B <- createBoseBushl(4, 4, 16, TRUE)
A <- createBoseBushl(3, 3, 3, TRUE) B <- createBoseBushl(4, 4, 16, TRUE)
The bush
program
produces OA( q^3, k, q, 3 )
, k <= q+1
for prime powers q
.
createBush(q, ncol, bRandom = TRUE)
createBush(q, ncol, bRandom = TRUE)
q |
the number of symbols in the array |
ncol |
number of parameters or columns |
bRandom |
should the array be randomized |
From Owen: An orthogonal array A
is a matrix of n
rows, k
columns with every element being one of q
symbols
0,...,q-1
. The array has strength t
if, in every n
by t
submatrix, the q^t
possible distinct rows, all appear
the same number of times. This number is the index
of the array, commonly denoted lambda
. Clearly,
lambda*q^t=n
. The notation for such an array is OA( n, k, q, t )
.
an orthogonal array
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, and Integration in high dimensions. https://lib.stat.cmu.edu/designs/oa.c. 1994 K.A. Bush (1952) Annals of Mathematical Statistics, Vol 23 pp 426-434
Other methods to create orthogonal arrays [createBoseBush()], [createBose()], [createAddelKemp()], [createAddelKemp3()], [createAddelKempN()], [createBusht()], [createBoseBushl()]
A <- createBush(3, 3, FALSE) B <- createBush(4, 5, TRUE)
A <- createBush(3, 3, FALSE) B <- createBush(4, 5, TRUE)
The busht
program produces OA( q^t, k, q, t )
, k <= q+1
, t>=3
,
for prime powers q
.
createBusht(q, ncol, strength, bRandom = TRUE)
createBusht(q, ncol, strength, bRandom = TRUE)
q |
the number of symbols in the array |
ncol |
number of parameters or columns |
strength |
the strength of the array to be created |
bRandom |
should the array be randomized |
From Owen: An orthogonal array A
is a matrix of n
rows, k
columns with every element being one of q
symbols
0,...,q-1
. The array has strength t
if, in every n
by t
submatrix, the q^t
possible distinct rows, all appear
the same number of times. This number is the index
of the array, commonly denoted lambda
. Clearly,
lambda*q^t=n
. The notation for such an array is OA( n, k, q, t )
.
an orthogonal array
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, and Integration in high dimensions. https://lib.stat.cmu.edu/designs/oa.c. 1994 K.A. Bush (1952) Annals of Mathematical Statistics, Vol 23 pp 426-434
Other methods to create orthogonal arrays [createBoseBush()], [createBose()], [createAddelKemp()], [createAddelKemp3()], [createAddelKempN()], [createBoseBushl()]
set.seed(1234) A <- createBusht(3, 4, 2, TRUE) B <- createBusht(3, 4, 3, FALSE) G <- createBusht(3, 4, 3, TRUE)
set.seed(1234) A <- createBusht(3, 4, 2, TRUE) B <- createBusht(3, 4, 3, FALSE) G <- createBusht(3, 4, 3, TRUE)
Draws a Latin Hypercube Sample from a set of uniform distributions for use in creating a Latin Hypercube Design. This function attempts to optimize the sample with respect to the S optimality criterion through a genetic type algorithm.
geneticLHS( n = 10, k = 2, pop = 100, gen = 4, pMut = 0.1, criterium = "S", verbose = FALSE )
geneticLHS( n = 10, k = 2, pop = 100, gen = 4, pMut = 0.1, criterium = "S", verbose = FALSE )
n |
The number of partitions (simulations or design points or rows) |
k |
The number of replications (variables or columns) |
pop |
The number of designs in the initial population |
gen |
The number of generations over which the algorithm is applied |
pMut |
The probability with which a mutation occurs in a column of the progeny |
criterium |
The optimality criterium of the algorithm. Default is |
verbose |
Print informational messages. Default is |
Latin hypercube sampling (LHS) was developed to generate a distribution
of collections of parameter values from a multidimensional distribution.
A square grid containing possible sample points is a Latin square iff there
is only one sample in each row and each column. A Latin hypercube is the
generalisation of this concept to an arbitrary number of dimensions. When
sampling a function of k
variables, the range of each variable is divided
into n
equally probable intervals. n
sample points are then drawn such that a
Latin Hypercube is created. Latin Hypercube sampling generates more efficient
estimates of desired parameters than simple Monte Carlo sampling.
This program generates a Latin Hypercube Sample by creating random permutations
of the first n
integers in each of k
columns and then transforming those
integers into n sections of a standard uniform distribution. Random values are
then sampled from within each of the n sections. Once the sample is generated,
the uniform sample from a column can be transformed to any distribution by
using the quantile functions, e.g. qnorm(). Different columns can have
different distributions.
S-optimality seeks to maximize the mean distance from each design point to all the other points in the design, so the points are as spread out as possible.
Genetic Algorithm:
Generate pop
random latin hypercube designs of size n
by k
Calculate the S optimality measure of each design
Keep the best design in the first position and throw away half of the rest of the population
Take a random column out of the best matrix and place it in a random column of each of the other matricies, and take a random column out of each of the other matricies and put it in copies of the best matrix thereby causing the progeny
For each of the progeny, cause a genetic mutation pMut
percent of the time. The mutation is accomplished by swtching two elements in a column
An n
by k
Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
Rob Carnell
Stocki, R. (2005) A method to improve design reliability using optimal Latin hypercube sampling Computer Assisted Mechanics and Engineering Sciences 12, 87–105.
Stein, M. (1987) Large Sample Properties of Simulations Using Latin Hypercube Sampling. Technometrics. 29, 143–151.
[randomLHS()], [improvedLHS()], [maximinLHS()], and [optimumLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()] [optSeededLHS()], and [augtmentLHS()] to modify and augment existing designs.
set.seed(1234) A <- geneticLHS(4, 3, 50, 5, .25)
set.seed(1234) A <- geneticLHS(4, 3, 50, 5, .25)
Get version information for all libraries in the lhs package
get_library_versions()
get_library_versions()
a character string containing the versions
get_library_versions()
get_library_versions()
Draws a Latin Hypercube Sample from a set of uniform distributions for use in creating a Latin Hypercube Design. This function attempts to optimize the sample with respect to an optimum euclidean distance between design points.
improvedLHS(n, k, dup = 1)
improvedLHS(n, k, dup = 1)
n |
The number of partitions (simulations or design points or rows) |
k |
The number of replications (variables or columns) |
dup |
A factor that determines the number of candidate points used in the search. A multiple of the number of remaining points than can be added. |
Latin hypercube sampling (LHS) was developed to generate a distribution
of collections of parameter values from a multidimensional distribution.
A square grid containing possible sample points is a Latin square iff there
is only one sample in each row and each column. A Latin hypercube is the
generalisation of this concept to an arbitrary number of dimensions. When
sampling a function of k
variables, the range of each variable is divided
into n
equally probable intervals. n
sample points are then drawn such that a
Latin Hypercube is created. Latin Hypercube sampling generates more efficient
estimates of desired parameters than simple Monte Carlo sampling.
This program generates a Latin Hypercube Sample by creating random permutations
of the first n
integers in each of k
columns and then transforming those
integers into n sections of a standard uniform distribution. Random values are
then sampled from within each of the n sections. Once the sample is generated,
the uniform sample from a column can be transformed to any distribution byusing the quantile functions, e.g. qnorm(). Different columns can have
different distributions.
This function attempts to optimize the sample with respect to an optimum euclidean distance between design points.
An n
by k
Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
Beachkofski, B., Grandhi, R. (2002) Improved Distributed Hypercube Sampling American Institute of Aeronautics and Astronautics Paper 1274.
This function is based on the MATLAB program written by John Burkardt and modified 16 Feb 2005 https://people.math.sc.edu/Burkardt/m_src/ihs/ihs.html
[randomLHS()], [geneticLHS()], [maximinLHS()], and [optimumLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()], [optSeededLHS()], and [augmentLHS()] to modify and augment existing designs.
set.seed(1234) A <- improvedLHS(4, 3, 2)
set.seed(1234) A <- improvedLHS(4, 3, 2)
Draws a Latin Hypercube Sample from a set of uniform distributions for use in creating a Latin Hypercube Design. This function attempts to optimize the sample by maximizing the minium distance between design points (maximin criteria).
maximinLHS( n, k, method = "build", dup = 1, eps = 0.05, maxIter = 100, optimize.on = "grid", debug = FALSE )
maximinLHS( n, k, method = "build", dup = 1, eps = 0.05, maxIter = 100, optimize.on = "grid", debug = FALSE )
n |
The number of partitions (simulations or design points or rows) |
k |
The number of replications (variables or columns) |
method |
|
dup |
A factor that determines the number of candidate points used in the
search. A multiple of the number of remaining points than can be
added. This is used when |
eps |
The minimum percent change in the minimum distance used in the
|
maxIter |
The maximum number of iterations to use in the |
optimize.on |
|
debug |
prints additional information about the process of the optimization |
Latin hypercube sampling (LHS) was developed to generate a distribution
of collections of parameter values from a multidimensional distribution.
A square grid containing possible sample points is a Latin square iff there
is only one sample in each row and each column. A Latin hypercube is the
generalisation of this concept to an arbitrary number of dimensions. When
sampling a function of k
variables, the range of each variable is divided
into n
equally probable intervals. n
sample points are then drawn such that a
Latin Hypercube is created. Latin Hypercube sampling generates more efficient
estimates of desired parameters than simple Monte Carlo sampling.
This program generates a Latin Hypercube Sample by creating random permutations
of the first n
integers in each of k
columns and then transforming those
integers into n sections of a standard uniform distribution. Random values are
then sampled from within each of the n sections. Once the sample is generated,
the uniform sample from a column can be transformed to any distribution by
using the quantile functions, e.g. qnorm(). Different columns can have
different distributions.
Here, values are added to the design one by one such that the maximin criteria is satisfied.
An n
by k
Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
Stein, M. (1987) Large Sample Properties of Simulations Using Latin Hypercube Sampling. Technometrics. 29, 143–151.
This function is motivated by the MATLAB program written by John Burkardt and modified 16 Feb 2005 https://people.math.sc.edu/Burkardt/m_src/ihs/ihs.html
[randomLHS()], [geneticLHS()], [improvedLHS()] and [optimumLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()], [optSeededLHS()], and [augmentLHS()] to modify and augment existing designs.
set.seed(1234) A1 <- maximinLHS(4, 3, dup=2) A2 <- maximinLHS(4, 3, method="build", dup=2) A3 <- maximinLHS(4, 3, method="iterative", eps=0.05, maxIter=100, optimize.on="grid") A4 <- maximinLHS(4, 3, method="iterative", eps=0.05, maxIter=100, optimize.on="result")
set.seed(1234) A1 <- maximinLHS(4, 3, dup=2) A2 <- maximinLHS(4, 3, method="build", dup=2) A3 <- maximinLHS(4, 3, method="iterative", eps=0.05, maxIter=100, optimize.on="grid") A4 <- maximinLHS(4, 3, method="iterative", eps=0.05, maxIter=100, optimize.on="result")
Create a Latin hypercube from an orthogonal array
oa_to_oalhs(n, k, oa)
oa_to_oalhs(n, k, oa)
n |
the number of samples or rows in the LHS (integer) |
k |
the number of parameters or columns in the LHS (integer) |
oa |
the orthogonal array to be used as the basis for the LHS (matrix of integers) or data.frame of factors |
a numeric matrix which is a Latin hypercube sample
oa <- createBose(3, 4, TRUE) B <- oa_to_oalhs(9, 4, oa)
oa <- createBose(3, 4, TRUE) B <- oa_to_oalhs(9, 4, oa)
Augments an existing Latin Hypercube Sample, adding points to the design, while maintaining the latin properties of the design. This function attempts to add the points to the design in an optimal way.
optAugmentLHS(lhs, m = 1, mult = 2)
optAugmentLHS(lhs, m = 1, mult = 2)
lhs |
The Latin Hypercube Design to which points are to be added |
m |
The number of additional points to add to matrix |
mult |
|
Augments an existing Latin Hypercube Sample, adding points to the design, while maintaining the latin properties of the design. This function attempts to add the points to the design in a way that maximizes S optimality.
S-optimality seeks to maximize the mean distance from each design point to all the other points in the design, so the points are as spread out as possible.
An n
by k
Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
Stein, M. (1987) Large Sample Properties of Simulations Using Latin Hypercube Sampling. Technometrics. 29, 143–151.
[randomLHS()], [geneticLHS()], [improvedLHS()], [maximinLHS()], and [optimumLHS()] to generate Latin Hypercube Samples. [optSeededLHS()] and [augmentLHS()] to modify and augment existing designs.
set.seed(1234) a <- randomLHS(4,3) b <- optAugmentLHS(a, 2, 3)
set.seed(1234) a <- randomLHS(4,3) b <- optAugmentLHS(a, 2, 3)
Draws a Latin Hypercube Sample from a set of uniform distributions for use in creating a Latin Hypercube Design. This function uses the Columnwise Pairwise (CP) algorithm to generate an optimal design with respect to the S optimality criterion.
optimumLHS(n = 10, k = 2, maxSweeps = 2, eps = 0.1, verbose = FALSE)
optimumLHS(n = 10, k = 2, maxSweeps = 2, eps = 0.1, verbose = FALSE)
n |
The number of partitions (simulations or design points or rows) |
k |
The number of replications (variables or columns) |
maxSweeps |
The maximum number of times the CP algorithm is applied to all the columns. |
eps |
The optimal stopping criterion. Algorithm stops when the change in optimality measure is less than eps*100% of the previous value. |
verbose |
Print informational messages |
Latin hypercube sampling (LHS) was developed to generate a distribution
of collections of parameter values from a multidimensional distribution.
A square grid containing possible sample points is a Latin square iff there
is only one sample in each row and each column. A Latin hypercube is the
generalisation of this concept to an arbitrary number of dimensions. When
sampling a function of k
variables, the range of each variable is divided
into n
equally probable intervals. n
sample points are then drawn such that a
Latin Hypercube is created. Latin Hypercube sampling generates more efficient
estimates of desired parameters than simple Monte Carlo sampling.
This program generates a Latin Hypercube Sample by creating random permutations
of the first n
integers in each of k
columns and then transforming those
integers into n sections of a standard uniform distribution. Random values are
then sampled from within each of the n sections. Once the sample is generated,
the uniform sample from a column can be transformed to any distribution by
using the quantile functions, e.g. qnorm(). Different columns can have
different distributions.
S-optimality seeks to maximize the mean distance from each design point to all the other points in the design, so the points are as spread out as possible.
This function uses the CP algorithm to generate an optimal design with respect to the S optimality criterion.
An n
by k
Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
Stocki, R. (2005) A method to improve design reliability using optimal Latin hypercube sampling Computer Assisted Mechanics and Engineering Sciences 12, 87–105.
[randomLHS()], [geneticLHS()], [improvedLHS()] and [maximinLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()], [optSeededLHS()], and [augmentLHS()] to modify and augment existing designs.
A <- optimumLHS(4, 3, 5, .05)
A <- optimumLHS(4, 3, 5, .05)
Augments an existing Latin Hypercube Sample, adding points to the design, while maintaining the latin properties of the design. This function then uses the columnwise pairwise (CP) algoritm to optimize the design. The original design is not necessarily maintained.
optSeededLHS(seed, m = 0, maxSweeps = 2, eps = 0.1, verbose = FALSE)
optSeededLHS(seed, m = 0, maxSweeps = 2, eps = 0.1, verbose = FALSE)
seed |
The number of partitions (simulations or design points) |
m |
The number of additional points to add to the seed matrix |
maxSweeps |
The maximum number of times the CP algorithm is applied to all the columns. |
eps |
The optimal stopping criterion |
verbose |
Print informational messages |
Augments an existing Latin Hypercube Sample, adding points to the design, while maintaining the latin properties of the design. This function then uses the CP algoritm to optimize the design. The original design is not necessarily maintained.
An n
by k
Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
Stein, M. (1987) Large Sample Properties of Simulations Using Latin Hypercube Sampling. Technometrics. 29, 143–151.
[randomLHS()], [geneticLHS()], [improvedLHS()], [maximinLHS()], and [optimumLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()] and [augmentLHS()] to modify and augment existing designs.
set.seed(1234) a <- randomLHS(4,3) b <- optSeededLHS(a, 2, 2, .1)
set.seed(1234) a <- randomLHS(4,3) b <- optSeededLHS(a, 2, 2, .1)
Multiplication in polynomial representation
poly_prod(p, n, xton, p1, p2)
poly_prod(p, n, xton, p1, p2)
p |
modulus |
n |
length of polynomials |
xton |
characteristic polynomial vector for the field (x to the n power) |
p1 |
polynomial vector 1 |
p2 |
polynomial vector 2 |
the product of p1 and p2
gf <- create_galois_field(4) a <- poly_prod(gf$p, gf$n, gf$xton, c(1, 0), c(0, 1)) stopifnot(all(a == c(0, 1)))
gf <- create_galois_field(4) a <- poly_prod(gf$p, gf$n, gf$xton, c(1, 0), c(0, 1)) stopifnot(all(a == c(0, 1)))
Addition in polynomial representation
poly_sum(p, n, p1, p2)
poly_sum(p, n, p1, p2)
p |
modulus |
n |
length of polynomial 1 and 2 |
p1 |
polynomial vector 1 |
p2 |
polynomial vector 2 |
the sum of p1 and p2
gf <- create_galois_field(4) a <- poly_sum(gf$p, gf$n, c(1, 0), c(0, 1)) stopifnot(all(a == c(1, 1)))
gf <- create_galois_field(4) a <- poly_sum(gf$p, gf$n, c(1, 0), c(0, 1)) stopifnot(all(a == c(1, 1)))
Convert polynomial to integer in <code>0..q-1</code>
poly2int(p, n, poly)
poly2int(p, n, poly)
p |
modulus |
n |
the length of poly |
poly |
the polynomial vector |
an integer
gf <- create_galois_field(4) stopifnot(poly2int(gf$p, gf$n, c(0, 0)) == 0)
gf <- create_galois_field(4) stopifnot(poly2int(gf$p, gf$n, c(0, 0)) == 0)
A collection of functions that transform the margins of a Latin hypercube sample in multiple ways
qfactor(p, fact) qinteger(p, a, b) qdirichlet(X, alpha)
qfactor(p, fact) qinteger(p, a, b) qdirichlet(X, alpha)
p |
a vector of LHS samples on (0,1) |
fact |
a factor or categorical variable. Ordered and un-ordered variables are allowed. |
a |
a minimum integer |
b |
a maximum integer |
X |
multiple columns of an LHS sample on (0,1) |
alpha |
Dirichlet distribution parameters. All |
qdirichlet
is not an exact quantile function since the quantile of a
multivariate distribution is not unique. qdirichlet
is also not the
independent quantiles of the marginal distributions since
those quantiles do not sum to one. qdirichlet
is the quantile of the
underlying gamma functions, normalized. This is the same procedure that
is used to generate random deviates from the Dirichlet distribution therefore
it will produce transformed Latin hypercube samples with the intended distribution.
q_factor
divides the [0,1] interval into nlevel(fact)
equal sections
and assigns values in those sections to the factor level.
the transformed column or columns
X <- randomLHS(20, 7) Y <- as.data.frame(X) Y[,1] <- qnorm(X[,1], 2, 0.5) Y[,2] <- qfactor(X[,2], factor(LETTERS[c(1,3,5,7,8)])) Y[,3] <- qinteger(X[,3], 5, 17) Y[,4:6] <- qdirichlet(X[,4:6], c(2,3,4)) Y[,7] <- qfactor(X[,7], ordered(LETTERS[c(1,3,5,7,8)]))
X <- randomLHS(20, 7) Y <- as.data.frame(X) Y[,1] <- qnorm(X[,1], 2, 0.5) Y[,2] <- qfactor(X[,2], factor(LETTERS[c(1,3,5,7,8)])) Y[,3] <- qinteger(X[,3], 5, 17) Y[,4:6] <- qdirichlet(X[,4:6], c(2,3,4)) Y[,7] <- qfactor(X[,7], ordered(LETTERS[c(1,3,5,7,8)]))
randomLHS(4,3)
returns a 4x3 matrix with each column
constructed as follows: A random permutation of (1,2,3,4) is
generated, say (3,1,2,4) for each of K columns. Then a uniform
random number is picked from each indicated quartile. In this
example a random number between .5 and .75 is chosen, then one between
0 and .25, then one between .25 and .5, finally one between
.75 and 1.
randomLHS(n, k, preserveDraw = FALSE)
randomLHS(n, k, preserveDraw = FALSE)
n |
the number of rows or samples |
k |
the number of columns or parameters/variables |
preserveDraw |
should the draw be constructed so that it is the same for variable numbers of columns? |
a Latin hypercube sample
a <- randomLHS(5, 3)
a <- randomLHS(5, 3)
Create a Random Sample of Uniform Integers
runifint(n = 1, min_int = 0, max_int = 1)
runifint(n = 1, min_int = 0, max_int = 1)
n |
The number of samples |
min_int |
the minimum integer |
max_int |
the maximum integer |
the sample sample of size n