{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Let the covariance matrix be "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "A"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", let "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "V"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " be matrix of eigenvectors, and let "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "W"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " be the diagonal matrix of eigenvalues such that "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "V W V^T = A",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When all of the eigenvalues are strictly positive, whitening of a data point "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is performed by computing "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x^T (V W^{-1/2})"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", where the inverse square root can be taken element-wise. "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\log\\det{A}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is calculated as  "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "tr(\\log{W})"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", where the "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\log"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " operation is performed element-wise."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "Covariance",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.stats._covariance:Covariance"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " class supports singular covariance matrices. When computing "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "_log_pdet"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", non-positive eigenvalues are ignored. Whitening is not well defined when the point to be whitened does not lie in the span of the columns of the covariance matrix. The convention taken here is to treat the inverse square root of non-positive eigenvalues as zeros."
            }
          ]
        }
      ],
      "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": "Representation of a covariance provided via eigendecomposition"
            }
          ]
        }
      ],
      "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": "eigendecomposition",
              "annotation": "sequence",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A sequence (nominally a tuple) containing the eigenvalue and eigenvector arrays as computed by "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.linalg.eigh",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.linalg._decomp:eigh"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.linalg.eigh",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.linalg:eigh"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "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/_covariance.py",
  "item_line": 252,
  "item_type": "staticmethod",
  "aliases": [
    "scipy.stats.Covariance.from_eigendecomposition"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Prepare a symmetric positive definite covariance matrix ``A`` and a\ndata point ``x``.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy import stats\nrng = np.random.default_rng()\nn = 5\nA = rng.random(size=(n, n))\nA = A @ A.T  # make the covariance symmetric positive definite\nx = rng.random(size=n)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nPerform the eigendecomposition of ``A`` and create the `Covariance`\nobject.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "w, v = np.linalg.eigh(A)\ncov = stats.Covariance.from_eigendecomposition((w, v))\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCompare the functionality of the `Covariance` object against\nreference implementations.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "res = cov.whiten(x)\nref = x @ (v @ np.diag(w**-0.5))\nnp.allclose(res, ref)\nres = cov.log_pdet\nref = np.linalg.slogdet(A)[-1]\nnp.allclose(res, ref)\n",
        "execution_status": "success"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "eigendecomposition",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "from_eigendecomposition"
  },
  "references": null,
  "qa": "scipy.stats._covariance:Covariance.from_eigendecomposition",
  "arbitrary": [],
  "local_refs": [
    "eigendecomposition"
  ]
}