-
Notifications
You must be signed in to change notification settings - Fork 31
/
init.py
37 lines (26 loc) · 1009 Bytes
/
init.py
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
import numpy as np
import theano
import theano.tensor as T
from theano import shared
dtype = T.config.floatX
print("loading init.py")
def init_weight(shape, name, sample='uni', seed=None):
rng = np.random.RandomState(seed)
if sample == 'unishape':
values = rng.uniform(
low=-np.sqrt(6. / (shape[0] + shape[1])),
high=np.sqrt(6. / (shape[0] + shape[1])),
size=shape).astype(dtype)
elif sample == 'svd':
values = rng.uniform(low=-1., high=1., size=shape).astype(dtype)
_, svs, _ = np.linalg.svd(values)
# svs[0] is the largest singular value
values = values / svs[0]
elif sample == 'uni':
values = rng.uniform(low=-0.1, high=0.1, size=shape).astype(dtype)
elif sample == 'zero':
values = np.zeros(shape=shape, dtype=dtype)
else:
raise ValueError("Unsupported initialization scheme: %s"
% sample)
return shared(values, name=name, borrow=True)