{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "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": "Base class for numerical integration algorithms (cubatures)."
            }
          ]
        }
      ],
      "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": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Finds an estimate for the integral of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "f"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " over the region described by two arrays "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "a"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "b"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " via "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "estimate",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and find an estimate for the error of this approximation via "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "estimate_error",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If a subclass does not implement its own "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "estimate_error",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", then it will use a default error estimate based on the difference between the estimate over the whole region and the sum of estimates over that region divided into "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "2^ndim"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " subregions."
            }
          ]
        }
      ],
      "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/integrate/_rules/_base.py",
  "item_line": 6,
  "item_type": "class",
  "aliases": [
    "scipy.integrate._rules.Rule"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "In the following, a custom rule is created which uses 3D Genz-Malik cubature for\nthe estimate of the integral, and the difference between this estimate and a less\naccurate estimate using 5-node Gauss-Legendre quadrature as an estimate for the\nerror.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.integrate import cubature\nfrom scipy.integrate._rules import (\n    Rule, ProductNestedFixed, GenzMalikCubature, GaussLegendreQuadrature\n)\ndef f(x, r, alphas):\n    # f(x) = cos(2*pi*r + alpha @ x)\n    # Need to allow r and alphas to be arbitrary shape\n    npoints, ndim = x.shape[0], x.shape[-1]\n    alphas_reshaped = alphas[np.newaxis, :]\n    x_reshaped = x.reshape(npoints, *([1]*(len(alphas.shape) - 1)), ndim)\n    return np.cos(2*np.pi*r + np.sum(alphas_reshaped * x_reshaped, axis=-1))\ngenz = GenzMalikCubature(ndim=3)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "gauss = GaussKronrodQuadrature(npoints=21)\ngauss_3d = ProductNestedFixed([gauss, gauss, gauss])\n",
        "execution_status": "unexpected_exception"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "class CustomRule(Rule):\n    def estimate(self, f, a, b, args=()):\n        return genz.estimate(f, a, b, args)\n    def estimate_error(self, f, a, b, args=()):\n        return np.abs(\n            genz.estimate(f, a, b, args)\n            - gauss_3d.estimate(f, a, b, args)\n        )\nrng = np.random.default_rng()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "res = cubature(\n    f=f,\n    a=np.array([0, 0, 0]),\n    b=np.array([1, 1, 1]),\n    rule=CustomRule(),\n    args=(rng.random((2,)), rng.random((3, 2, 3)))\n)\nres.estimate\n",
        "execution_status": "unexpected_exception"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "FixedRule",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.integrate._rules._base:FixedRule"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "Rule"
  },
  "references": null,
  "qa": "scipy.integrate._rules._base:Rule",
  "arbitrary": [],
  "local_refs": []
}