c44b3890创建于 2022年6月23日历史提交
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7380950b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c08b3b66",
   "metadata": {},
   "source": [
    "## Dirichlet distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ebd00d0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1.2574327653159187"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from scipy.stats import dirichlet\n",
    "quantiles = np.array([0.2, 0.2, 0.6])  # specify quantiles\n",
    "alpha = np.array([0.4, 5, 15])  # specify concentration parameters\n",
    "dirichlet.logpdf(quantiles, alpha)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "688ab01a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2843831684937255"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dirichlet.pdf(quantiles, alpha)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "10438f86",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.01960784, 0.24509804, 0.73529412])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dirichlet.mean(alpha)  # get the mean of the distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "246b9173",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.00089829, 0.00864603, 0.00909517])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dirichlet.var(alpha) # get variance"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ee077a1",
   "metadata": {},
   "source": [
    "## Wishart distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "58477c40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1.74939317, -1.78835126, -1.87158613, -1.97953317])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from scipy.stats import wishart, chi2\n",
    "x = [0.24197072, 0.2186801, 0.17771369, 0.1375705]\n",
    "wishart.logpdf(x, df=3, scale=1.0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}