Logistic#
#logistic #๋ก์ง์คํฑ #sigmoid
ํ์ ๋ฐฐ๊ฒฝ#
๋ก์ง์คํธํ ๊ฐ์ฒด๊ตฐ ์ฑ์ฅ๋ชจ๋ธ(logistic model of population growth)๋ ๊ฐ์ฒด๊ตฐ ์ํํ์์ ๊ฐ์ฒด๊ตฐ์ ์ฆ๊ฐ์จ์ ์ค๋ช ํ๋ ๋ชจ๋ธ๋ก 1838๋ ์ Verhulst๊ฐ ๊ณ ์ํ ๋ชจ๋ธ์ด๋ค. ์ด ๋ชจ๋ธ์ ๋ฐ๋ฅด๋ฉด ์ผ์ ํ์ง ์์ ํ๊ฒฝ, ํ์ ๋ ์์ ๋ด์์์ ๊ฐ์ฒด๊ตฐ ๋ฐ๋๊ฐ ์ฆ๊ฐํจ์ ๋ฐ๋ผ ์์ ์๊ตฌ๊ฐ ์ฆ๊ฐํ๊ฒ ๋๊ณ , ์ด๋ ๊ฐ์ฒด๋น ์ถ์๋ฅ ์ ๊ฐ์, ๊ฐ์ฒด๋น ์ฌ๋ง๋ฅ ์ ์ฆ๊ฐ๋ฅผ ๊ฐ์ ธ์ค๊ฒ ๋๋ฏ๋ก ๊ฐ์ฒด๊ตฐ์ ์ฑ์ฅ์ ๊ฐ์ํ ๊ฒ์ผ๋ก ๋ณด์ฌ์ค๋ค.
์ฌ๊ธฐ์ x๋ input, e๋ ์์ฐ์์(์ฝ 2.71828)์ ์๋ฏธํ๋ค. input์ ์ค์ ์ ์ฒด๋ฅผ ์ ์์ญ์ผ๋ก ๊ฐ์ง๋ค. output์ 0~1 ์ฌ์ด์ ๊ฐ์ ๊ฐ์ง๋ฉด์, x=0์ผ ๋ 0.5์ด๋ค. x๊ฐ ์์ ๋ฌดํ๋๋ก ๊ฐ๋ฉด ์ถ๋ ฅ๊ฐ์ 1์ ๊ฐ๊น์์ง๊ณ , ๋ฐ๋๋ก ์์ ๋ฌดํ๋๋ก ๊ฐ๋ฉด ์ถ๋ ฅ๊ฐ์ 0์ ๊ฐ๊น์์ง๋ค.
์๊ทธ๋ชจ์ด๋ ํจ์๋ ๋ฏธ๋ถ์ด ๊ฐ๋ฅํ๋ฉฐ, ๋ฏธ๋ถ ๊ฒฐ๊ณผ ์ญ์ ํด๋น ํจ์๋ฅผ ์ด์ฉํด์ ํํํ ์ ์๋ค. ๋ฏธ๋ถ์ ํ๋ฉด ์๋ ์์์ฒ๋ผ ๋๋ค.
katex#
chain rule์ ํตํด์ ๊ธฐ๋ณธ์์์ derivative ์๊น์ง ์ดํดํด๋ณด๊ธฐ
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()