(problem, N, seed=None)
return result
Generate model inputs using Latin hypercube sampling (LHS).

    Returns a NumPy matrix containing the model inputs generated by Latin
    hypercube sampling.  The resulting matrix contains N rows and D columns,
    where D is the number of parameters.

    Parameters
    ----------
    problem : dict
        The problem definition
    N : int
        The number of samples to generate


    References
    ----------
    .. [1] McKay, M.D., Beckman, R.J., Conover, W.J., 1979.
           A comparison of three methods for selecting values of input
           variables in the analysis of output from a computer code.
           Technometrics 21, 239–245.
           https://doi.org/10.2307/1268522

    .. [2] Iman, R.L., Helton, J.C., Campbell, J.E., 1981.
           An Approach to Sensitivity Analysis of Computer Models:
           Part I—Introduction, Input Variable Selection and
           Preliminary Variable Assessment.
           Journal of Quality Technology 13, 174–183.
           https://doi.org/10.1080/00224065.1981.11978748
Generate model inputs using Latin hypercube sampling (LHS).
Generate model inputs using Latin hypercube sampling ( LHS ) .
def sample(problem, N, seed=None):
    """Generate model inputs using Latin hypercube sampling (LHS).

    Returns a NumPy matrix containing the model inputs generated by Latin
    hypercube sampling.  The resulting matrix contains N rows and D columns,
    where D is the number of parameters.

    Parameters
    ----------
    problem : dict
        The problem definition
    N : int
        The number of samples to generate


    References
    ----------
    .. [1] McKay, M.D., Beckman, R.J., Conover, W.J., 1979.
           A comparison of three methods for selecting values of input
           variables in the analysis of output from a computer code.
           Technometrics 21, 239–245.
           https://doi.org/10.2307/1268522

    .. [2] Iman, R.L., Helton, J.C., Campbell, J.E., 1981.
           An Approach to Sensitivity Analysis of Computer Models:
           Part I—Introduction, Input Variable Selection and
           Preliminary Variable Assessment.
           Journal of Quality Technology 13, 174–183.
           https://doi.org/10.1080/00224065.1981.11978748

    """
    num_samples = N

    if seed:
        np.random.seed(seed)

    groups = problem.get('groups')
    if groups:
        num_groups = len(set(groups))
        G, group_names = compute_groups_matrix(groups)
    else:
        num_groups = problem['num_vars']

    result = np.empty([num_samples, problem['num_vars']])
    temp = np.empty([num_samples])
    d = 1.0 / num_samples

    temp = np.array([np.random.uniform(low=sample * d,
                                       high=(sample + 1) * d,
                                       size=num_groups)
                     for sample in range(num_samples)])

    for group in range(num_groups):

        np.random.shuffle(temp[:, group])

        for sample in range(num_samples):
            if groups:
                grouped_variables = np.where(G[:, group] == 1)
                result[sample, grouped_variables[0]] = temp[sample, group]
            else:
                result[sample, group] = temp[sample, group]

    result = scale_samples(result, problem)

    return result
def sample ( problem , N , seed = None ) : num_samples = N if seed : np . random . seed ( seed ) groups = problem . get ( 'groups' ) if groups : num_groups = len ( set ( groups ) ) G , group_names = compute_groups_matrix ( groups ) else : num_groups = problem [ 'num_vars' ] result = np . empty ( [ num_samples , problem [ 'num_vars' ] ] ) temp = np . empty ( [ num_samples ] ) d = 1.0 / num_samples temp = np . array ( [ np . random . uniform ( low = sample * d , high = ( sample + 1 ) * d , size = num_groups ) for sample in range ( num_samples ) ] ) for group in range ( num_groups ) : np . random . shuffle ( temp [ : , group ] ) for sample in range ( num_samples ) : if groups : grouped_variables = np . where ( G [ : , group ] == 1 ) result [ sample , grouped_variables [ 0 ] ] = temp [ sample , group ] else : result [ sample , group ] = temp [ sample , group ] result = scale_samples ( result , problem ) return result