{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When LHS is used for integrating a function "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " over "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", LHS is extremely effective on integrands that are nearly additive "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". With a LHS of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " points, the variance of the integral is always lower than plain MC on "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n-1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " points "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". There is a central limit theorem for LHS on the mean and variance of the integral "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "4"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", but not necessarily for optimized LHS due to the randomization."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "A"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is called an orthogonal array of strength "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "t"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " if in each n-row-by-t-column submatrix of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "A"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ": all "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p^t"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " possible distinct rows occur the same number of times. The elements of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "A"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are in the set "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\{0, 1, ..., p-1\\}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", also called symbols. The constraint that "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " must be a prime number is to allow modular arithmetic. Increasing strength adds some symmetry to the sub-projections of a sample. With strength 2, samples are symmetric along the diagonals of 2D sub-projections. This may be undesirable, but on the other hand, the sample dispersion is improved."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Strength 1 (plain LHS) brings an advantage over strength 0 (MC) and strength 2 is a useful increment over strength 1. Going to strength 3 is a smaller increment and scrambled QMC like Sobol', Halton are more performant "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "7"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To create a LHS of strength 2, the orthogonal array "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "A"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is randomized by applying a random, bijective map of the set of symbols onto itself. For example, in column 0, all 0s might become 2; in column 1, all 0s might become 1, etc. Then, for each column "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and symbol "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "j"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", we add a plain, one-dimensional LHS of size "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to the subarray where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "A^i = j"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The resulting matrix is finally divided by "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Latin hypercube sampling (LHS)."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "d",
              "annotation": "int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Dimension of the parameter space."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "scramble",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "When False, center samples within cells of a multi-dimensional grid. Otherwise, samples are randomly placed within cells of the grid."
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "note",
                  "base_type": "note",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "note "
                        }
                      ]
                    },
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Setting "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "scramble=False"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " does not ensure deterministic output. For that, use the "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "rng"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " parameter."
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Default is True."
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionadded",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionadded 1.10.0"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "optimization",
              "annotation": "{None, \"random-cd\", \"lloyd\"}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Whether to use an optimization scheme to improve the quality after sampling. Note that this is a post-processing step that does not guarantee that all properties of the sample will be conserved. Default is None."
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "random-cd"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": ": random permutations of coordinates to lower the   centered discrepancy. The best sample based on the centered   discrepancy is constantly updated. Centered discrepancy-based   sampling shows better space-filling robustness toward 2D and 3D   subprojections compared to using other discrepancy measures."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "lloyd"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": ": Perturb samples using a modified Lloyd-Max algorithm.   The process converges to equally spaced samples."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionadded",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionadded 1.8.0"
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionchanged",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionchanged 1.10.0"
                        }
                      ]
                    },
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Add "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "lloyd"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "."
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "strength",
              "annotation": "{1, 2}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Strength of the LHS. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "strength=1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " produces a plain LHS while "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "strength=2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " produces an orthogonal array based LHS of strength 2 "
                    },
                    {
                      "__type": "FootnoteReference",
                      "__tag": 4066,
                      "label": "7"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "FootnoteReference",
                      "__tag": 4066,
                      "label": "8"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". In that case, only "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n=p**2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " points can be sampled, with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "p"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " a prime number. It also constrains "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "d <= p + 1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Default is 1."
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionadded",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionadded 1.8.0"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "rng",
              "annotation": "`numpy.random.Generator`, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Pseudorandom number generator state. When "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rng"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None, a new "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.random.Generator",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.random._generator:Generator"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is created using entropy from the operating system. Types other than "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.random.Generator",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.random._generator:Generator"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are passed to "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.random.default_rng",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.random:default_rng"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " to instantiate a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Generator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionchanged",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionchanged 1.15.0"
                        }
                      ]
                    },
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "As part of the "
                        },
                        {
                          "__type": "Link",
                          "__tag": 4049,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "SPEC-007"
                            }
                          ],
                          "url": "https://scientific-python.org/specs/spec-0007/",
                          "title": ""
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " transition from use of "
                        },
                        {
                          "__type": "CrossRef",
                          "__tag": 4002,
                          "value": "numpy.random.RandomState",
                          "reference": {
                            "__type": "RefInfo",
                            "__tag": 4000,
                            "module": "numpy",
                            "version": "*",
                            "kind": "api",
                            "path": "numpy.random.mtrand:RandomState"
                          },
                          "kind": "module"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " to "
                        },
                        {
                          "__type": "CrossRef",
                          "__tag": 4002,
                          "value": "numpy.random.Generator",
                          "reference": {
                            "__type": "RefInfo",
                            "__tag": 4000,
                            "module": "numpy",
                            "version": "*",
                            "kind": "api",
                            "path": "numpy.random._generator:Generator"
                          },
                          "kind": "module"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": ", this keyword was changed from "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "seed"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " to "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "rng"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": ". For an interim period, both keywords will continue to work, although only one may be specified at a time. After the interim period, function calls using the "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "seed"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " keyword will emit warnings. Following a deprecation period, the "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "seed"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " keyword will be removed."
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A Latin hypercube sample "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " generates "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " points in "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "[0,1)^{d}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Each univariate marginal distribution is stratified, placing exactly one point in "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "[j/n, (j+1)/n)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "j=0,1,...,n-1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". They are still applicable when "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n << d"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/stats/_qmc.py",
  "item_line": 1286,
  "item_type": "ABCMeta",
  "aliases": [
    "scipy.stats._qmc.LatinHypercube"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Generate samples from a Latin hypercube generator.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.stats import qmc\nsampler = qmc.LatinHypercube(d=2)\nsample = sampler.random(n=5)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "sample\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCompute the quality of the sample using the discrepancy criterion.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "qmc.discrepancy(sample)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nSamples can be scaled to bounds.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "l_bounds = [0, 2]\nu_bounds = [10, 5]\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "qmc.scale(sample, l_bounds, u_bounds)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nBelow are other examples showing alternative ways to construct LHS with\neven better coverage of the space.\n\nUsing a base LHS as a baseline.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "sampler = qmc.LatinHypercube(d=2)\nsample = sampler.random(n=5)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "qmc.discrepancy(sample)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nUse the `optimization` keyword argument to produce a LHS with\nlower discrepancy at higher computational cost.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "sampler = qmc.LatinHypercube(d=2, optimization=\"random-cd\")\nsample = sampler.random(n=5)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "qmc.discrepancy(sample)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nUse the `strength` keyword argument to produce an orthogonal array based\nLHS of strength 2. In this case, the number of sample points must be the\nsquare of a prime number.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "sampler = qmc.LatinHypercube(d=2, strength=2)\nsample = sampler.random(n=9)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "qmc.discrepancy(sample)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nOptions could be combined to produce an optimized centered\northogonal array based LHS. After optimization, the result would not\nbe guaranteed to be of strength 2.\n\n**Real-world example**\n\nIn [9]_, a Latin Hypercube sampling (LHS) strategy was used to sample a\nparameter space to study the importance of each parameter of an epidemic\nmodel. Such analysis is also called a sensitivity analysis.\n\nSince the dimensionality of the problem is high (6), it is computationally\nexpensive to cover the space. When numerical experiments are costly, QMC\nenables analysis that may not be possible if using a grid.\n\nThe six parameters of the model represented the probability of illness,\nthe probability of withdrawal, and four contact probabilities. The\nauthors assumed uniform distributions for all parameters and generated\n50 samples.\n\nUsing `scipy.stats.qmc.LatinHypercube` to replicate the protocol,\nthe first step is to create a sample in the unit hypercube:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.stats import qmc\nsampler = qmc.LatinHypercube(d=6)\nsample = sampler.random(n=50)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThen the sample can be scaled to the appropriate bounds:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "l_bounds = [0.000125, 0.01, 0.0025, 0.05, 0.47, 0.7]\nu_bounds = [0.000375, 0.03, 0.0075, 0.15, 0.87, 0.9]\nsample_scaled = qmc.scale(sample, l_bounds, u_bounds)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nSuch a sample was used to run the model 50 times, and a polynomial\nresponse surface was constructed. This allowed the authors to study the\nrelative importance of each parameter across the range of possibilities\nof every other parameter.\n\nIn this computer experiment, they showed a 14-fold reduction in the\nnumber of samples required to maintain an error below 2% on their\nresponse surface when compared to a grid sampling."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "quasi-monte-carlo",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "quasi-monte-carlo"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "ref"
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "d",
        "annotation": "int | numpy.integer",
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "scramble",
        "annotation": "bool",
        "kind": "KEYWORD_ONLY",
        "default": "True"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "strength",
        "annotation": "int",
        "kind": "KEYWORD_ONLY",
        "default": "1"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "optimization",
        "annotation": "Literal['random-cd', 'lloyd'] | None",
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "rng",
        "annotation": "int | numpy.integer | numpy.random._generator.Generator | numpy.random.mtrand.RandomState | None",
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "seed",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": "None",
    "target_name": "LatinHypercube"
  },
  "references": [
    ".. [1] Mckay et al., \"A Comparison of Three Methods for Selecting Values",
    "   of Input Variables in the Analysis of Output from a Computer Code.\"",
    "   Technometrics, 1979.",
    ".. [2] M. Stein, \"Large sample properties of simulations using Latin",
    "   hypercube sampling.\" Technometrics 29, no. 2: 143-151, 1987.",
    ".. [3] A. B. Owen, \"Monte Carlo variance of scrambled net quadrature.\"",
    "   SIAM Journal on Numerical Analysis 34, no. 5: 1884-1910, 1997",
    ".. [4]  Loh, W.-L. \"On Latin hypercube sampling.\" The annals of statistics",
    "   24, no. 5: 2058-2080, 1996.",
    ".. [5] Fang et al. \"Design and modeling for computer experiments\".",
    "   Computer Science and Data Analysis Series, 2006.",
    ".. [6] Damblin et al., \"Numerical studies of space filling designs:",
    "   optimization of Latin Hypercube Samples and subprojection properties.\"",
    "   Journal of Simulation, 2013.",
    ".. [7] A. B. Owen , \"Orthogonal arrays for computer experiments,",
    "   integration and visualization.\" Statistica Sinica, 1992.",
    ".. [8] B. Tang, \"Orthogonal Array-Based Latin Hypercubes.\"",
    "   Journal of the American Statistical Association, 1993.",
    ".. [9] Seaholm, Susan K. et al. (1988). Latin hypercube sampling and the",
    "   sensitivity analysis of a Monte Carlo epidemic model. Int J Biomed",
    "   Comput, 23(1-2), 97-112. :doi:`10.1016/0020-7101(88)90067-0`"
  ],
  "qa": "scipy.stats._qmc:LatinHypercube",
  "arbitrary": [],
  "local_refs": [
    "d",
    "optimization",
    "rng",
    "scramble",
    "strength"
  ]
}