Latin Hypercube Samples (lhs)  1.0
R, C++, and Rcpp code to generate Latin hypercube samples
All Classes Namespaces Files Functions Variables Typedefs Macros Pages
lhslib Namespace Reference

Classes

struct  invert
 
struct  squareDifference
 

Typedefs

typedef bclib::matrix< int >::size_type msize_type
 
typedef std::vector< int >::size_type vsize_type
 

Functions

void geneticLHS (int n, int k, int pop, int gen, double pMut, const std::string &criterium, bool bVerbose, bclib::matrix< double > &result, bclib::CRandom< double > &oRandom)
 
void improvedLHS (int n, int k, int dup, bclib::matrix< int > &result, bclib::CRandom< double > &oRandom)
 
void maximinLHS (int n, int k, int dup, bclib::matrix< int > &result, bclib::CRandom< double > &oRandom)
 
void optimumLHS (int n, int k, int maxSweeps, double eps, bclib::matrix< int > &outlhs, int optimalityRecordLength, bclib::CRandom< double > &oRandom, bool bVerbose)
 
void optSeededLHS (int n, int k, int maxSweeps, double eps, bclib::matrix< double > &oldHypercube, int optimalityRecordLength, bool bVerbose)
 
void randomLHS (int n, int k, bool bPreserveDraw, bclib::matrix< double > &result, bclib::CRandom< double > &oRandom)
 
void randomLHS (int n, int k, bclib::matrix< int > &result, bclib::CRandom< double > &oRandom)
 
bool isValidLHS (const bclib::matrix< int > &result)
 
bool isValidLHS (const bclib::matrix< double > &result)
 
void initializeAvailableMatrix (bclib::matrix< int > &avail)
 
void runif_std (unsigned int n, std::vector< double > &output, bclib::CRandom< double > &oRandom)
 
template<class T >
void rank (const std::vector< T > &toRank, std::vector< int > &ranks)
 
template<class T >
void lhsPrint (const bclib::matrix< T > &A)
 
template<class T >
calculateDistanceSquared (const std::vector< T > &A, const std::vector< T > &B)
 
template<class T , bool ISROWWISE>
calculateDistanceSquared (const typename bclib::matrixConstIter< T, ISROWWISE > Abegin, const typename bclib::matrixConstIter< T, ISROWWISE > Aend, const typename bclib::matrixConstIter< T, ISROWWISE > Bbegin)
 
template<class T >
void calculateDistance (const bclib::matrix< T > &mat, bclib::matrix< double > &result)
 
template<class T >
double sumInvDistance (const bclib::matrix< T > &A)
 
template<class T >
double sumInvDistance_deprecated (const bclib::matrix< T > &A)
 
template<class T >
void copyMatrix (bclib::matrix< T > &copyTo, const bclib::matrix< T > &copyFrom)
 
template<class T >
double calculateSOptimal (const bclib::matrix< T > &mat)
 
template<class T1 >
void runifint (unsigned int n, T1 min, T1 max, std::vector< T1 > &output, bclib::CRandom< double > &oRandom)
 
template<class T1 >
void runifint (T1 min, T1 max, T1 *output, bclib::CRandom< double > &oRandom)
 

Detailed Description

LHS c++ Library namespace

Typedef Documentation

◆ msize_type

typedef bclib::matrix<int>::size_type lhslib::msize_type

type of size type for use with bclib::matrix<T>

Note
the type of the matrix (i.e. int) is irrelevant for size_type

◆ vsize_type

typedef std::vector<int>::size_type lhslib::vsize_type

type of size type for use with std::vector<T>

Note
the type of the vector (i.e. int) is irrelevant for size_type

Function Documentation

◆ calculateDistance()

template<class T >
void lhslib::calculateDistance ( const bclib::matrix< T > &  mat,
bclib::matrix< double > &  result 
)

Calculate the distance between the rows of a matrix

Parameters
matthe matrix to calculate distances on
resultthe matrix to hold the results of the calculation
Template Parameters
Tthe type of object in the matrix

◆ calculateDistanceSquared() [1/2]

template<class T >
T lhslib::calculateDistanceSquared ( const std::vector< T > &  A,
const std::vector< T > &  B 
)

