{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The Sobol' method "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a variance-based Sensitivity Analysis which obtains the contribution of each parameter to the variance of the quantities of interest (QoIs; i.e., the outputs of "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "func"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "). Respective contributions can be used to rank the parameters and also gauge the complexity of the model by computing the model's effective (or mean) dimension."
            }
          ]
        },
        {
          "__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": "Parameters are assumed to be independently distributed. Each parameter can still follow any distribution. In fact, the distribution is very important and should match the real distribution of the parameters."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "It uses a functional decomposition of the variance of the function to explore"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\mathbb{V}(Y) = \\sum_{i}^{d} \\mathbb{V}_i (Y) + \\sum_{i<j}^{d}\n\\mathbb{V}_{ij}(Y) + ... + \\mathbb{V}_{1,2,...,d}(Y),"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "introducing conditional variances:"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\mathbb{V}_i(Y) = \\mathbb{\\mathbb{V}}[\\mathbb{E}(Y|x_i)]\n\\qquad\n\\mathbb{V}_{ij}(Y) = \\mathbb{\\mathbb{V}}[\\mathbb{E}(Y|x_i x_j)]\n- \\mathbb{V}_i(Y) - \\mathbb{V}_j(Y),"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Sobol' indices are expressed as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "S_i = \\frac{\\mathbb{V}_i(Y)}{\\mathbb{V}[Y]}\n\\qquad\nS_{ij} =\\frac{\\mathbb{V}_{ij}(Y)}{\\mathbb{V}[Y]}."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "S_{i}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " corresponds to the first-order term which apprises the contribution of the i-th parameter, while "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "S_{ij}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " corresponds to the second-order term which informs about the contribution of interactions between the i-th and the j-th parameters. These equations can be generalized to compute higher order terms; however, they are expensive to compute and their interpretation is complex. This is why only first order indices are provided."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Total order indices represent the global contribution of the parameters to the variance of the QoI and are defined as:"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "S_{T_i} = S_i + \\sum_j S_{ij} + \\sum_{j,k} S_{ijk} + ...\n= 1 - \\frac{\\mathbb{V}[\\mathbb{E}(Y|x_{\\sim i})]}{\\mathbb{V}[Y]}."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "First order indices sum to at most 1, while total order indices sum to at least 1. If there are no interactions, then first and total order indices are equal, and both first and total order indices sum to 1."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "warning",
          "base_type": "warning",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "warning "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Negative Sobol' values are due to numerical errors. Increasing the number of points "
                },
                {
                  "__type": "ParamRef",
                  "__tag": 4071,
                  "name": "n"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " should help."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The number of sample required to have a good analysis increases with the dimensionality of the problem. e.g. for a 3 dimension problem, consider at minima "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "n >= 2**12"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ". The more complex the model is, the more samples will be needed."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Even for a purely additive model, the indices may not sum to 1 due to numerical noise."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Array API Standard Support"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "sobol_indices",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.stats._sensitivity_analysis:sobol_indices"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "SCIPY_ARRAY_API=1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "====================  ====================  ====================\nLibrary               CPU                   GPU\n====================  ====================  ====================\nNumPy                 ✅                     n/a                 \nCuPy                  n/a                   ⛔                   \nPyTorch               ⛔                     ⛔                   \nJAX                   ⛔                     ⛔                   \nDask                  ⛔                     n/a                 \n====================  ====================  ====================",
          "execution_status": null
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "See "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "dev-arrayapi",
                  "domain": null,
                  "role": "ref",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " for more information."
                }
              ]
            }
          ]
        }
      ],
      "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": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "res",
              "annotation": "SobolResult",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An object with attributes:"
                    }
                  ]
                },
                {
                  "__type": "DefList",
                  "__tag": 4033,
                  "children": [
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "first_order"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "first_order"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "total_order"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "total_order"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "And method:"
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "bootstrap(confidence_level: float, n_resamples: int) -> BootstrapSobolResult"
                    }
                  ]
                },
                {
                  "__type": "Blockquote",
                  "__tag": 4059,
                  "children": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "A method providing confidence intervals on the indices.     See "
                        },
                        {
                          "__type": "CrossRef",
                          "__tag": 4002,
                          "value": "scipy.stats.bootstrap",
                          "reference": {
                            "__type": "RefInfo",
                            "__tag": 4000,
                            "module": "scipy",
                            "version": "*",
                            "kind": "api",
                            "path": "scipy.stats._resampling:bootstrap"
                          },
                          "kind": "module"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " for more details."
                        }
                      ]
                    },
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "The bootstrapping is done on both first and total order indices,     and they are available in "
                        },
                        {
                          "__type": "CrossRef",
                          "__tag": 4002,
                          "value": "BootstrapSobolResult",
                          "reference": {
                            "__type": "LocalRef",
                            "__tag": 4022,
                            "kind": "module",
                            "path": "scipy.stats._sensitivity_analysis:BootstrapSobolResult"
                          },
                          "kind": "module"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " as attributes     "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "first_order"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " and "
                        },
                        {
                          "__type": "InlineCode",
                          "__tag": 4051,
                          "value": "total_order"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "."
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Global sensitivity indices of Sobol'."
            }
          ]
        }
      ],
      "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": "func",
              "annotation": "callable or dict(str, array_like)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "func"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a callable, function to compute the Sobol' indices from. Its signature must be      "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "func(x: ArrayLike) -> ArrayLike",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " of shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(d, n)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and output of shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(s, n)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " where:"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "d"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is the input dimensionality of "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "func"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "   (number of input variables),"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "s"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is the output dimensionality of "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "func"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "   (number of output variables), and"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "n"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is the number of samples (see "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "n"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " below)."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Function evaluation values must be finite."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "func"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a dictionary, contains the function evaluations from three different arrays. Keys must be: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f_A"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f_B"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f_AB"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f_A"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f_B"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " should have a shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(s, n)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f_AB"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " should have a shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(d, s, n)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". This is an advanced feature and misuse can lead to wrong analysis."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "n",
              "annotation": "int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of samples used to generate the matrices "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "A"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "B"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Must be a power of 2. The total number of points at which "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "func"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is evaluated will be "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "n*(d+2)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "dists",
              "annotation": "list(distributions), optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "List of each parameter's distribution. The distribution of parameters depends on the application and should be carefully chosen. Parameters are assumed to be independently distributed, meaning there is no constraint nor relationship between their values."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Distributions must be an instance of a class with a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "ppf"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " method."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Must be specified if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "func"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a callable, and ignored otherwise."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "method",
              "annotation": "Callable or str, default: 'saltelli_2010'",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Method used to compute the first and total Sobol' indices."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If a callable, its signature must be      "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "func(f_A: np.ndarray, f_B: np.ndarray, f_AB: np.ndarray)\n-> Tuple[np.ndarray, np.ndarray]",
                  "execution_status": null
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "with "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f_A, f_B"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " of shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(s, n)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f_AB"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " of shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(d, s, n)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". These arrays contain the function evaluations from three different sets of samples. The output is a tuple of the first and total indices with shape "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(s, d)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". This is an advanced feature and misuse can lead to wrong analysis."
                    }
                  ]
                }
              ]
            },
            {
              "__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": "random_state"
                        },
                        {
                          "__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": "random_state"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " keyword will emit warnings. Following a deprecation period, the "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "random_state"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " keyword will be removed."
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "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/_sensitivity_analysis.py",
  "item_line": 241,
  "item_type": "function",
  "aliases": [
    "scipy.stats.sobol_indices"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "The following is an example with the Ishigami function [6]_\n\n.. math::\n\n    Y(\\mathbf{x}) = \\sin x_1 + 7 \\sin^2 x_2 + 0.1 x_3^4 \\sin x_1,\n\nwith :math:`\\mathbf{x} \\in [-\\pi, \\pi]^3`. This function exhibits strong\nnon-linearity and non-monotonicity.\n\nRemember, Sobol' indices assumes that samples are independently\ndistributed. In this case we use a uniform distribution on each marginals.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.stats import sobol_indices, uniform\nrng = np.random.default_rng()\ndef f_ishigami(x):\n    f_eval = (\n        np.sin(x[0])\n        + 7 * np.sin(x[1])**2\n        + 0.1 * (x[2]**4) * np.sin(x[0])\n    )\n    return f_eval\nindices = sobol_indices(\n    func=f_ishigami, n=1024,\n    dists=[\n        uniform(loc=-np.pi, scale=2*np.pi),\n        uniform(loc=-np.pi, scale=2*np.pi),\n        uniform(loc=-np.pi, scale=2*np.pi)\n    ],\n    rng=rng\n)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "indices.first_order\nindices.total_order\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nConfidence interval can be obtained using bootstrapping.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "boot = indices.bootstrap()\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThen, this information can be easily visualized.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import matplotlib.pyplot as plt\nfig, axs = plt.subplots(1, 2, figsize=(9, 4))\n_ = axs[0].errorbar(\n    [1, 2, 3], indices.first_order, fmt='o',\n    yerr=[\n        indices.first_order - boot.first_order.confidence_interval.low,\n        boot.first_order.confidence_interval.high - indices.first_order\n    ],\n)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "axs[0].set_ylabel(\"First order Sobol' indices\")\naxs[0].set_xlabel('Input parameters')\naxs[0].set_xticks([1, 2, 3])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "_ = axs[1].errorbar(\n    [1, 2, 3], indices.total_order, fmt='o',\n    yerr=[\n        indices.total_order - boot.total_order.confidence_interval.low,\n        boot.total_order.confidence_interval.high - indices.total_order\n    ],\n)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "axs[1].set_ylabel(\"Total order Sobol' indices\")\naxs[1].set_xlabel('Input parameters')\naxs[1].set_xticks([1, 2, 3])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.tight_layout()\nplt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-896728bb561cb560.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n.. note::\n\n    By default, `scipy.stats.uniform` has support ``[0, 1]``.\n    Using the parameters ``loc`` and ``scale``, one obtains the uniform\n    distribution on ``[loc, loc + scale]``.\n\nThis result is particularly interesting because the first order index\n:math:`S_{x_3} = 0` whereas its total order is :math:`S_{T_{x_3}} = 0.244`.\nThis means that higher order interactions with :math:`x_3` are responsible\nfor the difference. Almost 25% of the observed variance\non the QoI is due to the correlations between :math:`x_3` and :math:`x_1`,\nalthough :math:`x_3` by itself has no impact on the QoI.\n\nThe following gives a visual explanation of Sobol' indices on this\nfunction. Let's generate 1024 samples in :math:`[-\\pi, \\pi]^3` and\ncalculate the value of the output.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.stats import qmc\nn_dim = 3\np_labels = ['$x_1$', '$x_2$', '$x_3$']\nsample = qmc.Sobol(d=n_dim, seed=rng).random(1024)\nsample = qmc.scale(\n    sample=sample,\n    l_bounds=[-np.pi, -np.pi, -np.pi],\n    u_bounds=[np.pi, np.pi, np.pi]\n)\noutput = f_ishigami(sample.T)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNow we can do scatter plots of the output with respect to each parameter.\nThis gives a visual way to understand how each parameter impacts the\noutput of the function.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "fig, ax = plt.subplots(1, n_dim, figsize=(12, 4))\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "for i in range(n_dim):\n    xi = sample[:, i]\n    ax[i].scatter(xi, output, marker='+')\n    ax[i].set_xlabel(p_labels[i])\nax[0].set_ylabel('Y')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.tight_layout()\nplt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-36fa33ffb0075d71.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNow Sobol' goes a step further:\nby conditioning the output value by given values of the parameter\n(black lines), the conditional output mean is computed. It corresponds to\nthe term :math:`\\mathbb{E}(Y|x_i)`. Taking the variance of this term gives\nthe numerator of the Sobol' indices.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "mini = np.min(output)\nmaxi = np.max(output)\nn_bins = 10\nbins = np.linspace(-np.pi, np.pi, num=n_bins, endpoint=False)\ndx = bins[1] - bins[0]\nfig, ax = plt.subplots(1, n_dim, figsize=(12, 4))\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "for i in range(n_dim):\n    xi = sample[:, i]\n    ax[i].scatter(xi, output, marker='+')\n    ax[i].set_xlabel(p_labels[i])\n    for bin_ in bins:\n        idx = np.where((bin_ <= xi) & (xi <= bin_ + dx))\n        xi_ = xi[idx]\n        y_ = output[idx]\n        ave_y_ = np.mean(y_)\n        ax[i].plot([bin_ + dx/2] * 2, [mini, maxi], c='k')\n        ax[i].scatter(bin_ + dx/2, ave_y_, c='r')\nax[0].set_ylabel('Y')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.tight_layout()\nplt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-592e9204c2451526.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nLooking at :math:`x_3`, the variance\nof the mean is zero leading to :math:`S_{x_3} = 0`. But we can further\nobserve that the variance of the output is not constant along the parameter\nvalues of :math:`x_3`. This heteroscedasticity is explained by higher order\ninteractions. Moreover, an heteroscedasticity is also noticeable on\n:math:`x_1` leading to an interaction between :math:`x_3` and :math:`x_1`.\nOn :math:`x_2`, the variance seems to be constant and thus null interaction\nwith this parameter can be supposed.\n\nThis case is fairly simple to analyse visually---although it is only a\nqualitative analysis. Nevertheless, when the number of input parameters\nincreases such analysis becomes unrealistic as it would be difficult to\nconclude on high-order terms. Hence the benefit of using Sobol' indices."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "func",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "n",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "dists",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "method",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "saltelli_2010"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "rng",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "random_state",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "sobol_indices"
  },
  "references": [
    ".. [1] Sobol, I. M.. \"Sensitivity analysis for nonlinear mathematical",
    "   models.\" Mathematical Modeling and Computational Experiment, 1:407-414,",
    "   1993.",
    ".. [2] Sobol, I. M. (2001). \"Global sensitivity indices for nonlinear",
    "   mathematical models and their Monte Carlo estimates.\" Mathematics",
    "   and Computers in Simulation, 55(1-3):271-280,",
    "   :doi:`10.1016/S0378-4754(00)00270-6`, 2001.",
    ".. [3] Saltelli, A. \"Making best use of model evaluations to",
    "   compute sensitivity indices.\"  Computer Physics Communications,",
    "   145(2):280-297, :doi:`10.1016/S0010-4655(02)00280-1`, 2002.",
    ".. [4] Saltelli, A., M. Ratto, T. Andres, F. Campolongo, J. Cariboni,",
    "   D. Gatelli, M. Saisana, and S. Tarantola. \"Global Sensitivity Analysis.",
    "   The Primer.\" 2007.",
    ".. [5] Saltelli, A., P. Annoni, I. Azzini, F. Campolongo, M. Ratto, and",
    "   S. Tarantola. \"Variance based sensitivity analysis of model",
    "   output. Design and estimator for the total sensitivity index.\"",
    "   Computer Physics Communications, 181(2):259-270,",
    "   :doi:`10.1016/j.cpc.2009.09.018`, 2010.",
    ".. [6] Ishigami, T. and T. Homma. \"An importance quantification technique",
    "   in uncertainty analysis for computer models.\" IEEE,",
    "   :doi:`10.1109/ISUMA.1990.151285`, 1990."
  ],
  "qa": "scipy.stats._sensitivity_analysis:sobol_indices",
  "arbitrary": [],
  "local_refs": [
    "dists",
    "func",
    "method",
    "n",
    "res",
    "rng"
  ]
}