{
  "__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": ", its precision matrix be "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "P = A^{-1}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "L"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " be the lower Cholesky factor such that "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "L L^T = P"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". 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 L"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\log\\det{A}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is calculated as "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "-2tr(\\log{L})"
            },
            {
              "__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 does not support singular covariance matrices because the precision matrix does not exist for a singular covariance matrix."
            }
          ]
        }
      ],
      "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": "Return a representation of a covariance from its precision matrix."
            }
          ]
        }
      ],
      "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": "precision",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The precision matrix; that is, the inverse of a square, symmetric, positive definite covariance matrix."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "covariance",
              "annotation": "array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The square, symmetric, positive definite covariance matrix. If not provided, this may need to be calculated (e.g. to evaluate the cumulative distribution function of "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "scipy.stats.multivariate_normal",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ") by inverting "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "precision"
                    },
                    {
                      "__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": 131,
  "item_type": "staticmethod",
  "aliases": [
    "scipy.stats.Covariance.from_precision"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Prepare a symmetric positive definite precision matrix ``P`` and a\ndata point ``x``. (If the precision matrix is not already available,\nconsider the other factory methods of the `Covariance` class.)\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy import stats\nrng = np.random.default_rng()\nn = 5\nP = rng.random(size=(n, n))\nP = P @ P.T  # a precision matrix must be positive definite\nx = rng.random(size=n)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCreate the `Covariance` object.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "cov = stats.Covariance.from_precision(P)\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 @ np.linalg.cholesky(P)\nnp.allclose(res, ref)\nres = cov.log_pdet\nref = -np.linalg.slogdet(P)[-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": "precision",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "covariance",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "from_precision"
  },
  "references": null,
  "qa": "scipy.stats._covariance:Covariance.from_precision",
  "arbitrary": [],
  "local_refs": [
    "covariance",
    "precision"
  ]
}