Main Content

lhsdesign

Latin hypercube sample

    Description

    example

    X = lhsdesign(n,p) returns a Latin hypercube sample matrix of size n-by-p. For each column of X, the n values are randomly distributed with one from each interval (0,1/n), (1/n,2/n), ..., (1 - 1/n,1), and randomly permuted.

    example

    X = lhsdesign(n,p,Name,Value) modifies the resulting design using one or more name-value pair arguments. For example, you can obtain a discrete design by specifying 'Smooth','off'.

    Examples

    collapse all

    Create a Latin hypercube sample of 10 rows and 4 columns.

    rng default % For reproducibility
    X = lhsdesign(10,4)
    X = 10×4
    
        0.1893    0.2569    0.0147    0.5583
        0.8038    0.1089    0.9378    0.1950
        0.5995    0.6818    0.3649    0.3097
        0.3225    0.8736    0.4487    0.8055
        0.9183    0.9854    0.1598    0.2509
        0.0131    0.3864    0.5924    0.7511
        0.7916    0.7131    0.2760    0.6662
        0.6600    0.5420    0.6877    0.9100
        0.2740    0.0450    0.7816    0.0631
        0.4200    0.4855    0.8760    0.4889
    
    

    Each column of X contains one random number in each interval [0,0.1], [0.1,0.2], [0.2,0.3], [0.3,0.4], [0.4,0.5], [0.5,0.6], [0.6,0.7], [0.7,0.8], [0.8,0.9], and [0.9,1].

    Determine the effects of various name-value pair arguments in lhsdesign. Start with a default design for 10 rows and four columns.

    rng default % For reproducibility
    X = lhsdesign(10,4)
    X = 10×4
    
        0.1893    0.2569    0.0147    0.5583
        0.8038    0.1089    0.9378    0.1950
        0.5995    0.6818    0.3649    0.3097
        0.3225    0.8736    0.4487    0.8055
        0.9183    0.9854    0.1598    0.2509
        0.0131    0.3864    0.5924    0.7511
        0.7916    0.7131    0.2760    0.6662
        0.6600    0.5420    0.6877    0.9100
        0.2740    0.0450    0.7816    0.0631
        0.4200    0.4855    0.8760    0.4889
    
    

    To obtain a discrete design, as opposed to a continuous design, set the 'Smooth' name-value pair argument to 'off'.

    rng default % For reproducibility
    X = lhsdesign(10,4,'Smooth','off')
    X = 10×4
    
        0.2500    0.3500    0.7500    0.8500
        0.1500    0.8500    0.2500    0.3500
        0.8500    0.7500    0.4500    0.7500
        0.9500    0.1500    0.6500    0.1500
        0.0500    0.0500    0.8500    0.9500
        0.4500    0.5500    0.9500    0.4500
        0.3500    0.9500    0.5500    0.0500
        0.5500    0.4500    0.0500    0.2500
        0.6500    0.6500    0.1500    0.6500
        0.7500    0.2500    0.3500    0.5500
    
    

    The resulting design is discrete.

    Calculate the sum of squares of the between-column correlations of the returned design.

    y = corr(X);
    (sum(y(:).^2) - 4)/2 % Subtract 4 to remove the diagonal terms of corr(X)
    ans = 0.4874
    

    Observe the effect of changing the 'Criterion' name-value pair argument to 'correlation', which minimizes the sum of between-column squared correlations. The 'correlation' criterion always gives a discrete design, as if 'Smooth' is set to 'off'.

    rng default % For reproducibility
    X = lhsdesign(10,4,'Criterion','correlation')
    X = 10×4
    
        0.6500    0.0500    0.4500    0.7500
        0.2500    0.3500    0.0500    0.1500
        0.1500    0.9500    0.8500    0.4500
        0.8500    0.5500    0.9500    0.0500
        0.5500    0.2500    0.5500    0.3500
        0.3500    0.4500    0.7500    0.8500
        0.4500    0.1500    0.6500    0.6500
        0.0500    0.6500    0.2500    0.5500
        0.9500    0.8500    0.3500    0.9500
        0.7500    0.7500    0.1500    0.2500
    
    
    y = corr(X);
    (sum(y(:).^2) - 4)/2
    ans = 0.0102
    

    Minimizing the correlations results in a design with much lower sum of squared correlations.

    Specify fewer iterations to improve the criterion.

    rng default % For reproducibility
    X = lhsdesign(10,4,'Criterion','correlation','Iterations',2)
    X = 10×4
    
        0.6500    0.0500    0.4500    0.7500
        0.3500    0.3500    0.0500    0.1500
        0.1500    0.9500    0.8500    0.4500
        0.9500    0.5500    0.9500    0.0500
        0.5500    0.2500    0.5500    0.3500
        0.2500    0.4500    0.7500    0.8500
        0.4500    0.1500    0.6500    0.6500
        0.0500    0.6500    0.2500    0.5500
        0.8500    0.8500    0.3500    0.9500
        0.7500    0.7500    0.1500    0.2500
    
    
    y = corr(X);
    (sum(y(:).^2) - 4)/2
    ans = 0.0328
    

    Lowering the number of iterations results in a worse design (higher sum of squared correlations).

    Input Arguments

    collapse all

    Number of returned samples, specified as a positive integer.

    Example: 24

    Data Types: single | double

    Number of returned variables, specified as a positive integer.

    Example: 4

    Data Types: single | double

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: X = lhsdesign(n,p,'Smooth','off') returns a discrete Latin hypercube design

    Indication for continuous samples, specified as the comma-separated pair consisting of 'Smooth' and 'on' (continuous samples) or 'off' (discrete samples). When this option is 'off', the returned values in each column of X are a random permutation of the values 0.5/n, 1.5/n, …, 1 – 0.5/n.

    Example: 'Smooth','off'

    Data Types: char | string

    Criterion for iterative sample generation, specified as the comma-separated pair consisting of 'Criterion' and 'maximin', 'none', or 'correlation'. The algorithm uses up to Iterations tries to improve the criterion.

    Note

    The 'correlation' criterion gives discrete samples, as if Smooth is set to 'off'.

    CriterionDescription

    'maximin'

    Maximize the minimum distance between points.

    'correlation'

    Minimize the sum of between-column squared correlations.

    'none'

    No iteration

    Example: 'Criterion','correlation'

    Data Types: char | string

    Maximum number of iterations to improve Criterion, specified as the comma-separated pair consisting of 'Iterations' and a positive integer. The algorithm uses up to Iterations tries to improve the criterion.

    Example: 'Iterations',10

    Data Types: single | double

    Version History

    Introduced before R2006a