C++ Latin hypercube sampling code. Used in the lhs
pacakge in the R statistical software (www.r-project.org).
Link to the lhs
project page here.
Linux & MacOS | Windows | Code Coverage | Actions | CodeQL | Linter |
---|---|---|---|---|---|
- oa orthogonal array project
- bclib bertcarnell template library
- lhs package
- R project
- lhs on CRAN
- doxygen
The API is primarily documented through the Doxygen documentation supplied here.
The following code illustrates how the API is called from C++. The bclib::matrix<T>
class is a simple matrix class that only
includes necessary operations (bclib). More
robust matrix templates could be used in the future. lhslib
is the namespace of this project.
int n = 4;
int k = 3;
bool bPreserveDraw = false;
bclib::matrix<double> result = bclib::matrix<double>(n,k);
bclib::CRandomStandardUniform oRandom = bclib::CRandomStandardUniform();
oRandom.setSeed(1976, 1968);
lhslib::randomLHS(n, k, bPreserveDraw, result, oRandom);
int n = 4;
int k = 3;
int dup = 5;
bclib::matrix<int> result = bclib::matrix<int>(n,k);
bclib::CRandomStandardUniform oRandom = bclib::CRandomStandardUniform();
oRandom.setSeed(1976, 1968);
lhslib::improvedLHS(n, k, dup, result, oRandom);
int n = 4;
int k = 3;
int dup = 5;
bclib::matrix<int> result = bclib::matrix<int>(n, k);
bclib::CRandomStandardUniform oRandom = bclib::CRandomStandardUniform();
oRandom.setSeed(1976, 1968);
lhslib::maximinLHS(n, k, dup, result, oRandom);
int n = 4;
int k = 3;
int maxSweeps = 2;
double eps = 0.1;
int jLen = 7; // (4 choose 2) + 1
bclib::matrix<int> result = bclib::matrix<int>(n, k);
bclib::CRandomStandardUniform oRandom = bclib::CRandomStandardUniform();
oRandom.setSeed(1976, 1968);
lhslib::optimumLHS(n, k, maxSweeps, eps, result, jLen, oRandom, false);
int n = 10;
int k = 4;
int pop = 20;
int gen = 5;
double pMut = 0.10;
std::string crit = "S";
bool verbose = false;
bclib::matrix<double> result = bclib::matrix<double>(n, k);
bclib::CRandomStandardUniform oRandom = bclib::CRandomStandardUniform();
oRandom.setSeed(1976, 1968);
lhslib::geneticLHS(n, k, pop, gen, pMut, crit, verbose, result, oRandom);