Logistic#

#logistic #๋กœ์ง€์Šคํ‹ฑ #sigmoid

ํƒ„์ƒ ๋ฐฐ๊ฒฝ#

๋กœ์ง€์ŠคํŠธํ˜• ๊ฐœ์ฒด๊ตฐ ์„ฑ์žฅ๋ชจ๋ธ(logistic model of population growth)๋Š” ๊ฐœ์ฒด๊ตฐ ์ƒํƒœํ•™์—์„œ ๊ฐœ์ฒด๊ตฐ์˜ ์ฆ๊ฐ€์œจ์„ ์„ค๋ช…ํ•˜๋Š” ๋ชจ๋ธ๋กœ 1838๋…„์— Verhulst๊ฐ€ ๊ณ ์•ˆํ•œ ๋ชจ๋ธ์ด๋‹ค. ์ด ๋ชจ๋ธ์— ๋”ฐ๋ฅด๋ฉด ์ผ์ •ํ•˜์ง€ ์•Š์€ ํ™˜๊ฒฝ, ํ•œ์ •๋œ ์ž์› ๋‚ด์—์„œ์˜ ๊ฐœ์ฒด๊ตฐ ๋ฐ€๋„๊ฐ€ ์ฆ๊ฐ€ํ•จ์— ๋”ฐ๋ผ ์ž์› ์š”๊ตฌ๊ฐ€ ์ฆ๊ฐ€ํ•˜๊ฒŒ ๋˜๊ณ , ์ด๋Š” ๊ฐœ์ฒด๋‹น ์ถœ์ƒ๋ฅ ์˜ ๊ฐ์†Œ, ๊ฐœ์ฒด๋‹น ์‚ฌ๋ง๋ฅ ์˜ ์ฆ๊ฐ€๋ฅผ ๊ฐ€์ ธ์˜ค๊ฒŒ ๋˜๋ฏ€๋กœ ๊ฐœ์ฒด๊ตฐ์˜ ์„ฑ์žฅ์€ ๊ฐ์†Œํ•  ๊ฒƒ์œผ๋กœ ๋ณด์—ฌ์ค€๋‹ค.

\[ \tag{sigmoid} f(x) = \frac{1}{1+e^{-x}} \]

์—ฌ๊ธฐ์„œ x๋Š” input, e๋Š” ์ž์—ฐ์ƒ์ˆ˜(์•ฝ 2.71828)์„ ์˜๋ฏธํ•œ๋‹ค. input์€ ์‹ค์ˆ˜ ์ „์ฒด๋ฅผ ์ •์˜์—ญ์œผ๋กœ ๊ฐ€์ง„๋‹ค. output์€ 0~1 ์‚ฌ์ด์˜ ๊ฐ’์„ ๊ฐ€์ง€๋ฉด์„œ, x=0์ผ ๋•Œ 0.5์ด๋‹ค. x๊ฐ€ ์–‘์˜ ๋ฌดํ•œ๋Œ€๋กœ ๊ฐ€๋ฉด ์ถœ๋ ฅ๊ฐ’์€ 1์— ๊ฐ€๊นŒ์›Œ์ง€๊ณ , ๋ฐ˜๋Œ€๋กœ ์Œ์˜ ๋ฌดํ•œ๋Œ€๋กœ ๊ฐ€๋ฉด ์ถœ๋ ฅ๊ฐ’์€ 0์— ๊ฐ€๊นŒ์›Œ์ง„๋‹ค.

https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Logistic-curve.svg/320px-Logistic-curve.svg.png

Fig. 4 ๋กœ์ง€์ŠคํŠธํ˜• ๊ณก์„ ์˜ ํ‘œ์ค€ํ˜• - ๋”ฑ ๊ทธ๋ƒฅ ์‹œ๊ทธ๋ชจ์ด๋“œ ํ•จ์ˆ˜๊ฐ€ ์ƒ๊ฐ๋‚˜๋ฒ„๋ฆฌ๋Š” ๋ชจ์–‘์ด๋‹ค.#

์‹œ๊ทธ๋ชจ์ด๋“œ ํ•จ์ˆ˜๋Š” ๋ฏธ๋ถ„์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ, ๋ฏธ๋ถ„ ๊ฒฐ๊ณผ ์—ญ์‹œ ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ฏธ๋ถ„์„ ํ•˜๋ฉด ์•„๋ž˜ ์ˆ˜์‹์ฒ˜๋Ÿผ ๋œ๋‹ค.

\[ \tag{deriative of sigmoid} f`(x) = f(x)(1-f(x)) \]

katex#

\[ h(x) = \frac {1} {1+e^{-x}} \]

chain rule์„ ํ†ตํ•ด์„œ ๊ธฐ๋ณธ์‹์—์„œ derivative ์‹๊นŒ์ง€ ์ดํ•ดํ•ด๋ณด๊ธฐ

\[\begin{split} \begin{equation} \begin{split} h'(x) &= \frac {\partial} {\partial x} h(x) \\ &= \frac {\partial} {\partial x} \Big[ \frac {1} {1+e^{-x}} \Big]=\frac {\partial} {\partial x} (1+e^{-x})^{-1}\\ &= -1 *(1+e^{-x})^{-2}(-e^{-x})\\ &= \frac {-e^{-x}} {-(1+e^{-x})^2} = \frac {e^{-x}} {(1+e^{-x})^2}\\ &= \frac {1} {1+e^{-x}} \frac {e^{-x}} {1+e^{-x}}\\ &= \frac {1} {1+e^{-x}} \frac {1+e^{-x}-1} {1+e^{-x}}\\ &= \frac {1} {1+e^{-x}} \Big[ \frac {(1+e^{-x})} {1+e^{-x}} - \frac {1} {1+e^{-x}} \Big]\\ &= \frac {1} {1+e^{-x}} \Big[ 1 - \frac {1} {1+e^{-x}} \Big]\\ &=h(x)(1 - h(x)) \\ \end{split} \end{equation} \end{split}\]

numpy#


import numpy
import matplotlib.pyplot as plt

def sigmoid(x):
    return 1 / (1+numpy.exp(-x))

def sigmoid_derivative(x,step):
    return (sigmoid(x + step) - sigmoid(x)) / step

def other_derivative(x):
    y = [(1 / (1 + numpy.exp(-i))) * (1 - (1 /(1 + numpy.exp(-i)))) for i in x]
    return y

x = numpy.linspace(-10, 10, 1000)

y1 = sigmoid(x)
y2 = sigmoid_derivative(x, 0.0000000000001)
y3 = other_derivative(x)

plt.plot(x, y1, label='sigmoid')
plt.plot(x, y2, label='derivative')
plt.plot(x, y3, label='other derivative')
plt.legend(loc='upper left')
plt.show()