Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
81841795
提交
81841795
authored
10月 26, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix fugly blocksparse doc formatting.
上级
d451fc3b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
73 行增加
和
37 行删除
+73
-37
blocksparse.py
theano/sandbox/blocksparse.py
+73
-37
没有找到文件。
theano/sandbox/blocksparse.py
浏览文件 @
81841795
...
@@ -10,7 +10,8 @@ from theano.gradient import grad_undefined
...
@@ -10,7 +10,8 @@ from theano.gradient import grad_undefined
class
SparseBlockGemv
(
Op
):
class
SparseBlockGemv
(
Op
):
"""
"""
This op computes the dot product of specified pieces of vectors
This op computes the dot product of specified pieces of vectors
and matrices, returning pieces of vectors:
and matrices, returning pieces of vectors::
for b in range(batch_size):
for b in range(batch_size):
for j in range(o.shape[1]):
for j in range(o.shape[1]):
for i in range(h.shape[1]):
for i in range(h.shape[1]):
...
@@ -20,6 +21,7 @@ class SparseBlockGemv(Op):
...
@@ -20,6 +21,7 @@ class SparseBlockGemv(Op):
.. image:: ../../images/blocksparse.png
.. image:: ../../images/blocksparse.png
:scale: 50
%
:scale: 50
%
"""
"""
registered_opts
=
[]
registered_opts
=
[]
...
@@ -34,29 +36,40 @@ class SparseBlockGemv(Op):
...
@@ -34,29 +36,40 @@ class SparseBlockGemv(Op):
Compute the dot product of the specified pieces of vectors
Compute the dot product of the specified pieces of vectors
and matrices.
and matrices.
The parameter types are actually their expected shapes
relative to each other.
Parameters
Parameters
----------
----------
var: shape, comment
o : batch, oWin, oSize
o: (batch, oWin, oSize) output vector
output vector
W: (iBlocks, oBlocks, iSize, oSize), weight matrix
W : iBlocks, oBlocks, iSize, oSize
h: (batch, iWin, iSize), input from lower layer (sparse)
weight matrix
inputIdx: (batch, iWin), indexes of the input blocks
h : batch, iWin, iSize
outputIdx: (batch, oWin), indexes of the output blocks
input from lower layer (sparse)
returns (batch, oWin, oSize), dot(W[i, j], h[i]) + o[j]
inputIdx : batch, iWin
indexes of the input blocks
Notation
outputIdx : batch, oWin
--------
indexes of the output blocks
Returns
-------
(batch, oWin, oSize)
dot(W[i, j], h[i]) + o[j]
Notes
-----
- `batch` is the number of examples in a minibatch (batch size).
- `batch` is the number of examples in a minibatch (batch size).
- `iBlocks` is the total number of blocks in the input (from lower
- `iBlocks` is the total number of blocks in the input (from lower
layer).
layer).
- `iSize` is the size of each of these input blocks.
- `iSize` is the size of each of these input blocks.
- `iWin` is the number of blocks that will be used as inputs. Which
- `iWin` is the number of blocks that will be used as inputs. Which
blocks
blocks will be used is specified in `inputIdx`.
will be used is specified in `inputIdx`.
- `oBlocks` is the number or possible output blocks.
- `oBlocks` is the number or possible output blocks.
- `oSize` is the size of each of these output blocks.
- `oSize` is the size of each of these output blocks.
- `oWin` is the number of output blocks that will actually be computed.
- `oWin` is the number of output blocks that will actually be computed.
Which blocks will be computed is specified in `outputIdx`.
Which blocks will be computed is specified in `outputIdx`.
"""
"""
o
=
theano
.
tensor
.
as_tensor_variable
(
o
)
o
=
theano
.
tensor
.
as_tensor_variable
(
o
)
W
=
theano
.
tensor
.
as_tensor_variable
(
W
)
W
=
theano
.
tensor
.
as_tensor_variable
(
W
)
...
@@ -118,10 +131,13 @@ class SparseBlockGemv(Op):
...
@@ -118,10 +131,13 @@ class SparseBlockGemv(Op):
class
SparseBlockOuter
(
Op
):
class
SparseBlockOuter
(
Op
):
"""
"""
This computes the outer product of two sets of pieces of vectors
This computes the outer product of two sets of pieces of vectors
updating a full matrix with the results:
updating a full matrix with the results::
for b in range(batch_size):
for b in range(batch_size):
o[xIdx[b, i], yIdx[b, j]] += (alpha * outer(x[b, i], y[b, j]))
o[xIdx[b, i], yIdx[b, j]] += (alpha * outer(x[b, i], y[b, j]))
This op is involved in the gradient of SparseBlockGemv.
This op is involved in the gradient of SparseBlockGemv.
"""
"""
registered_opts
=
[]
registered_opts
=
[]
...
@@ -136,18 +152,26 @@ class SparseBlockOuter(Op):
...
@@ -136,18 +152,26 @@ class SparseBlockOuter(Op):
Compute the dot product of the specified pieces of vectors
Compute the dot product of the specified pieces of vectors
and matrices.
and matrices.
The parameter types are actually their expected shapes
relative to each other.
Parameters
Parameters
----------
----------
var: shape, comment
o : xBlocks, yBlocks, xSize, ySize
o: (xBlocks, yBlocks, xSize, ySize)
x : batch, xWin, xSize
x: (batch, xWin, xSize)
y : batch, yWin, ySize
y: (batch, yWin, ySize)
xIdx : batch, iWin
xIdx: (batch, iWin), indexes of the x blocks
indexes of the x blocks
yIdx: (batch, oWin), indexes of the y blocks
yIdx : batch, oWin
returns (xBlocks, yBlocks, xSize, ySize), outer(x[i], y[j]) + o[i, j]
indexes of the y blocks
Notation
Returns
--------
-------
(xBlocks, yBlocks, xSize, ySize)
outer(x[i], y[j]) + o[i, j]
Notes
-----
- `batch` is the number of examples in a minibatch (batch size).
- `batch` is the number of examples in a minibatch (batch size).
- `xBlocks` is the total number of blocks in x.
- `xBlocks` is the total number of blocks in x.
- `xSize` is the size of each of these x blocks.
- `xSize` is the size of each of these x blocks.
...
@@ -157,6 +181,7 @@ class SparseBlockOuter(Op):
...
@@ -157,6 +181,7 @@ class SparseBlockOuter(Op):
- `ySize` is the size of each of these y blocks.
- `ySize` is the size of each of these y blocks.
- `yWin` is the number of y blocks that will actually be computed.
- `yWin` is the number of y blocks that will actually be computed.
Which blocks will be computed is specified in `yIdx`.
Which blocks will be computed is specified in `yIdx`.
"""
"""
one
=
tensor
.
constant
(
numpy
.
asarray
(
1.0
,
dtype
=
'float32'
))
one
=
tensor
.
constant
(
numpy
.
asarray
(
1.0
,
dtype
=
'float32'
))
o
=
theano
.
tensor
.
as_tensor_variable
(
o
)
o
=
theano
.
tensor
.
as_tensor_variable
(
o
)
...
@@ -197,27 +222,38 @@ def sparse_block_dot(W, h, inputIdx, b, outputIdx):
...
@@ -197,27 +222,38 @@ def sparse_block_dot(W, h, inputIdx, b, outputIdx):
Compute the dot product (plus bias) of the specified pieces of vectors
Compute the dot product (plus bias) of the specified pieces of vectors
and matrices. See SparseBlockGemv to get more information.
and matrices. See SparseBlockGemv to get more information.
The parameter types are actually their expected shapes relative to
each other.
Parameters
Parameters
----------
----------
var: shape, comment
W : iBlocks, oBlocks, iSize, oSize
W: (iBlocks, oBlocks, iSize, oSize), weight matrix
weight matrix
h: (batch, iWin, iSize), input from lower layer (sparse)
h : batch, iWin, iSize
inputIdx: (batch, iWin), indexes of the input blocks
input from lower layer (sparse)
b: (oBlocks, oSize), bias vector
inputIdx : batch, iWin
outputIdx: (batch, oWin), indexes of the output blocks
indexes of the input blocks
returns (batch, oWin, oSize), dot(W[i, j], h[i]) + b[j]
b : oBlocks, oSize
but b[j] is only added once
bias vector
Notation
outputIdx : batch, oWin
--------
indexes of the output blocks
Returns
-------
(batch, oWin, oSize)
dot(W[i, j], h[i]) + b[j] but b[j] is only added once
Notes
-----
- `batch` is the number of examples in a minibatch (batch size).
- `batch` is the number of examples in a minibatch (batch size).
- `iBlocks` is the total number of blocks in the input (from lower layer).
- `iBlocks` is the total number of blocks in the input (from lower layer).
- `iSize` is the size of each of these input blocks.
- `iSize` is the size of each of these input blocks.
- `iWin` is the number of blocks that will be used as inputs. Which blocks
- `iWin` is the number of blocks that will be used as inputs. Which blocks
will be used is specified in `inputIdx`.
will be used is specified in `inputIdx`.
- `oBlocks` is the number or possible output blocks.
- `oBlocks` is the number or possible output blocks.
- `oSize` is the size of each of these output blocks.
- `oSize` is the size of each of these output blocks.
- `oWin` is the number of output blocks that will actually be computed.
- `oWin` is the number of output blocks that will actually be computed.
Which blocks will be computed is specified in `outputIdx`.
Which blocks will be computed is specified in `outputIdx`.
"""
"""
assert
inputIdx
.
ndim
==
h
.
ndim
-
1
assert
inputIdx
.
ndim
==
h
.
ndim
-
1
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论