Skip to content

Commit ce6aba1

Browse files
minor updates
1 parent faadf24 commit ce6aba1

File tree

14 files changed

+50
-27
lines changed

14 files changed

+50
-27
lines changed

Diff for: airline/ann.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ANN(object):
3838
def __init__(self, hidden_layer_sizes):
3939
self.hidden_layer_sizes = hidden_layer_sizes
4040

41-
def fit(self, X, Y, activation=T.tanh, learning_rate=10e-4, mu=0.5, reg=0, epochs=5000, batch_sz=None, print_period=100, show_fig=True):
41+
def fit(self, X, Y, activation=T.tanh, learning_rate=1e-3, mu=0.5, reg=0, epochs=5000, batch_sz=None, print_period=100, show_fig=True):
4242
X = X.astype(np.float32)
4343
Y = Y.astype(np.float32)
4444

Diff for: airline/rnn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RNN(object):
2929
def __init__(self, hidden_layer_sizes):
3030
self.hidden_layer_sizes = hidden_layer_sizes
3131

32-
def fit(self, X, Y, activation=T.tanh, learning_rate=10e-2, mu=0.5, reg=0, epochs=2000, show_fig=False):
32+
def fit(self, X, Y, activation=T.tanh, learning_rate=1e-1, mu=0.5, reg=0, epochs=2000, show_fig=False):
3333
N, t, D = X.shape
3434

3535
self.hidden_layers = []

Diff for: ann_class2/extra_reading.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ Xavier (Glorot) Normal Initializer
1818
http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf
1919

2020
He Normal Initializer
21-
http://arxiv.org/abs/1502.01852
21+
http://arxiv.org/abs/1502.01852
22+
23+
For understanding Nesterov Momentum:
24+
Advances in optimizing Recurrent Networks by Yoshua Bengio, Section 3.5
25+
http://arxiv.org/pdf/1212.0901v2.pdf

Diff for: bayesian_ml/3/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def objective(X, Y, C, mu, a, b, e, f, a0, b0, e0, f0):
6666
# e3 = gamma_dist.entropy(e, scale=1.0/f)
6767
# e4 = -e_ln_q_gamma(e, f)
6868
# print "e3:", e3, "e4:", e4
69-
# assert(np.abs(e3 - e4) < 10e-8)
69+
# assert(np.abs(e3 - e4) < 1e-8)
7070
total += gamma_dist.entropy(e, scale=1.0/f)
7171
# total -= e_ln_q_gamma(e, f)
7272
# print "total after lnq(lambda):", total

Diff for: cnn_class/custom_blur.py

+10
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,13 @@ def convolve2d(X, W):
9191
print(out.shape)
9292
# after convolution, the output signal is N1 + N2 - 1
9393

94+
# try it in color
95+
out = np.zeros(img.shape)
96+
W /= W.sum()
97+
for i in range(3):
98+
out[:,:,i] = convolve2d(img[:,:,i], W)
99+
plt.imshow(out)
100+
plt.show()
101+
102+
103+

Diff for: logistic_regression_class/logistic3.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
N = 100
1717
D = 2
1818

19+
N_per_class = N//2
20+
1921

2022
X = np.random.randn(N,D)
2123

2224
# center the first 50 points at (-2,-2)
23-
X[:50,:] = X[:50,:] - 2*np.ones((50,D))
25+
X[:N_per_class,:] = X[:N_per_class,:] - 2*np.ones((N_per_class,D))
2426

2527
# center the last 50 points at (2, 2)
26-
X[50:,:] = X[50:,:] + 2*np.ones((50,D))
28+
X[N_per_class:,:] = X[N_per_class:,:] + 2*np.ones((N_per_class,D))
2729

28-
# labels: first 50 are 0, last 50 are 1
29-
T = np.array([0]*50 + [1]*50)
30+
# labels: first N_per_class are 0, last N_per_class are 1
31+
T = np.array([0]*N_per_class + [1]*N_per_class)
3032

3133
# add a column of ones
3234
# ones = np.array([[1]*N]).T # old

