{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This algorithm is a clean room reimplementation of the algorithm introduced by Woltring in FORTRAN [2]. The original version cannot be used in SciPy source code because of the license issues. The details of the reimplementation are discussed here (available only in Russian) [4]."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If the vector of weights "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "w"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is None, we assume that all the points are equal in terms of weights, and vector of weights is vector of ones."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that in weighted residual sum of squares, weights are not squared: "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\sum\\limits_{i=1}^n w_i\\lvert y_i - f(x_i) \\rvert^2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " while in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "splrep"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " the sum is built from the squared weights."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In cases when the initial problem is ill-posed (for example, the product "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "X^T W X"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "X"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a design matrix is not a positive defined matrix) a ValueError is raised."
            }
          ]
        },
        {
          "__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": "make_smoothing_spline",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.interpolate._bsplines:make_smoothing_spline"
              },
              "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                   ⚠️ no JIT             ⛔                   \nDask                  ⚠️ computes graph     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": "func",
              "annotation": "`BSpline` object",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An object representing a spline in the B-spline basis as a solution of the problem of smoothing splines using the GCV criteria [1] in case "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "lam"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None, otherwise using the given parameter "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "lam"
                    },
                    {
                      "__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": "Create a smoothing B-spline satisfying the Generalized Cross Validation (GCV) criterion."
            }
          ]
        }
      ],
      "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": "x",
              "annotation": "array_like, shape (n,)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Abscissas. "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "n",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must be at least 5."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "y",
              "annotation": "array_like, shape (n, ...)",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Ordinates. "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "n",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must be at least 5."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "w",
              "annotation": "array_like, shape (n,), optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Vector of weights. Default is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "np.ones_like(x)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "lam",
              "annotation": "float, (:math:`\\lambda \\geq 0`), optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Regularization parameter. If "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "lam"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None, then it is found from the GCV criteria. Default is None."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The data axis. Default is zero. The assumption is that "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "y.shape[axis] == n"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", and all other axes of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are batching axes."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute the (coefficients of) smoothing cubic spline function using "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "lam"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to control the tradeoff between the amount of smoothness of the curve and its proximity to the data. In case "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "lam"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is None, using the GCV criteria [1] to find it."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A smoothing spline is found as a solution to the regularized weighted linear regression problem:"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\sum\\limits_{i=1}^n w_i\\lvert y_i - f(x_i) \\rvert^2 +\n\\lambda\\int\\limits_{x_1}^{x_n} (f^{(2)}(u))^2 d u"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a spline function, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "w"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a vector of weights and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\lambda"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a regularization parameter."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "lam"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is None, we use the GCV criteria to find an optimal regularization parameter, otherwise we solve the regularized weighted linear regression problem with given parameter. The parameter controls the tradeoff in the following way: the larger the parameter becomes, the smoother the function gets."
            }
          ]
        }
      ],
      "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/interpolate/_bsplines.py",
  "item_line": 2248,
  "item_type": "function",
  "aliases": [
    "scipy.interpolate.make_smoothing_spline"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Generate some noisy data\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nnp.random.seed(1234)\nn = 200\ndef func(x):\n   return x**3 + x**2 * np.sin(4 * x)\nx = np.sort(np.random.random_sample(n) * 4 - 2)\ny = func(x) + np.random.normal(scale=1.5, size=n)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nMake a smoothing spline function\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.interpolate import make_smoothing_spline\nspl = make_smoothing_spline(x, y)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nPlot both\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import matplotlib.pyplot as plt\ngrid = np.linspace(x[0], x[-1], 400)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.plot(x, y, '.')\nplt.plot(grid, spl(grid), label='Spline')\nplt.plot(grid, func(grid), label='Original function')\nplt.legend(loc='best')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-b77f48254baa5213.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "y",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "w",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "lam",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "0"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "make_smoothing_spline"
  },
  "references": [
    ".. [1] G. Wahba, \"Estimating the smoothing parameter\" in Spline models for",
    "    observational data, Philadelphia, Pennsylvania: Society for Industrial",
    "    and Applied Mathematics, 1990, pp. 45-65.",
    "    :doi:`10.1137/1.9781611970128`",
    ".. [2] H. J. Woltring, A Fortran package for generalized, cross-validatory",
    "    spline smoothing and differentiation, Advances in Engineering",
    "    Software, vol. 8, no. 2, pp. 104-113, 1986.",
    "    :doi:`10.1016/0141-1195(86)90098-7`",
    ".. [3] T. Hastie, J. Friedman, and R. Tisbshirani, \"Smoothing Splines\" in",
    "    The elements of Statistical Learning: Data Mining, Inference, and",
    "    prediction, New York: Springer, 2017, pp. 241-249.",
    "    :doi:`10.1007/978-0-387-84858-7`",
    ".. [4] E. Zemlyanoy, \"Generalized cross-validation smoothing splines\",",
    "    BSc thesis, 2022.",
    "    `<https://www.hse.ru/ba/am/students/diplomas/620910604>`_ (in",
    "    Russian)"
  ],
  "qa": "scipy.interpolate._bsplines:make_smoothing_spline",
  "arbitrary": [],
  "local_refs": [
    "axis",
    "func",
    "lam",
    "w",
    "x",
    "y"
  ]
}