<jupyter_start><jupyter_text>알고리즘 결과 Visualization  Import modules<jupyter_code>import numpy as np
import tensorflow as tf
print(tf.__version__)<jupyter_output>2.4.0-dev20200724<jupyter_text>손실 함수 정의<jupyter_code>def f(x):
    return 0.1*x**4 - 1.5*x**3 + 0.6*x**2 + 1.0*x + 20.0<jupyter_output><empty_output><jupyter_text>손실 함수 미분 정의<jupyter_code>def df_dx(x):
    return 0.4*x**3 - 4.5*x**2 + 1.2*x + 1.0<jupyter_output><empty_output><jupyter_text>Gradient Descent 알고리즘 구현<jupyter_code>def gradient_descent(initial_x, max_epoch=1000, learning_rate=0.01, eps=1e-5):
    x = initial_x
    
    x_log = [x]
    
    min_x = x
    min_y = f(min_x)
    for _ in range(max_epoch):
        grad = df_dx(x)
        new_x = x - learning_rate * grad
        y = f(new_x)
        
        x_log.append(new_x)

        if min_y > y:
            min_x = new_x
            min_y = y

        if np.abs(x - new_x) < eps:
            break

        x = new_x
    return min_x, min_y, x_log<jupyter_output><empty_output><jupyter_text>알고리즘 결과 시각화<jupyter_code>min_x1, min_y1, x_log1 = gradient_descent(initial_x=5)
min_x2, min_y2, x_log2 = gradient_descent(initial_x=-5)
min_x3, min_y3, x_log3 = gradient_descent(initial_x=0)
min_x4, min_y4, x_log4 = gradient_descent(initial_x=15, learning_rate=0.04)

y_log1 = f(np.array(x_log1))
y_log2 = f(np.array(x_log2))
y_log3 = f(np.array(x_log3))
y_log4 = f(np.array(x_log4))

plt.plot(x_log1, y_log1, '.-')
plt.plot(x_log2, y_log2, '.-')
plt.plot(x_log3, y_log3, '.-')
plt.plot(x_log4, y_log4, '.-')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14221938775510204, 'fraction_numerical': 0.05102040816326531, 'mean_word_length': 3.683582089552239, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '202072', 'license': 'MIT', 'n_tokens_mistral': 794, 'n_tokens_neox': 785, 'n_words': 111, 'path': 'algorithms/Deep_Learning/04.Visualization.ipynb', 'repo_name': 'WGLee87/TIL', 'size': '1568'}