Diff for: nlp_class2/glove.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def fit(self, sentences, cc_matrix=None, learning_rate=1e-4, reg=0.1, xmax=100,
223223
for i in xrange(V):
224224
# matrix = reg*np.eye(D) + np.sum((fX[i,j]*np.outer(U[j], U[j]) for j in xrange(V)), axis=0)
225225
matrix = reg*np.eye(D) + (fX[i,:]*U.T).dot(U)
226-
# assert(np.abs(matrix - matrix2).sum() < 10e-5)
226+
# assert(np.abs(matrix - matrix2).sum() < 1e-5)
227227
vector = (fX[i,:]*(logX[i,:] - b[i] - c - mu)).dot(U)
228228
W[i] = np.linalg.solve(matrix, vector)
229229
# print "fast way took:", (datetime.now() - t0)
@@ -238,8 +238,8 @@ def fit(self, sentences, cc_matrix=None, learning_rate=1e-4, reg=0.1, xmax=100,
238238
# vector2 += fX[i,j]*(logX[i,j] - b[i] - c[j])*U[j]
239239
# print "slow way took:", (datetime.now() - t0)
240240

241-
# assert(np.abs(matrix - matrix2).sum() < 10e-5)
242-
# assert(np.abs(vector - vector2).sum() < 10e-5)
241+
# assert(np.abs(matrix - matrix2).sum() < 1e-5)
242+
# assert(np.abs(vector - vector2).sum() < 1e-5)
243243
# W[i] = np.linalg.solve(matrix, vector)
244244
# print "updated W"
245245

@@ -257,7 +257,7 @@ def fit(self, sentences, cc_matrix=None, learning_rate=1e-4, reg=0.1, xmax=100,
257257
for j in xrange(V):
258258
# matrix = reg*np.eye(D) + np.sum((fX[i,j]*np.outer(W[i], W[i]) for i in xrange(V)), axis=0)
259259
matrix = reg*np.eye(D) + (fX[:,j]*W.T).dot(W)
260-
# assert(np.abs(matrix - matrix2).sum() < 10e-8)
260+
# assert(np.abs(matrix - matrix2).sum() < 1e-8)
261261
vector = (fX[:,j]*(logX[:,j] - b - c[j] - mu)).dot(W)
262262
# matrix = reg*np.eye(D)
263263
# vector = 0
@@ -323,7 +323,7 @@ def main(we_file, w2i_file, use_brown=True, n_files=50):
323323
model.fit(
324324
sentences,
325325
cc_matrix=cc_matrix,
326-
learning_rate=3*10e-5,
326+
learning_rate=3e-4,
327327
reg=0.1,
328328
epochs=10,
329329
gd=True,

Diff for: nlp_class2/rntn_tensorflow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, V, D, K, activation):
6868
self.bo = tf.Variable(bo.astype(np.float32))
6969
self.params = [self.We, self.W11, self.W22, self.W12, self.W1, self.W2, self.Wo]
7070

71-
def fit(self, trees, lr=10e-3, mu=0.9, reg=10e-2, epochs=5):
71+
def fit(self, trees, lr=1e-2, mu=0.9, reg=1e-1, epochs=5):
7272
train_ops = []
7373
costs = []
7474
predictions = []

Diff for: nlp_class2/util.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Course URL:
22
# https://deeplearningcourses.com/c/natural-language-processing-with-deep-learning-in-python
33
# https://udemy.com/natural-language-processing-with-deep-learning-in-python
4+
from __future__ import print_function, division
5+
from future.utils import iteritems
6+
from builtins import range
7+
# Note: you may need to update your version of future
8+
# sudo pip install -U future
9+
10+
411
import numpy as np
512

613
def init_weight(Mi, Mo):
@@ -21,15 +28,15 @@ def dist2(a, b):
2128
for dist, name in [(dist1, 'Euclidean'), (dist2, 'cosine')]:
2229
min_dist = float('inf')
2330
best_word = ''
24-
for word, idx in word2idx.iteritems():
31+
for word, idx in iteritems(word2idx):
2532
if word not in (w1, w2, w3):
2633
v1 = We[idx]
2734
d = dist(v0, v1)
2835
if d < min_dist:
2936
min_dist = d
3037
best_word = word
31-
print "closest match by", name, "distance:", best_word
32-
print w1, "-", w2, "=", best_word, "-", w3
38+
print("closest match by", name, "distance:", best_word)
39+
print(w1, "-", w2, "=", best_word, "-", w3)
3340

3441

3542
class Tree:
@@ -43,9 +50,9 @@ def __init__(self, word, label):
4350
def display_tree(t, lvl=0):
4451
prefix = ''.join(['>']*lvl)
4552
if t.word is not None:
46-
print "%s%s %s" % (prefix, t.label, t.word)
53+
print("%s%s %s" % (prefix, t.label, t.word))
4754
else:
48-
print "%s%s -" % (prefix, t.label)
55+
print("%s%s -" % (prefix, t.label))
4956
# if t.left is None or t.right is None:
5057
# raise Exception("Tree node has no word but left and right child are None")
5158
if t.left:

Diff for: rl2/atari/dqn_tf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(self, K, conv_layer_sizes, hidden_layer_sizes, gamma, scope):
100100
cost = tf.reduce_mean(tf.square(self.G - selected_action_values))
101101
# self.train_op = tf.train.AdamOptimizer(1e-2).minimize(cost)
102102
# self.train_op = tf.train.AdagradOptimizer(1e-2).minimize(cost)
103-
# self.train_op = tf.train.RMSPropOptimizer(2.5e-4, decay=0.99, epsilon=10e-3).minimize(cost)
103+
# self.train_op = tf.train.RMSPropOptimizer(2.5e-4, decay=0.99, epsilon=1e-3).minimize(cost)
104104
self.train_op = tf.train.RMSPropOptimizer(0.00025, 0.99, 0.0, 1e-6).minimize(cost)
105105
# self.train_op = tf.train.MomentumOptimizer(1e-3, momentum=0.9).minimize(cost)
106106
# self.train_op = tf.train.GradientDescentOptimizer(1e-4).minimize(cost)

Diff for: rl2/atari/dqn_tf_alt.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ def __init__(self, K, conv_layer_sizes, hidden_layer_sizes, gamma):
165165

166166
cost = tf.reduce_mean(tf.square(self.G - selected_action_values))
167167
self.cost = cost
168-
# self.train_op = tf.train.AdamOptimizer(10e-3).minimize(cost)
169-
# self.train_op = tf.train.AdagradOptimizer(10e-3).minimize(cost)
168+
# self.train_op = tf.train.AdamOptimizer(1e-2).minimize(cost)
169+
# self.train_op = tf.train.AdagradOptimizer(1e-2).minimize(cost)
170170
self.train_op = tf.train.RMSPropOptimizer(0.00025, 0.99, 0.0, 1e-6).minimize(cost)
171-
# self.train_op = tf.train.MomentumOptimizer(10e-4, momentum=0.9).minimize(cost)
172-
# self.train_op = tf.train.GradientDescentOptimizer(10e-5).minimize(cost)
171+
# self.train_op = tf.train.MomentumOptimizer(1e-3, momentum=0.9).minimize(cost)
172+
# self.train_op = tf.train.GradientDescentOptimizer(1e-4).minimize(cost)
173173

174174
def set_session(self, session):
175175
self.session = session

Diff for: unsupervised_class/kmeans.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def plot_k_means(X, K, max_iter=20, beta=1.0, show_plots=True):
5050
exponents[n,k] = np.exp(-beta*d(M[k], X[n]))
5151

5252
R = exponents / exponents.sum(axis=1, keepdims=True)
53-
# assert(np.abs(R - R2).sum() < 10e-10)
53+
# assert(np.abs(R - R2).sum() < 1e-10)
5454

5555
# step 2: recalculate means
5656
for k in range(K):

Diff for: unsupervised_class/kmeans_visualize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def plot_k_means(X, K, max_iter=20, beta=1.0):
5757

5858
costs[i] = cost(X, R, M)
5959
if i > 0:
60-
if np.abs(costs[i] - costs[i-1]) < 10e-5:
60+
if np.abs(costs[i] - costs[i-1]) < 1e-5:
6161
break
6262
plt.show()
6363

Diff for: unsupervised_class2/autoencoder_tf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def build(self, D, M):
4343
)
4444

4545
self.train_op = tf.train.AdamOptimizer(1e-1).minimize(self.cost)
46-
# self.train_op = tf.train.MomentumOptimizer(10e-4, momentum=0.9).minimize(self.cost)
46+
# self.train_op = tf.train.MomentumOptimizer(1e-3, momentum=0.9).minimize(self.cost)
4747

4848
def fit(self, X, epochs=1, batch_sz=100, show_fig=False):
4949
N, D = X.shape

0 commit comments

Comments
 (0)