bertcarnell / lhslib

Latin hypercube sampling code for the lhs pacakge in the statistical software package R (www.r-project.org)
GNU General Public License v2.0
9 stars 1 forks source link
c-plus-plus latin-hypercube-sampling r rcpp

lhslib

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
Build Status Build status codecov CMake CodeQL CppLinter

Connections to Other Projects

Documentation

The API is primarily documented through the Doxygen documentation supplied here.

Examples

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.

randomLHS Algorithm

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);

improvedLHS Algorithm

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);

maximinLHS Algorithm

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);

optimumLHS Algorithm

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);

geneticLHS Algorithm

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);