Calculate the total squared distance between two vectors

Parameters
Athe first vector
Bthe second vector
Template Parameters
Tthe type of the objects in the vector
Returns
the total squared distance

◆ calculateDistanceSquared() [2/2]

template<class T , bool ISROWWISE>
T lhslib::calculateDistanceSquared ( const typename bclib::matrixConstIter< T, ISROWWISE >  Abegin,
const typename bclib::matrixConstIter< T, ISROWWISE >  Aend,
const typename bclib::matrixConstIter< T, ISROWWISE >  Bbegin 
)

Calculate the distance squared between two sequence of numbers

this was primarily implemented to be able to calculate distances between rows of a matrix without having to copy those rows out

Parameters
Abeginthe beginning of the first iterator
Aendthe end of the first iterator
Bbeginthe beginning of the second iterator
Template Parameters
Tthe type of object de-referenced by the iterator
ISROWWISEa boolean to indicate if the iterator operates row-wise in the matrix
Returns
the distance squared

◆ calculateSOptimal()

template<class T >
double lhslib::calculateSOptimal ( const bclib::matrix< T > &  mat)

Calculate the S optimality measure

Parameters
matthe matrix to calculate S optimality for
Template Parameters
thetype of object contained in the matrix
Returns
the S optimality measure

◆ copyMatrix()

template<class T >
void lhslib::copyMatrix ( bclib::matrix< T > &  copyTo,
const bclib::matrix< T > &  copyFrom 
)

Copy a matrix

Parameters
copyTothe matrix to copy to
copyFromthe matrix to copy from
Template Parameters
thetype of object contained in the matrix

◆ geneticLHS()

void lhslib::geneticLHS ( int  n,
int  k,
int  pop,
int  gen,
double  pMut,
const std::string &  criterium,
bool  bVerbose,
bclib::matrix< double > &  result,
bclib::CRandom< double > &  oRandom 
)

Create a latin hypercube sample optimized by some criteria with a genetic algorithm

Parameters
nnumber of rows / samples in the lhs
knumber parameters / columns in the lhs
popthe population of the genetic algorithm in each iteration
genthe number of generations to use
pMutthe mutation rate
criteriumthe optimization criterium
bVerboseshould messages be printed?
resultthe lhs
oRandomthe random number stream

◆ improvedLHS()

void lhslib::improvedLHS ( int  n,
int  k,
int  dup,
bclib::matrix< int > &  result,
bclib::CRandom< double > &  oRandom 
)

Improved Latin hypercube sample algorithm

Parameters
nnumber of rows / samples in the lha
knumber parameters / columns in the lhs
dupA factor that determines the number of candidate points used in the search.
resultthe result matrix
oRandomthe random number stream

◆ initializeAvailableMatrix()

void lhslib::initializeAvailableMatrix ( bclib::matrix< int > &  avail)

Initialize the matrix of available points

Parameters
availthe matrix of available points

◆ isValidLHS() [1/2]

bool lhslib::isValidLHS ( const bclib::matrix< double > &  result)

is the Latin hypercube sample valid?

Parameters
resultthe latin hypercube sample
Returns
the result of the validity check

◆ isValidLHS() [2/2]

bool lhslib::isValidLHS ( const bclib::matrix< int > &  result)

is the Latin hypercube sample valid

Parameters
resultthe latin hypercube sample with integer values
Returns
the result of the validity check

◆ lhsPrint()

template<class T >
void lhslib::lhsPrint ( const bclib::matrix< T > &  A)

print the Latin hypercube sample

Parameters
Athe matrix to print
Template Parameters
Tthe type of matrix to print

◆ maximinLHS()

void lhslib::maximinLHS ( int  n,
int  k,
int  dup,
bclib::matrix< int > &  result,
bclib::CRandom< double > &  oRandom 
)

Latin hypercube sample algorithm with maximin criterion

Parameters
nnumber of rows / samples in the lha
knumber parameters / columns in the lhs
dupA factor that determines the number of candidate points used in the search.
resultthe result matrix
oRandomthe random number stream

◆ optimumLHS()

