| Title: | Latin Hypercube Samples |
| Version: | 1.2.0 |
| Description: | Provides a number of methods for creating and augmenting Latin Hypercube Samples and Orthogonal Array Latin Hypercube Samples. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| Depends: | R (≥ 3.4.0) |
| LinkingTo: | Rcpp |
| Imports: | Rcpp |
| Suggests: | testthat, DoE.base, knitr, rmarkdown |
| URL: | https://github.com/bertcarnell/lhs |
| BugReports: | https://github.com/bertcarnell/lhs/issues |
| RoxygenNote: | 7.3.2 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | yes |
| Packaged: | 2024-06-30 21:59:33 UTC; bertc |
| Author: | Rob Carnell [aut, cre] |
| Maintainer: | Rob Carnell <bertcarnell@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2024-06-30 23:10:02 UTC |
lhs: Latin Hypercube Samples
Description
Provides a number of methods for creating and augmenting Latin Hypercube Samples and Orthogonal Array Latin Hypercube Samples.
Author(s)
Maintainer: Rob Carnellbertcarnell@gmail.com
See Also
Useful links:
Augment a Latin Hypercube Design
Description
Augments an existing Latin Hypercube Sample, adding points to the design, whilemaintaining thelatin properties of the design.
Usage
augmentLHS(lhs, m = 1)Arguments
lhs | The Latin Hypercube Design to which points are to be added.Contains an existing latin hypercube design with a number of rows equalto the points in the design (simulations) and a number of columns equalto the number of variables (parameters). The values of each cell must bebetween 0 and 1 and uniformly distributed |
m | The number of additional points to add to matrix |
Details
Augments an existing Latin Hypercube Sample, adding points to the design, whilemaintaining thelatin properties of the design. Augmentation is perfomedin 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 hasbeen re-partitioned into(n+m)^{2} cells, where n is number ofpoints in the originallhs matrix. Then randomly sweep through eachcolumn (1...k) in the repartitioned design to find the missing cells.For each column (variable), randomly search for an empty row, generate arandom value that fits in that row, record the value in the new matrix.The new matrix can contain more filled cells thanm unlesm = 2n,in which case the new matrix will contain exactlym filled cells.Finally, keep only the first m rows of the new matrix. It is guaranteed tohavem full rows in the new matrix. The deleted rows are partially full.The additional candidate points are selected randomly due to the random searchfor empty cells.
Value
Ann byk Latin Hypercube Sample matrix with valuesuniformly distributed on [0,1]
Author(s)
Rob Carnell
References
Stein, M. (1987) Large Sample Properties of Simulations Using LatinHypercube Sampling.Technometrics.29, 143–151.
See Also
[randomLHS()], [geneticLHS()], [improvedLHS()], [maximinLHS()],and [optimumLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()]and [optSeededLHS()] to modify and augment existing designs.
Examples
set.seed(1234)a <- randomLHS(4,3)b <- augmentLHS(a, 2)Transformed Latin hypercube with a multivariate distribution
Description
A method to create a transformed Latin Hypercube sample where the marginaldistributions can be correlated according to an arbitrary set of criteriacontained 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 themargins |
marginal_transform_function | a function that takes Latin hypercube sampleas the first argument and other passed-through variables as desired. |
cost_function | a function that takes a transformed Latin hypercube sampleas the first argument and other passed-through variables as desired. |
debug | Should debug messages be printed. Causes cost function outputand iterations to be printed to aid in setting the maximum number of iterations |
maxiter | the maximum number of iterations. The algorithm proceeds byswapping one variable of two points at a time. Each swap is an iteration. |
... | Additional arguments to be passed through to the |
Value
a list of the Latin hypercube with uniform margins, the transformedLatin 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)Create an orthogonal array using the Addelman-Kempthorne algorithm.
Description
Theaddelkemp program producesOA( 2q^2, k, q, 2 ),k <= 2q+1,for odd prime powersq.
Usage
createAddelKemp(q, ncol, bRandom = TRUE)Arguments
q | the number of symbols in the array |
ncol | number of parameters or columns |
bRandom | should the array be randomized |
Details
From Owen: An orthogonal arrayA is a matrix ofn rows,kcolumns with every element being one ofq symbols0,...,q-1. The array has strengtht if, in everyn bytsubmatrix, theq^t possible distinct rows, all appearthe same number of times. This number is the indexof the array, commonly denotedlambda. Clearly,lambda*q^t=n. The notation for such an array isOA( n, k, q, t ).
Value
an orthogonal array
References
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, andIntegration in high dimensions.https://lib.stat.cmu.edu/designs/oa.c. 1994S. Addelman and O. Kempthorne (1961) Annals of Mathematical Statistics, Vol 32 pp 1167-1176.
See Also
Other methods to create orthogonal arrays [createBoseBush()],[createBose()], [createAddelKemp3()],[createAddelKempN()], [createBusht()], [createBoseBushl()]
Examples
A <- createAddelKemp(3, 3, TRUE)B <- createAddelKemp(3, 5, FALSE)Create an orthogonal array using the Addelman-Kempthorne algorithmwith2q^3 rows.
Description
Theaddelkemp3 program producesOA( 2*q^3, k, q, 2 ),k <= 2q^2+2q+1, for prime powersq.q may be an odd prime power, orq may be 2 or 4.
Usage
createAddelKemp3(q, ncol, bRandom = TRUE)Arguments
q | the number of symbols in the array |
ncol | number of parameters or columns |
bRandom | should the array be randomized |
Details
From Owen: An orthogonal arrayA is a matrix ofn rows,kcolumns with every element being one ofq symbols0,...,q-1. The array has strengtht if, in everyn bytsubmatrix, theq^t possible distinct rows, all appearthe same number of times. This number is the indexof the array, commonly denotedlambda. Clearly,lambda*q^t=n. The notation for such an array isOA( n, k, q, t ).
Value
an orthogonal array
References
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, andIntegration in high dimensions.https://lib.stat.cmu.edu/designs/oa.c. 1994S. Addelman and O. Kempthorne (1961) Annals of Mathematical Statistics, Vol 32 pp 1167-1176.
See Also
Other methods to create orthogonal arrays [createBushBush()],[createBose()], [createAddelKemp()],[createAddelKempN()], [createBusht()], [createBoseBushl()]
Examples
A <- createAddelKemp3(3, 3, TRUE)B <- createAddelKemp3(3, 5, FALSE)Create an orthogonal array using the Addelman-Kempthorne algorithm withalternate strength with2q^n rows.
Description
Theaddelkempn program producesOA( 2*q^n, k, q, 2 ),k <= 2(q^n - 1)/(q-1)-1, for prime powersq.q may be an odd prime power, orq may be 2 or 4.
Usage
createAddelKempN(q, ncol, exponent, bRandom = TRUE)Arguments
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 |
Details
From Owen: An orthogonal arrayA is a matrix ofn rows,kcolumns with every element being one ofq symbols0,...,q-1. The array has strengtht if, in everyn bytsubmatrix, theq^t possible distinct rows, all appearthe same number of times. This number is the indexof the array, commonly denotedlambda. Clearly,lambda*q^t=n. The notation for such an array isOA( n, k, q, t ).
Value
an orthogonal array
See Also
Other methods to create orthogonal arrays [createBoseBush()],[createBose()], [createBush()], [createAddelKemp()], [createAddelKemp3()],[createBusht()], [createBoseBushl()]
Examples
A <- createAddelKempN(3, 4, 3, TRUE)B <- createAddelKempN(3, 4, 4, TRUE)Create an orthogonal array using the Bose algorithm.
Description
Thebose programproducesOA( q^2, k, q, 2 ),k <= q+1 for prime powersq.
Usage
createBose(q, ncol, bRandom = TRUE)Arguments
q | the number of symbols in the array |
ncol | number of parameters or columns |
bRandom | should the array be randomized |
Details
From Owen: An orthogonal arrayA is a matrix ofn rows,kcolumns with every element being one ofq symbols0,...,q-1. The array has strengtht if, in everyn bytsubmatrix, theq^t possible distinct rows, all appearthe same number of times. This number is the indexof the array, commonly denotedlambda. Clearly,lambda*q^t=n. The notation for such an array isOA( n, k, q, t ).
Value
an orthogonal array
References
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, andIntegration in high dimensions.https://lib.stat.cmu.edu/designs/oa.c. 1994R.C. Bose (1938) Sankhya Vol 3 pp 323-338
See Also
Other methods to create orthogonal arrays [createBush()],[createBoseBush()], [createAddelKemp()], [createAddelKemp3()],[createAddelKempN()], [createBusht()], [createBoseBushl()]
Examples
A <- createBose(3, 3, FALSE)B <- createBose(5, 4, TRUE)Create an orthogonal array using the Bose-Bush algorithm.
Description
Thebosebush programproducesOA( 2q^2, k, q, 2 ),k <= 2q+1, for powers of 2,q=2^r.
Usage
createBoseBush(q, ncol, bRandom = TRUE)Arguments
q | the number of symbols in the array |
ncol | number of parameters or columns |
bRandom | should the array be randomized |
Details
From Owen: An orthogonal arrayA is a matrix ofn rows,kcolumns with every element being one ofq symbols0,...,q-1. The array has strengtht if, in everyn bytsubmatrix, theq^t possible distinct rows, all appearthe same number of times. This number is the indexof the array, commonly denotedlambda. Clearly,lambda*q^t=n. The notation for such an array isOA( n, k, q, t ).
Value
an orthogonal array
References
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, andIntegration in high dimensions.https://lib.stat.cmu.edu/designs/oa.c. 1994R.C. Bose and K.A. Bush (1952) Annals of Mathematical Statistics, Vol 23 pp 508-524.
See Also
Other methods to create orthogonal arrays [createBush()],[createBose()], [createAddelKemp()], [createAddelKemp3()],[createAddelKempN()], [createBusht()], [createBoseBushl()]
Examples
A <- createBoseBush(4, 3, FALSE)B <- createBoseBush(8, 3, TRUE)Create an orthogonal array using the Bose-Bush algorithm with alternate strength >= 3.
Description
Thebosebushl program producesOA( lambda*q^2, k, q, 2 ),k <= lambda*q+1, for prime powersq andlambda > 1. Bothq andlambda must be powers of the same prime.
Usage
createBoseBushl(q, ncol, lambda, bRandom = TRUE)Arguments
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 |
Details
From Owen: An orthogonal arrayA is a matrix ofn rows,kcolumns with every element being one ofq symbols0,...,q-1. The array has strengtht if, in everyn bytsubmatrix, theq^t possible distinct rows, all appearthe same number of times. This number is the indexof the array, commonly denotedlambda. Clearly,lambda*q^t=n. The notation for such an array isOA( n, k, q, t ).
Value
an orthogonal array
References
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, andIntegration in high dimensions.https://lib.stat.cmu.edu/designs/oa.c. 1994R.C. Bose and K.A. Bush (1952) Annals of Mathematical Statistics, Vol 23 pp 508-524.
See Also
Other methods to create orthogonal arrays [createBoseBush()],[createBose()], [createBush()], [createAddelKemp()], [createAddelKemp3()],[createAddelKempN()], [createBusht()]
Examples
A <- createBoseBushl(3, 3, 3, TRUE)B <- createBoseBushl(4, 4, 16, TRUE)Create an orthogonal array using the Bush algorithm.
Description
Thebush programproducesOA( q^3, k, q, 3 ),k <= q+1 for prime powersq.
Usage
createBush(q, ncol, bRandom = TRUE)Arguments
q | the number of symbols in the array |
ncol | number of parameters or columns |
bRandom | should the array be randomized |
Details
From Owen: An orthogonal arrayA is a matrix ofn rows,kcolumns with every element being one ofq symbols0,...,q-1. The array has strengtht if, in everyn bytsubmatrix, theq^t possible distinct rows, all appearthe same number of times. This number is the indexof the array, commonly denotedlambda. Clearly,lambda*q^t=n. The notation for such an array isOA( n, k, q, t ).
Value
an orthogonal array
References
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, andIntegration in high dimensions.https://lib.stat.cmu.edu/designs/oa.c. 1994K.A. Bush (1952) Annals of Mathematical Statistics, Vol 23 pp 426-434
See Also
Other methods to create orthogonal arrays [createBoseBush()],[createBose()], [createAddelKemp()], [createAddelKemp3()],[createAddelKempN()], [createBusht()], [createBoseBushl()]
Examples
A <- createBush(3, 3, FALSE)B <- createBush(4, 5, TRUE)Create an orthogonal array using the Bush algorithm with alternate strength.
Description
Thebusht program producesOA( q^t, k, q, t ),k <= q+1,t>=3,for prime powersq.
Usage
createBusht(q, ncol, strength, bRandom = TRUE)Arguments
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 |
Details
From Owen: An orthogonal arrayA is a matrix ofn rows,kcolumns with every element being one ofq symbols0,...,q-1. The array has strengtht if, in everyn bytsubmatrix, theq^t possible distinct rows, all appearthe same number of times. This number is the indexof the array, commonly denotedlambda. Clearly,lambda*q^t=n. The notation for such an array isOA( n, k, q, t ).
Value
an orthogonal array
References
Owen, Art. Orthogonal Arrays for: Computer Experiments, Visualizations, andIntegration in high dimensions.https://lib.stat.cmu.edu/designs/oa.c. 1994K.A. Bush (1952) Annals of Mathematical Statistics, Vol 23 pp 426-434
See Also
Other methods to create orthogonal arrays [createBoseBush()],[createBose()], [createAddelKemp()], [createAddelKemp3()],[createAddelKempN()], [createBoseBushl()]
Examples
set.seed(1234)A <- createBusht(3, 4, 2, TRUE)B <- createBusht(3, 4, 3, FALSE)G <- createBusht(3, 4, 3, TRUE)Create a Galois field
Description
Create a Galois field
Usage
create_galois_field(q)Arguments
q | The order of the Galois Field q = p^n |
Value
a GaloisField object containing
- n
q = p^n
- p
The prime modulus of the field q=p^n
- q
The order of the Galois Field q = p^n.
qmust be a prime power.- xton
coefficients of the characteristic polynomial where the first coefficient is on $x^0$, the second is on $x^1$ and so on
- inv
An index for which row of
poly(zero based) is the multiplicative inverse of this row. AnNAindicates that this row ofpolyhas 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- neg
An index for which row of
poly(zero based) is the negative or additive inverse of this row. AnNAindicates that this row ofpolyhas 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- root
An index for which row of
poly(zero based) is the square root of this row. AnNAindicates that this row ofpolyhas 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- plus
sum table of the Galois Field
- times
multiplication table of the Galois Field
- poly
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
Examples
gf <- create_galois_field(4);Create an orthogonal array Latin hypercube
Description
Create an orthogonal array Latin hypercube
Usage
create_oalhs(n, k, bChooseLargerDesign, bverbose)Arguments
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 |
Value
a numeric matrix which is an orthogonal array Latin hypercube sample
Examples
set.seed(34)A <- create_oalhs(9, 4, TRUE, FALSE)B <- create_oalhs(9, 4, TRUE, FALSE)Latin Hypercube Sampling with a Genetic Algorithm
Description
Draws a Latin Hypercube Sample from a set of uniform distributions for use increating a Latin Hypercube Design. This function attempts to optimize thesample with respect to the S optimality criterion through a genetic typealgorithm.
Usage
geneticLHS( n = 10, k = 2, pop = 100, gen = 4, pMut = 0.1, criterium = "S", verbose = FALSE)Arguments
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 |
Details
Latin hypercube sampling (LHS) was developed to generate a distributionof collections of parameter values from a multidimensional distribution.A square grid containing possible sample points is a Latin square iff thereis only one sample in each row and each column. A Latin hypercube is thegeneralisation of this concept to an arbitrary number of dimensions. Whensampling a function ofk variables, the range of each variable is dividedinton equally probable intervals.n sample points are then drawn such that aLatin Hypercube is created. Latin Hypercube sampling generates more efficientestimates of desired parameters than simple Monte Carlo sampling.
This program generates a Latin Hypercube Sample by creating random permutationsof the firstn integers in each ofk columns and then transforming thoseintegers into n sections of a standard uniform distribution. Random values arethen 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 havedifferent distributions.
S-optimality seeks to maximize the mean distance from each design point to allthe other points in the design, so the points are as spread out as possible.
Genetic Algorithm:
Generate
poprandom latin hypercube designs of sizenbykCalculate 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
pMutpercent of the time. The mutation is accomplished by swtching two elements in a column
Value
Ann byk Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
Author(s)
Rob Carnell
References
Stocki, R. (2005) A method to improve design reliability using optimal Latin hypercube samplingComputer Assisted Mechanics and Engineering Sciences12, 87–105.
Stein, M. (1987) Large Sample Properties of Simulations Using Latin Hypercube Sampling.Technometrics.29, 143–151.
See Also
[randomLHS()], [improvedLHS()], [maximinLHS()],and [optimumLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()][optSeededLHS()], and [augtmentLHS()] to modify and augment existing designs.
Examples
set.seed(1234)A <- geneticLHS(4, 3, 50, 5, .25)Get version information for all libraries in the lhs package
Description
Get version information for all libraries in the lhs package
Usage
get_library_versions()Value
a character string containing the versions
Examples
get_library_versions()Improved Latin Hypercube Sample
Description
Draws a Latin Hypercube Sample from a set of uniform distributions for use increating a Latin Hypercube Design. This function attempts to optimize thesample with respect to an optimum euclidean distance between design points.
Usage
improvedLHS(n, k, dup = 1)Arguments
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 thesearch. A multiple of the number of remaining points than can be added. |
Details
Latin hypercube sampling (LHS) was developed to generate a distributionof collections of parameter values from a multidimensional distribution.A square grid containing possible sample points is a Latin square iff thereis only one sample in each row and each column. A Latin hypercube is thegeneralisation of this concept to an arbitrary number of dimensions. Whensampling a function ofk variables, the range of each variable is dividedinton equally probable intervals.n sample points are then drawn such that aLatin Hypercube is created. Latin Hypercube sampling generates more efficientestimates of desired parameters than simple Monte Carlo sampling.
This program generates a Latin Hypercube Sample by creating random permutationsof the firstn integers in each ofk columns and then transforming thoseintegers into n sections of a standard uniform distribution. Random values arethen 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 havedifferent distributions.
This function attempts to optimize the sample with respect to an optimumeuclidean distance between design points.
Optimum distance = frac{n}{n^{\frac{1.0}{k}}}
Value
Ann byk Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
References
Beachkofski, B., Grandhi, R. (2002) Improved Distributed Hypercube SamplingAmerican Institute of Aeronautics and Astronautics Paper1274.
This function is based on the MATLAB program written by John Burkardt and modified 16 Feb 2005https://people.math.sc.edu/Burkardt/m_src/ihs/ihs.html
See Also
[randomLHS()], [geneticLHS()], [maximinLHS()], and [optimumLHS()]to generate Latin Hypercube Samples. [optAugmentLHS()], [optSeededLHS()], and[augmentLHS()] to modify and augment existing designs.
Examples
set.seed(1234)A <- improvedLHS(4, 3, 2)Maximin Latin Hypercube Sample
Description
Draws a Latin Hypercube Sample from a set of uniform distributions for use increating a Latin Hypercube Design. This function attempts to optimize thesample by maximizing the minium distance between design points (maximin criteria).
Usage
maximinLHS( n, k, method = "build", dup = 1, eps = 0.05, maxIter = 100, optimize.on = "grid", debug = FALSE)Arguments
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 thesearch. A multiple of the number of remaining points than can beadded. 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 |
Details
Latin hypercube sampling (LHS) was developed to generate a distributionof collections of parameter values from a multidimensional distribution.A square grid containing possible sample points is a Latin square iff thereis only one sample in each row and each column. A Latin hypercube is thegeneralisation of this concept to an arbitrary number of dimensions. Whensampling a function ofk variables, the range of each variable is dividedinton equally probable intervals.n sample points are then drawn such that aLatin Hypercube is created. Latin Hypercube sampling generates more efficientestimates of desired parameters than simple Monte Carlo sampling.
This program generates a Latin Hypercube Sample by creating random permutationsof the firstn integers in each ofk columns and then transforming thoseintegers into n sections of a standard uniform distribution. Random values arethen 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 havedifferent distributions.
Here, values are added to the design one by one such that the maximin criteria issatisfied.
Value
Ann byk Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
References
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 2005https://people.math.sc.edu/Burkardt/m_src/ihs/ihs.html
See Also
[randomLHS()], [geneticLHS()], [improvedLHS()] and [optimumLHS()]to generate Latin Hypercube Samples. [optAugmentLHS()], [optSeededLHS()], and[augmentLHS()] to modify and augment existing designs.
Examples
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
Description
Create a Latin hypercube from an orthogonal array
Usage
oa_to_oalhs(n, k, oa)Arguments
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 |
Value
a numeric matrix which is a Latin hypercube sample
Examples
oa <- createBose(3, 4, TRUE)B <- oa_to_oalhs(9, 4, oa)Optimal Augmented Latin Hypercube Sample
Description
Augments an existing Latin Hypercube Sample, adding points to the design, whilemaintaining thelatin properties of the design. This function attempts toadd the points to the design in an optimal way.
Usage
optAugmentLHS(lhs, m = 1, mult = 2)Arguments
lhs | The Latin Hypercube Design to which points are to be added |
m | The number of additional points to add to matrix |
mult |
|
Details
Augments an existing Latin Hypercube Sample, adding points to the design, whilemaintaining thelatin properties of the design. This function attempts toadd 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 allthe other points in the design, so the points are as spread out as possible.
Value
Ann byk Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
References
Stein, M. (1987) Large Sample Properties of Simulations Using Latin Hypercube Sampling.Technometrics.29, 143–151.
See Also
[randomLHS()], [geneticLHS()], [improvedLHS()], [maximinLHS()], and[optimumLHS()] to generate Latin Hypercube Samples. [optSeededLHS()] and[augmentLHS()] to modify and augment existing designs.
Examples
set.seed(1234)a <- randomLHS(4,3)b <- optAugmentLHS(a, 2, 3)Optimum Seeded Latin Hypercube Sample
Description
Augments an existing Latin Hypercube Sample, adding points to the design, whilemaintaining thelatin properties of the design. This function then uses thecolumnwise pairwise (CP) algoritm to optimize the design. The original design is not necessarily maintained.
Usage
optSeededLHS(seed, m = 0, maxSweeps = 2, eps = 0.1, verbose = FALSE)Arguments
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 |
Details
Augments an existing Latin Hypercube Sample, adding points to the design, whilemaintaining thelatin properties of the design. This function then uses theCP algoritm to optimize the design. The original designis not necessarily maintained.
Value
Ann byk Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
References
Stein, M. (1987) Large Sample Properties of Simulations Using Latin Hypercube Sampling.Technometrics.29, 143–151.
See Also
[randomLHS()], [geneticLHS()], [improvedLHS()], [maximinLHS()], and[optimumLHS()] to generate Latin Hypercube Samples. [optAugmentLHS()] and[augmentLHS()] to modify and augment existing designs.
Examples
set.seed(1234) a <- randomLHS(4,3) b <- optSeededLHS(a, 2, 2, .1)Optimum Latin Hypercube Sample
Description
Draws a Latin Hypercube Sample from a set of uniform distributions for use increating a Latin Hypercube Design. This function uses the ColumnwisePairwise (CP) algorithm to generate an optimal design with respect to the Soptimality criterion.
Usage
optimumLHS(n = 10, k = 2, maxSweeps = 2, eps = 0.1, verbose = FALSE)Arguments
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 inoptimality measure is less than eps*100% of the previous value. |
verbose | Print informational messages |
Details
Latin hypercube sampling (LHS) was developed to generate a distributionof collections of parameter values from a multidimensional distribution.A square grid containing possible sample points is a Latin square iff thereis only one sample in each row and each column. A Latin hypercube is thegeneralisation of this concept to an arbitrary number of dimensions. Whensampling a function ofk variables, the range of each variable is dividedinton equally probable intervals.n sample points are then drawn such that aLatin Hypercube is created. Latin Hypercube sampling generates more efficientestimates of desired parameters than simple Monte Carlo sampling.
This program generates a Latin Hypercube Sample by creating random permutationsof the firstn integers in each ofk columns and then transforming thoseintegers into n sections of a standard uniform distribution. Random values arethen 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 havedifferent distributions.
S-optimality seeks to maximize the mean distance from each design point to allthe other points in the design, so the points are as spread out as possible.
This function uses theCP algorithm to generate an optimaldesign with respect to the S optimality criterion.
Value
Ann byk Latin Hypercube Sample matrix with values uniformly distributed on [0,1]
References
Stocki, R. (2005) A method to improve design reliability using optimal Latin hypercube samplingComputer Assisted Mechanics and Engineering Sciences12, 87–105.
See Also
[randomLHS()], [geneticLHS()], [improvedLHS()] and [maximinLHS()]to generate Latin Hypercube Samples. [optAugmentLHS()], [optSeededLHS()], and[augmentLHS()] to modify and augment existing designs.
Examples
A <- optimumLHS(4, 3, 5, .05)Convert polynomial to integer in <code>0..q-1</code>
Description
Convert polynomial to integer in <code>0..q-1</code>
Usage
poly2int(p, n, poly)Arguments
p | modulus |
n | the length of poly |
poly | the polynomial vector |
Value
an integer
Examples
gf <- create_galois_field(4)stopifnot(poly2int(gf$p, gf$n, c(0, 0)) == 0)Multiplication in polynomial representation
Description
Multiplication in polynomial representation
Usage
poly_prod(p, n, xton, p1, p2)Arguments
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 |
Value
the product of p1 and p2
Examples
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
Description
Addition in polynomial representation
Usage
poly_sum(p, n, p1, p2)Arguments
p | modulus |
n | length of polynomial 1 and 2 |
p1 | polynomial vector 1 |
p2 | polynomial vector 2 |
Value
the sum of p1 and p2
Examples
gf <- create_galois_field(4)a <- poly_sum(gf$p, gf$n, c(1, 0), c(0, 1))stopifnot(all(a == c(1, 1)))Quantile Transformations
Description
A collection of functions that transform the margins of a Latin hypercubesample in multiple ways
Usage
qfactor(p, fact)qinteger(p, a, b)qdirichlet(X, alpha)Arguments
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 |
Details
qdirichlet is not an exact quantile function since the quantile of amultivariate distribution is not unique.qdirichlet is also not theindependent quantiles of the marginal distributions sincethose quantiles do not sum to one.qdirichlet is the quantile of theunderlying gamma functions, normalized. This is the same procedure thatis used to generate random deviates from the Dirichlet distribution thereforeit will produce transformed Latin hypercube samples with the intended distribution.
q_factor divides the [0,1] interval intonlevel(fact) equal sectionsand assigns values in those sections to the factor level.
Value
the transformed column or columns
Examples
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)]))Construct a random Latin hypercube design
Description
randomLHS(4,3) returns a 4x3 matrix with each columnconstructed as follows: A random permutation of (1,2,3,4) isgenerated, say (3,1,2,4) for each of K columns. Then a uniformrandom number is picked from each indicated quartile. In thisexample a random number between .5 and .75 is chosen, then one between0 and .25, then one between .25 and .5, finally one between.75 and 1.
Usage
randomLHS(n, k, preserveDraw = FALSE)Arguments
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? |
Value
a Latin hypercube sample
Examples
a <- randomLHS(5, 3)Create a Random Sample of Uniform Integers
Description
Create a Random Sample of Uniform Integers
Usage
runifint(n = 1, min_int = 0, max_int = 1)Arguments
n | The number of samples |
min_int | the minimum integer |
max_int | the maximum integer |
Value
the sample sample of sizen