기본 콘텐츠로 건너뛰기

라벨이 gamma인 게시물 표시

[matplotlib]quiver()함수

[data analysis] 감마분포(Gamma Distribution)

감마분포(Gamma Distribution) 확률은 전체 경우의 수 중에서 특정 시건의 비율이므로 확률을 계산하는데 있어 전체 경우의 수를 산정하는 것이 중요합니다. 이산변수의 경우 전체 경우의 수는 계승(factorial)을 사용하여 계산합니다. 연속변수의 경우에서 랜덤변수는 셀수 있는 수가 아니므로 계승을 직접적으로 사용할 수 없습니다. 대신에 계승에 대응하는 적분식을 사용하는데 이 부분을 감마함수 (식 1)로 대체할 수 있습니다. 감마함수를 기본으로 하는 감마분포는 지수 분포와 정규분포와 관련된 분포입니다. 감마함수 Γ(x)로 나타내는 감마함수는 양의 정수 영역에서 factorial 함수의 형태를 가지며 식 1과 같이 정의합니다. 이 식의 첫번째는 이산변수, 두번째는 연속변수를 위한 함수입니다. \begin{align}\tag{1} \Gamma(n)&=(n-1)! , \quad\quad n \in \{1,2,3, \cdots \}\\ &=(n-1)\Gamma(n-1)\\ &=\int^n_0 x^{n-1}e^{-x} ,\quad n > 0 \end{align} (식 1) 예 1) n = 10인 이산변수와 연속변수의 factorial과 감마함수를 계산합니다. factorial은 numpy 또는 scipy의 math 모듈의 factorial() 함수로 계산할 수 있으며 위의 감마함수는 scipy.special의 gamma() 함수로 계산할 수 있습니다. 또한 이 계산은 sympy 패키지의 symbol() 함수와 intergrate() 함수를 사용하여 수행할 수 있습니다. import numpy as np import pandas as pd import matplotlib.pyplot as plt from scipy import stats from sympy import * np.math.factorial(10-1) 362880 from scipy import specia...

Gamma , Chi square and F distribution

Contents Gamma Distribution Gamma function Gamma distribution Chi-square distribution F distribution Gamma Distribution Since the probability is the ratio of the target cases to the total number of cases, it is important to calculate the total number of cases in calculating the probability. For discrete variables, the total number of cases is calculated using factorial. In the case of continuous variables, the factorial cannot be calculated directly because random variables are not countable. Instead, an integral expression corresponding to factorial is used, which can be replaced with gamma function . Therefore, the gamma distribution based on the gamma function is a distribution related to the exponential distribution and the normal distribution and is used in various fields. Gamma function The gamma function is expressed as Γ(x) and has the form of a factorial function in the realm of natural numbers, and is defined as Equation 1 for discrete and continuous va...

[sympy] Sympy객체의 표현을 위한 함수들

Sympy객체의 표현을 위한 함수들 General simplify(x): 식 x(sympy 객체)를 간단히 정리 합니다. import numpy as np from sympy import * x=symbols("x") a=sin(x)**2+cos(x)**2 a $\sin^{2}{\left(x \right)} + \cos^{2}{\left(x \right)}$ simplify(a) 1 simplify(b) $\frac{x^{3} + x^{2} - x - 1}{x^{2} + 2 x + 1}$ simplify(b) x - 1 c=gamma(x)/gamma(x-2) c $\frac{\Gamma\left(x\right)}{\Gamma\left(x - 2\right)}$ simplify(c) $\displaystyle \left(x - 2\right) \left(x - 1\right)$ 위의 예들 중 객체 c의 감마함수(gamma(x))는 확률분포 등 여러 부분에서 사용되는 표현식으로 다음과 같이 정의 됩니다. 감마함수는 음이 아닌 정수를 제외한 모든 수에서 정의됩니다. 식 1과 같이 자연수에서 감마함수는 factorial(!), 부동소수(양의 실수)인 경우 적분을 적용하여 계산합니다. $$\tag{식 1}\Gamma(n) =\begin{cases}(n-1)!& n:\text{자연수}\\\int^\infty_0x^{n-1}e^{-x}\,dx& n:\text{부동소수}\end{cases}$$ x=symbols('x') gamma(x).subs(x,4) $\displaystyle 6$ factorial 계산은 math.factorial() 함수를 사용할 수 있습니다. import math math.factorial(3) 6 a=gamma(x).subs(x,4.5) a.evalf(3) 11.6 simpilfy() 함수의 알고리즘은 식에서 공통사항을 찾아 정리하...