void lhslib::optimumLHS ( int  n,
int  k,
int  maxSweeps,
double  eps,
bclib::matrix< int > &  outlhs,
int  optimalityRecordLength,
bclib::CRandom< double > &  oRandom,
bool  bVerbose 
)

Optimum Latin hypercube sample algorithm

Parameters
nnumber of rows / samples in the lha
knumber parameters / columns in the lhs
maxSweepsthe maximum number of sweeps to use in the algorithm
epsThe optimal stopping criterion
outlhsthe resultant lhs
optimalityRecordLengththe length of a vector used in the calculations
oRandomthe random number stream
bVerboseshould messages be printed?

◆ optSeededLHS()

void lhslib::optSeededLHS ( int  n,
int  k,
int  maxSweeps,
double  eps,
bclib::matrix< double > &  oldHypercube,
int  optimalityRecordLength,
bool  bVerbose 
)

Application of the optimum lhs method to a seeded Latin hypercube

Parameters
nnumber of rows / samples in the lhs
knumber parameters / columns in the lhs
maxSweepsthe maximum number of sweeps to use in the algorithm
epsThe optimal stopping criterion
oldHypercubethe seeded lhs
optimalityRecordLengththe length of a vector used in the calculations
bVerboseshould messages be printed?

◆ randomLHS() [1/2]

void lhslib::randomLHS ( int  n,
int  k,
bclib::matrix< int > &  result,
bclib::CRandom< double > &  oRandom 
)

Create a random latin hypercube sample with integer values

Parameters
nnumber of rows / samples in the lhs
knumber parameters / columns in the lhs
resultthe lhs
oRandomthe random number stream

◆ randomLHS() [2/2]

void lhslib::randomLHS ( int  n,
int  k,
bool  bPreserveDraw,
bclib::matrix< double > &  result,
bclib::CRandom< double > &  oRandom 
)

Create a random latin hypercube sample

Parameters
nnumber of rows / samples in the lhs
knumber parameters / columns in the lhs
bPreserveDrawshould the order of the draw be preserved if less columns are selected
resultthe lhs
oRandomthe random number stream

◆ rank()

template<class T >
void lhslib::rank ( const std::vector< T > &  toRank,
std::vector< int > &  ranks 
)

rank a vector of objects

Parameters
toRankthe vector of objects to rank
ranksthe ranks of the vector of values
Template Parameters
thetype of element in the vectors

◆ runif_std()

void lhslib::runif_std ( unsigned int  n,
std::vector< double > &  output,
bclib::CRandom< double > &  oRandom 
)

Create a vector of random values on (0,1)

Parameters
nthe number of random values
outputthe output vector of random values
oRandomthe pseudo random number generator

◆ runifint() [1/2]

template<class T1 >
void lhslib::runifint ( T1  min,
T1  max,
T1 *  output,
bclib::CRandom< double > &  oRandom 
)

Create a random integer like values

Parameters
minthe minimum integer value
maxthe maximum integer value
outputthe output value
oRandomthe pseudo random number generator
Template Parameters
T1the integer valued type like int, unsigned int, long, long long, unsigned long

◆ runifint() [2/2]

template<class T1 >
void lhslib::runifint ( unsigned int  n,
T1  min,
T1  max,
std::vector< T1 > &  output,
bclib::CRandom< double > &  oRandom 
)

Create a vector of random integer like values

Parameters
nthe length of the random vector
minthe minimum integer value
maxthe maximum integer value
outputthe output vector of values
oRandomthe pseudo random number generator.
Template Parameters
T1the integer valued type like int, unsigned int, long, long long, unsigned long

◆ sumInvDistance()

template<class T >
double lhslib::sumInvDistance ( const bclib::matrix< T > &  A)

sum of the inverse distance between points in a matrix

Parameters
Athe matrix
Template Parameters
Tthe type of object contained in the matrix
Returns
the sum of the inverse distance between points

◆ sumInvDistance_deprecated()

template<class T >
double lhslib::sumInvDistance_deprecated ( const bclib::matrix< T > &  A)

Sum of the inverse distance between points

Parameters
Athe matrix to sum
Template Parameters
Tthe type of object in the matrix
Returns
the sum of the inverse distance between points