Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
90b64005
提交
90b64005
authored
7月 17, 2013
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
bb34c8c2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
28 行删除
+30
-28
introduction.txt
doc/cifarSC2011/introduction.txt
+30
-28
没有找到文件。
doc/cifarSC2011/introduction.txt
浏览文件 @
90b64005
...
@@ -72,14 +72,14 @@ Python in one slide
...
@@ -72,14 +72,14 @@ Python in one slide
# PYTHON SYNTAX EXAMPLE
# PYTHON SYNTAX EXAMPLE
#######################
#######################
a = 1 # no type declaration required!
a = 1 # no type declaration required!
b = (1,
2,3)
# tuple of three int literals
b = (1,
2, 3)
# tuple of three int literals
c = [1,
2,3]
# list of three int literals
c = [1,
2, 3]
# list of three int literals
d = {'a': 5, b: None} # dictionary of two elements
d = {'a': 5, b: None} # dictionary of two elements
# N.B. string literal, None
# N.B. string literal, None
print d['a'] # square brackets index
print d['a'] # square brackets index
# -> 5
# -> 5
print d[(1,
2,3)]
# new tuple == b, retrieves None
print d[(1,
2, 3)]
# new tuple == b, retrieves None
# -> None
# -> None
print d[6]
print d[6]
# raises KeyError Exception
# raises KeyError Exception
...
@@ -186,23 +186,23 @@ Training an MNIST-ready classification neural network in pure NumPy might look l
...
@@ -186,23 +186,23 @@ Training an MNIST-ready classification neural network in pure NumPy might look l
batchsize = 100
batchsize = 100
for i in xrange(1000):
for i in xrange(1000):
x_i = x[i
*batchsize:(i+1)*
batchsize]
x_i = x[i
* batchsize: (i + 1) *
batchsize]
y_i = y[i
*batchsize:(i+1)*
batchsize]
y_i = y[i
* batchsize: (i + 1) *
batchsize]
hidin = np.dot(x_i, w) + b
hidin = np.dot(x_i, w) + b
hidout = np.tanh(hidin)
hidout = np.tanh(hidin)
outin = np.dot(hidout, v) + c
outin = np.dot(hidout, v) + c
outout = (np.tanh(outin)
+1)/
2.0
outout = (np.tanh(outin)
+ 1) /
2.0
g_outout = outout - y_i
g_outout = outout - y_i
err = 0.5 * np.sum(g_outout
**
2)
err = 0.5 * np.sum(g_outout
**
2)
g_outin = g_outout * outout * (1.0 - outout)
g_outin = g_outout * outout * (1.0 - outout)
g_hidout = np.dot(g_outin, v.T)
g_hidout = np.dot(g_outin, v.T)
g_hidin = g_hidout * (1 - hidout
**
2)
g_hidin = g_hidout * (1 - hidout
**
2)
b -= lr * np.sum(g_hidin, axis=0)
b -= lr * np.sum(g_hidin, axis=0)
c -= lr * np.sum(g_outin, axis=0)
c -= lr * np.sum(g_outin, axis=0)
...
@@ -229,40 +229,42 @@ you have GPU (I'm skipping some dtype-details which we'll come back to).
...
@@ -229,40 +229,42 @@ you have GPU (I'm skipping some dtype-details which we'll come back to).
# Neural Network on MNIST
# Neural Network on MNIST
#########################
#########################
import theano as T
import numpy as np
import theano.tensor as TT
import theano
import theano.tensor as tensor
x = np.load('data_x.npy')
x = np.load('data_x.npy')
y = np.load('data_y.npy')
y = np.load('data_y.npy')
# symbol declarations
# symbol declarations
sx =
TT
.matrix()
sx =
tensor
.matrix()
sy =
TT
.matrix()
sy =
tensor
.matrix()
w =
T
.shared(np.random.normal(avg=0, std=.1,
w =
theano
.shared(np.random.normal(avg=0, std=.1,
size=(784, 500)))
size=(784, 500)))
b =
T
.shared(np.zeros(500))
b =
theano
.shared(np.zeros(500))
v =
T
.shared(np.zeros((500, 10)))
v =
theano
.shared(np.zeros((500, 10)))
c =
T
.shared(np.zeros(10))
c =
theano
.shared(np.zeros(10))
# symbolic expression-building
# symbolic expression-building
hid =
TT.tanh(TT
.dot(sx, w) + b)
hid =
tensor.tanh(tensor
.dot(sx, w) + b)
out =
TT.tanh(TT
.dot(hid, v) + c)
out =
tensor.tanh(tensor
.dot(hid, v) + c)
err = 0.5 *
TT.sum(out - sy)**
2
err = 0.5 *
tensor.sum(out - sy) **
2
gw, gb, gv, gc =
TT.grad(err, [w,b,v,
c])
gw, gb, gv, gc =
tensor.grad(err, [w, b, v,
c])
# compile a fast training function
# compile a fast training function
train =
T
.function([sx, sy], err,
train =
theano
.function([sx, sy], err,
updates={
updates={
w:w - lr * gw,
w:
w - lr * gw,
b:b - lr * gb,
b:
b - lr * gb,
v:v - lr * gv,
v:
v - lr * gv,
c:c - lr * gc})
c:
c - lr * gc})
# now do the computations
# now do the computations
batchsize = 100
batchsize = 100
for i in xrange(1000):
for i in xrange(1000):
x_i = x[i
*batchsize:(i+1)*
batchsize]
x_i = x[i
* batchsize: (i + 1) *
batchsize]
y_i = y[i
*batchsize:(i+1)*
batchsize]
y_i = y[i
* batchsize: (i + 1) *
batchsize]
err_i = train(x_i, y_i)
err_i = train(x_i, y_i)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论