학회 1주차 세션 과제로 나왔던 문제 !!... 코드 칭찬을 들어서 기분이 넘나뤼 좋았다뤼 ^^... 수학 약한 만큼 열심히 공부해야지 🥲
https://github.com/isdiscodead/BIG_PY_2022/blob/main/LEVEL2_1_Session/SessionWeek1Assignment.ipynb
# y = x^2 함수를 경사하강법을 이용해 y값 0.1 이하가 될 때까지 진행 -> x 값 몇 번 갱신?
x1 = 4
a = 0.1
cnt = 1
def dydx(x) :
return 2*x
def f(x):
return x*x
def gradient_descent(x1, a, cnt) :
x2 = x1 - a*dydx(x1)
cnt += 1
# print(cnt, x2, f(x2))
if (f(x2) <= 0.1) :
return cnt
else :
return gradient_descent(x2, a, cnt)