

Return lengths*(latin_points + 0.5)/num_samples + param_minsĭef get_sym_sample(self, param_mins, param_maxes, num_samples): Raise ValueError("Number of samples must be even")ĭef get_lh_sample(self, param_mins, param_maxes, num_samples): I am mostly looking for any insights regarding my algorithms, as while they are very fast even for large dimensions and sample sizes, I don't doubt improvements exist.
#Latin hypercube sampling code
I am aware that my project structure is probably overkill for the amount of code here. My code can be seen along with specification and performance tests here, although not the visual tests at the moment. Also, the symmetric algorithm doesn't really work properly for odd numbers of samples, so I have outright blocked such samples from being generated. The code can produce either random Latin hypercubes or a rather nongeneral set of symmetric ones (I am convinced my second algorithm cannot in principle generate any possible symmetric Latin hypercube, just a specific type). Statistical tests of higher dimensional cases have convinced me it works successfully there as well. I have tested the code below both using automated tests and by visual inspection of the results for the trivial 2D case. Latin hypercube samples are used for the pre-computation instead of a grid, with the idea that they will more efficiently sample the behavior of the function and result in lower interpolation errors. I pre-generate a list of values for this function at a set of points and use interpolation over the parameters to extend this list to any desired point within a set range. The condensed version of why I want to do this is that I want to evaluate a function which is expensive to compute, and depends on many parameters. For 2D and n=4, this is an example of a symmetric Latin hypercube: | |x| | | , n-1-k), where n is the number of samples. , k), for some integer indices i,j,k, then it also has the sample (n-1-i, n-1-j. One way of expressing this condition, is that (if the samples are zero-indexed) if the hypercube has the sample (i, j. This property essentially means that the hypercube is invariant under spatial inversion. I am also interested in generating a special type of Latin hypercube called a symmetric Latin hypercube. Concatenating these together into a DxN matrix gives a list of coordinates which will form a Latin hypercube. One algorithm for generating this is to generate D random permutations of the integers 0 through N-1, where D is the number of dimensions and N is the desired number of samples. e.g., for 2 dimensions and 4 total samples, this is a Latin hypercube: | | | |x| Latin hypercubes are essentially collections of points on a hypercube that are placed on a cubic/rectangular grid, which possess the property that no two points share any individual coordinate, and every row/column/higher-dimensional-axis is sampled once. If this is done repeatedly, with many input samples drawn, one can build up a distribution of the output as well as examine correlations between input and output variables.I wrote some code to generate Latin hypercube samples for interpolation over high-dimensional parameter spaces. Many simulation codes have input parameters that are uncertain and can be specified by a distribution, To perform uncertainty analysis and sensitivity analysis, random values are drawn from the input parameter distributions, and the simulation is run with these values to obtain output values. In some cases, the pairing is restricted to obtain specified correlations amongst the input variables. A sample is selected at random with respect to the probability density in each interval, If multiple variables are sampled simultaneously, then values obtained for each are paired in a random manner with the n values of the other variables. In more » LHS, the range of each variable is divided into non-overlapping intervals on the basis of equal probability. LHS is a constrained Monte Carlo sampling scheme. LHS UNIX Library/Standalone uses the Latin Hypercube Sampling method (LHS) to generate samples.
#Latin hypercube sampling software
The LHS samples can be generated either as a callable library (e.g., from within the DAKOTA software framework) or as a standalone capability. Multiple distributions can be sampled simultaneously, with user-specified correlations amongst the input distributions, LHS UNIX Library/ Standalone provides a way to generate multi-variate samples. It performs the sampling by a stratified sampling method called Latin Hypercube Sampling (LHS). The LHS UNIX Library/Standalone software provides the capability to draw random samples from over 30 distribution types.
