Skip to content

Commit 2cb5b81

Browse files
committed
修复错误
1 parent 2d62b38 commit 2cb5b81

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

09. theano/09.07 loop with scan.ipynb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"x = T.vector()\n",
137137
"\n",
138138
"results, _ = theano.scan(fn = lambda t: t * 2,\n",
139-
" sequences = x)\n",
139+
" sequences = x)\n",
140140
"x_double_scan = theano.function([x], results)\n",
141141
"\n",
142142
"print x_double_scan(range(10))"
@@ -170,7 +170,7 @@
170170
],
171171
"source": [
172172
"result, _ = theano.map(fn = lambda t: t * 2,\n",
173-
" sequences = x)\n",
173+
" sequences = x)\n",
174174
"x_double_map = theano.function([x], result)\n",
175175
"\n",
176176
"print x_double_map(range(10))"
@@ -211,8 +211,8 @@
211211
],
212212
"source": [
213213
"result, _ = theano.scan(fn = lambda t, v: t + v,\n",
214-
" sequences = x,\n",
215-
" outputs_info = floatX(0.))\n",
214+
" sequences = x,\n",
215+
" outputs_info = floatX(0.))\n",
216216
"\n",
217217
"# 因为每一步的输出值都会被记录到最后的 result 中,所以最后的和是 result 的最后一个元素。\n",
218218
"x_sum_scan = theano.function([x], result[-1])\n",
@@ -245,8 +245,8 @@
245245
],
246246
"source": [
247247
"result, _ = theano.reduce(fn = lambda t, v: t + v,\n",
248-
" sequences = x,\n",
249-
" outputs_info = 0.)\n",
248+
" sequences = x,\n",
249+
" outputs_info = 0.)\n",
250250
"\n",
251251
"x_sum_reduce = theano.function([x], result)\n",
252252
"\n",
@@ -384,8 +384,8 @@
384384
"\n",
385385
"# a 对应的是 A, n 对应 N,v 对应 x\n",
386386
"components, _ = theano.scan(fn = lambda a, n, v: a * (v ** n),\n",
387-
" sequences = [A, N],\n",
388-
" non_sequences = x)\n",
387+
" sequences = [A, N],\n",
388+
" non_sequences = x)\n",
389389
"\n",
390390
"result = components.sum()\n",
391391
"\n",
@@ -436,7 +436,7 @@
436436
"Sequence3[t+3]\n",
437437
"```\n",
438438
"\n",
439-
"然后 `Output1` 传入的是 `[-5,-3,-1]`(**传入的初始值的形状应为 `shape (5,)+`**),`Output2` 不作为参数传入,`Output3` 传入的是 `[-1]`,所以接下的参数是:\n",
439+
"然后 `Output1` 传入的是 `[-3, -5]`(**传入的初始值的形状应为 `shape (5,)+`**),`Output2` 不作为参数传入,`Output3` 传入的是 `[-1]`,所以接下的参数是:\n",
440440
"```\n",
441441
"Output1[t-3]\n",
442442
"Output1[t-5]\n",
@@ -479,9 +479,9 @@
479479
"\n",
480480
"# W_yy 和 W_xy 作为不变的参数可以直接使用\n",
481481
"results, _ = theano.scan(fn = lambda x, x_pre, y: T.tanh(T.dot(W_1, y) + T.dot(W_2, x) + T.dot(W_3, x_pre)), \n",
482-
" # 0 对应 x,-1 对应 x_pre\n",
483-
" sequences = dict(input=X, taps=[0, -1]), \n",
484-
" outputs_info = Y)\n",
482+
" # 0 对应 x,-1 对应 x_pre\n",
483+
" sequences = dict(input=X, taps=[0, -1]), \n",
484+
" outputs_info = Y)\n",
485485
"\n",
486486
"Y_seq = theano.function(inputs = [X, Y, W_1, W_2, W_3], \n",
487487
" outputs = results)"
@@ -683,11 +683,11 @@
683683
"k = T.iscalar(\"k\")\n",
684684
"\n",
685685
"results, _ = theano.scan(fn = lambda P, A: P.dot(A),\n",
686-
" # 初始值设为单位矩阵\n",
687-
" outputs_info = T.eye(A.shape[0]),\n",
688-
" # 乘 k 次\n",
689-
" non_sequences = A,\n",
690-
" n_steps = k)\n",
686+
" # 初始值设为单位矩阵\n",
687+
" outputs_info = T.eye(A.shape[0]),\n",
688+
" # 乘 k 次\n",
689+
" non_sequences = A,\n",
690+
" n_steps = k)\n",
691691
"\n",
692692
"A_k = theano.function(inputs = [A, k], outputs = results[-1])\n",
693693
"\n",
@@ -740,8 +740,8 @@
740740
"\n",
741741
"# 这里 lambda 的返回值是一个 dict,因此这个值会被传入 updates 中\n",
742742
"_, updates = theano.scan(fn = lambda n: {n:n+1},\n",
743-
" non_sequences = n,\n",
744-
" n_steps = k)\n",
743+
" non_sequences = n,\n",
744+
" n_steps = k)\n",
745745
"\n",
746746
"counter = theano.function(inputs = [k], \n",
747747
" outputs = [],\n",

0 commit comments

Comments
 (0)