-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfromScratch_example_ch6_weight_init_activation_histogram.py
More file actions
50 lines (36 loc) ยท 1.33 KB
/
fromScratch_example_ch6_weight_init_activation_histogram.py
File metadata and controls
50 lines (36 loc) ยท 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Created on Fri May 28 15:50:31 2021
@author: ์ด์ฐฝํ
"""
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(x):
return 1 / (1+np.exp(-x))
def Relu(x):
return np.maximum(0,x)
def tanh(x):
return np.tanh(x)
input_data = np.random.randn(1000,100)
node_num = 100
hidden_layer_size = 5
activations = {}
x = input_data
for i in range(hidden_layer_size):
if i != 0:
x = activations[i-1]
"""๊ธฐ์ธ๊ธฐ ์์ค์ด๋, ํ์ฑํ๊ฐ์ด ์น์ฐ์ณ ํํ๋ ฅ์ด ์ ํ๋์ง ์๊ฒ ํ๊ธฐ ์ํด w์ ํ์คํธ์ฐจ๋ฅผ ๋ค์ํ๊ฒ ๋ฐ๊ฟ๋ณด์์ต๋๋ค."""
# w = np.random.randn(node_num, node_num) * 1
# w = np.random.randn(node_num, node_num) * 0.01
w = np.random.randn(node_num, node_num) / np.sqrt(node_num)
a = np.dot(x,w)
"""ํ์ฑํ ํจ์๋ก์๋ ์์ ๋์นญ์ธ ๊ฒ์ด ๋ฐ๋์งํ๊ธฐ ๋๋ฌธ์, sigmoid๋ณด๋ค tanh๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ ํจ๊ณผ์ ์ด๋ค."""
z = sigmoid(a)
#z = tanh(a)
activations[i]=z
""" Relu๋ฅผ ์ฌ์ฉํ ๋ He์ด๊ธฐ๊ฐ์ ์ฌ์ฉํ๊ณ sigmoid๋ tanh๊ฐ์ s์ ๋ชจ์ ๊ณก์ ์ผ๋๋ Xavier ์ด๊ธฐ๊ฐ์ ์ฐ๋ ๊ฒฝ์ฐ๊ฐ ๋ง๋ค."""
for i, a in activations.items():
plt.subplot(1,len(activations), i+1)
plt.title(str(i+1)+ "-layer")
plt.hist(a.flatten(), 30, range=(0,1))
plt.show()