Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0cfae9f9
提交
0cfae9f9
authored
1月 14, 2015
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
scan nextml doc
上级
680275ad
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
23 行删除
+48
-23
presentation.tex
doc/nextml2015/presentation.tex
+48
-23
没有找到文件。
doc/nextml2015/presentation.tex
浏览文件 @
0cfae9f9
...
...
@@ -862,15 +862,16 @@ print f([0, 1, 2])
\item
Allow looping (for, map, while)
\item
Allow recursion (reduce)
\item
Allow recursion with dependency on many of the previous time step
\item
Optimize some cases like moving computation outside of scan
.
\item
The Scan grad is done via Backpropagation
\_
through
\_
t
ime(BPTT)
\item
Optimize some cases like moving computation outside of scan
\item
The Scan grad is done via Backpropagation
Through T
ime(BPTT)
\end{itemize}
\end{frame}
\begin{frame}
{
When not to use scan
}
\begin{itemize}
\item
If only needed for ``vectorization'' or ``broadcasting''. tensor
and numpy.ndarray support them natively. This will be much better.
\item
If you only need for ``vectorization'' or
``broadcasting''. tensor and numpy.ndarray support them
natively. This will be much better for that use case.
\item
You do a fixed number of iteration that is very small (2,3). You
are probably better to just unroll the graph to do it.
...
...
@@ -892,22 +893,36 @@ import theano.tensor as T
import numpy as np
# define tensor variables
X = T.matrix("X")
W = T.matrix("W")
X = T.matrix("X")
b
_
sym = T.vector("b
_
sym")
# define shared random stream
trng = T.shared
_
randomstreams.RandomStreams(1234)
d=trng.binomial(size=W[1].shape)
\end{lstlisting}
\end{frame}
\begin{frame}
[fragile]
\frametitle
{
Scan Example1: Computing tanh(v.dot(W) + b) * d where d is binomial (2)
}
results, updates = theano.scan(lambda v: T.tanh(T.dot(v, W) + b
_
sym) * d, sequences=X)
compute
_
with
_
bnoise = theano.function(inputs=[X, W, b
_
sym], outputs=[results],
updates=updates, allow
_
input
_
downcast=True)
\lstset
{
language=Python,
commentstyle=
\itshape\color
{
blue
}
,
stringstyle=
\color
{
violet
}
,
}
\begin{lstlisting}
results, updates = theano.scan(
lambda v: T.tanh(T.dot(v, W) + b
_
sym) * d,
sequences=X)
f = theano.function(inputs=[X, W, b
_
sym],
outputs=[results],
updates=updates)
x = np.eye(10, 2, dtype=theano.config.floatX)
w = np.ones((2, 2), dtype=theano.config.floatX)
b = np.ones((2), dtype=theano.config.floatX)
print
compute
_
with
_
bnoise
(x, w, b)
print
f
(x, w, b)
\end{lstlisting}
\end{frame}
...
...
@@ -928,19 +943,28 @@ A = T.vector("A")
def inner
_
fct(prior
_
result, B):
return prior
_
result * B
\end{lstlisting}
\end{frame}
\begin{frame}
[fragile]
\frametitle
{
Scan Example2: Computing pow(A, k) (2)
}
# Symbolic description of the result
result, updates = theano.scan(fn=inner
_
fct,
\lstset
{
language=Python,
commentstyle=
\itshape\color
{
blue
}
,
stringstyle=
\color
{
violet
}
,
}
\begin{lstlisting}
result, updates = theano.scan(
fn=inner
_
fct,
outputs
_
info=T.ones
_
like(A),
non
_
sequences=A, n
_
steps=k)
# Scan
has provided us with A ** 1 through A ** k. Keep only the last
#
value. Scan notices this and does not waste memory saving them
.
final
_
result
= result[-1]
# Scan
provide us with A ** 1 through A ** k.
#
Keep only the last value. Scan optimize memory
.
final = result[-1]
power = theano.function(inputs=[A, k], outputs=final
_
result
,
power = theano.function(inputs=[A, k], outputs=final,
updates=updates)
print power(range(10), 2)
#[ 0. 1. 4. 9. 16. 25. 36. 49. 64. 81.]
\end{lstlisting}
...
...
@@ -954,18 +978,19 @@ print power(range(10), 2)
stringstyle=
\color
{
violet
}
,
}
\begin{lstlisting}
result, updates = theano.scan(fn=inner
_
fct,
outputs
_
info=T.ones
_
like(A),
non
_
sequences=A, n
_
steps=k)
result, updates = theano.scan(
fn=inner
_
fct,
sequences=[]
outputs
_
info=[T.ones
_
like(A)],
non
_
sequences=A,
n
_
steps=k)
\end{lstlisting}
\begin{itemize}
\item
u
pdates are needed if there is random number generated in the
\item
U
pdates are needed if there is random number generated in the
\item
Just pass them to the call theano.function(..., updates=updates)
\item
The innfer function of scan take argument like this:
\item
scan: sequence, outputs
\_
info, nonsequence
scan: sequences, outputs
\_
info, non sequences
\end{itemize}
\end{frame}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论