forked from lisa-lab/DeepLearningTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp_square.py
More file actions
43 lines (36 loc) · 734 Bytes
/
tmp_square.py
File metadata and controls
43 lines (36 loc) · 734 Bytes
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
from theano import tensor as T, shared, function
import numpy as np
rng = np.random.RandomState(1234)
# fprop
#p = T.matrix(name='p', dtype='float32')
p = shared(
np.asarray(
rng.uniform(low=-1, high=1, size=(3, 4)),
dtype='float32'
),
borrow=True
)
I = T.matrix(name='I', dtype='float32')
z = p * I
u = z**2
v = p + u
ell = T.mean(v)
# bprop
dp = T.grad(ell, wrt=p)
# the graph
fg = function(
inputs=[I],
outputs=[ell, v, dp],
updates=[(p, p - np.float32(0.1)*dp)]
)
# fire
pval = np.asarray(
rng.uniform(low=-1, high=1, size=(3, 4)),
dtype='float32'
)
Ival = np.asarray(
rng.uniform(low=-1, high=1, size=(3, 4)),
dtype='float32'
)
[ellval, vval, dpval] = fg(Ival)
pass