Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
24294c33
提交
24294c33
authored
3月 20, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tensor - introduced use of tsor_apply.Apply which handles forward-propagation of
variable.tag.shape
上级
b2fb02b1
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
22 行增加
和
14 行删除
+22
-14
basic.py
theano/tensor/basic.py
+2
-1
blas.py
theano/tensor/blas.py
+3
-1
elemwise.py
theano/tensor/elemwise.py
+4
-1
conv.py
theano/tensor/nnet/conv.py
+2
-1
nnet.py
theano/tensor/nnet/nnet.py
+11
-10
没有找到文件。
theano/tensor/basic.py
浏览文件 @
24294c33
...
@@ -13,7 +13,8 @@ import numpy, theano
...
@@ -13,7 +13,8 @@ import numpy, theano
from
copy
import
copy
from
copy
import
copy
from
theano
import
gof
from
theano
import
gof
from
theano.gof
import
Variable
,
Op
,
utils
,
Type
,
Constant
,
Apply
,
Value
from
theano.gof
import
Variable
,
Op
,
utils
,
Type
,
Constant
,
Value
from
.tsor_apply
import
Apply
from
theano
import
gradient
from
theano
import
gradient
...
...
theano/tensor/blas.py
浏览文件 @
24294c33
...
@@ -4,7 +4,7 @@ import sys, traceback, logging, copy, os
...
@@ -4,7 +4,7 @@ import sys, traceback, logging, copy, os
import
numpy
import
numpy
import
numpy.distutils
import
numpy.distutils
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
from
theano.gof
import
(
utils
,
Op
,
Apply
,
view_roots
,
PatternSub
,
DestroyHandler
,
from
theano.gof
import
(
utils
,
Op
,
view_roots
,
PatternSub
,
DestroyHandler
,
SeqOptimizer
,
local_optimizer
,
Optimizer
,
LocalOptimizer
,
OpKeyOptimizer
,
SeqOptimizer
,
local_optimizer
,
Optimizer
,
LocalOptimizer
,
OpKeyOptimizer
,
InconsistencyError
,
toolbox
,
SequenceDB
,
EquilibriumOptimizer
)
InconsistencyError
,
toolbox
,
SequenceDB
,
EquilibriumOptimizer
)
from
theano.printing
import
pprint
,
FunctionPrinter
from
theano.printing
import
pprint
,
FunctionPrinter
...
@@ -13,6 +13,8 @@ from theano.gof.python25 import any
...
@@ -13,6 +13,8 @@ from theano.gof.python25 import any
import
theano.scalar
import
theano.scalar
import
basic
as
T
import
basic
as
T
from
.tsor_apply
import
Apply
#NB: this clobbers the builtin 'compile' symbol
#NB: this clobbers the builtin 'compile' symbol
from
theano
import
compile
#to register the optimizer built by this file
from
theano
import
compile
#to register the optimizer built by this file
...
...
theano/tensor/elemwise.py
浏览文件 @
24294c33
...
@@ -3,7 +3,7 @@ import elemwise_cgen as cgen
...
@@ -3,7 +3,7 @@ import elemwise_cgen as cgen
import
numpy
,
theano
import
numpy
,
theano
from
theano
import
gof
from
theano
import
gof
from
theano.gof
import
Op
,
Apply
from
theano.gof
import
Op
from
theano
import
scalar
from
theano
import
scalar
from
theano.scalar
import
Scalar
from
theano.scalar
import
Scalar
from
theano
import
printing
from
theano
import
printing
...
@@ -11,6 +11,8 @@ from theano.printing import pprint
...
@@ -11,6 +11,8 @@ from theano.printing import pprint
from
theano.gof.python25
import
all
,
any
from
theano.gof.python25
import
all
,
any
from
copy
import
copy
,
deepcopy
from
copy
import
copy
,
deepcopy
from
.tsor_apply
import
Apply
# tensor depends on elemwise to provide definitions for several ops
# tensor depends on elemwise to provide definitions for several ops
# but elemwise needs to make TensorType instances, so we have these as
# but elemwise needs to make TensorType instances, so we have these as
...
@@ -150,6 +152,7 @@ class DimShuffle(Op):
...
@@ -150,6 +152,7 @@ class DimShuffle(Op):
output
=
TensorType
(
dtype
=
input
.
type
.
dtype
,
output
=
TensorType
(
dtype
=
input
.
type
.
dtype
,
broadcastable
=
ob
)
.
make_variable
()
broadcastable
=
ob
)
.
make_variable
()
return
Apply
(
self
,
[
input
],
[
output
])
return
Apply
(
self
,
[
input
],
[
output
])
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
...
...
theano/tensor/nnet/conv.py
浏览文件 @
24294c33
...
@@ -9,6 +9,7 @@ import numpy
...
@@ -9,6 +9,7 @@ import numpy
import
theano
import
theano
import
theano.tensor
as
tensor
import
theano.tensor
as
tensor
from
theano
import
gof
,
Op
,
tensor
,
config
from
theano
import
gof
,
Op
,
tensor
,
config
from
theano.tensor.tsor_apply
import
Apply
from
theano.gof.python25
import
any
from
theano.gof.python25
import
any
import
logging
import
logging
_logger
=
logging
.
getLogger
(
"theano.signal.conv"
)
_logger
=
logging
.
getLogger
(
"theano.signal.conv"
)
...
@@ -481,7 +482,7 @@ class ConvOp(Op):
...
@@ -481,7 +482,7 @@ class ConvOp(Op):
broadcastable
=
[
_inputs
.
broadcastable
[
0
],
broadcastable
=
[
_inputs
.
broadcastable
[
0
],
_kerns
.
broadcastable
[
0
],
False
,
False
]);
_kerns
.
broadcastable
[
0
],
False
,
False
]);
return
gof
.
Apply
(
self
,
[
_inputs
,
_kerns
],
[
output
])
return
Apply
(
self
,
[
_inputs
,
_kerns
],
[
output
])
def
infer_shape
(
self
,
node
,
input_shapes
):
def
infer_shape
(
self
,
node
,
input_shapes
):
imshp
=
input_shapes
[
0
]
imshp
=
input_shapes
[
0
]
...
...
theano/tensor/nnet/nnet.py
浏览文件 @
24294c33
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
:note: TODO: factor this out into a neural-network toolbox.
:note: TODO: factor this out into a neural-network toolbox.
"""
"""
import
numpy
from
theano
import
gof
from
theano
import
gof
from
theano
import
printing
from
theano
import
printing
...
@@ -9,7 +10,7 @@ from theano.tensor import basic as tensor
...
@@ -9,7 +10,7 @@ from theano.tensor import basic as tensor
from
theano.tensor
import
elemwise
,
dmatrix
,
fmatrix
,
dvector
,
fvector
from
theano.tensor
import
elemwise
,
dmatrix
,
fmatrix
,
dvector
,
fvector
from
theano.tensor
import
opt
from
theano.tensor
import
opt
from
theano.compile
import
optdb
from
theano.compile
import
optdb
import
nump
y
from
theano.tensor.tsor_apply
import
Appl
y
from
theano.tensor.nnet.sigm
import
sigmoid
,
softplus
from
theano.tensor.nnet.sigm
import
sigmoid
,
softplus
...
@@ -53,7 +54,7 @@ class SoftmaxWithBias(gof.Op):
...
@@ -53,7 +54,7 @@ class SoftmaxWithBias(gof.Op):
raise
ValueError
(
'b must be 1-d tensor of floats'
)
raise
ValueError
(
'b must be 1-d tensor of floats'
)
sm
=
x
.
type
.
make_variable
()
sm
=
x
.
type
.
make_variable
()
return
gof
.
Apply
(
self
,
[
x
,
b
],
[
sm
])
return
Apply
(
self
,
[
x
,
b
],
[
sm
])
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
x
,
b
=
input_storage
x
,
b
=
input_storage
...
@@ -220,7 +221,7 @@ class SoftmaxGrad(gof.Op):
...
@@ -220,7 +221,7 @@ class SoftmaxGrad(gof.Op):
def
make_node
(
self
,
dy
,
sm
,
**
kwargs
):
def
make_node
(
self
,
dy
,
sm
,
**
kwargs
):
dy
=
tensor
.
as_tensor_variable
(
dy
)
dy
=
tensor
.
as_tensor_variable
(
dy
)
sm
=
tensor
.
as_tensor_variable
(
sm
)
sm
=
tensor
.
as_tensor_variable
(
sm
)
return
gof
.
Apply
(
self
,
[
dy
,
sm
],
[
sm
.
type
.
make_variable
()])
return
Apply
(
self
,
[
dy
,
sm
],
[
sm
.
type
.
make_variable
()])
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
dy
,
sm
=
input_storage
dy
,
sm
=
input_storage
...
@@ -322,7 +323,7 @@ class Softmax(gof.Op):
...
@@ -322,7 +323,7 @@ class Softmax(gof.Op):
raise
ValueError
(
'x must be 1-d or 2-d tensor of floats'
)
raise
ValueError
(
'x must be 1-d or 2-d tensor of floats'
)
if
x
.
ndim
==
1
:
if
x
.
ndim
==
1
:
x
=
tensor
.
shape_padleft
(
x
,
n_ones
=
1
)
x
=
tensor
.
shape_padleft
(
x
,
n_ones
=
1
)
return
gof
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
x
,
=
input_storage
x
,
=
input_storage
...
@@ -449,7 +450,7 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
...
@@ -449,7 +450,7 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
# nll = TensorType(x.dtype, y.broadcastable)
# nll = TensorType(x.dtype, y.broadcastable)
sm
=
x
.
type
.
make_variable
()
sm
=
x
.
type
.
make_variable
()
am
=
y_idx
.
type
.
make_variable
()
am
=
y_idx
.
type
.
make_variable
()
return
gof
.
Apply
(
self
,
[
x
,
b
,
y_idx
],
[
nll
,
sm
,
am
])
return
Apply
(
self
,
[
x
,
b
,
y_idx
],
[
nll
,
sm
,
am
])
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
"""
"""
The math, where x is an input vector, and t is a target index:
The math, where x is an input vector, and t is a target index:
...
@@ -627,7 +628,7 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
...
@@ -627,7 +628,7 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
dy
=
tensor
.
as_tensor_variable
(
dy
)
dy
=
tensor
.
as_tensor_variable
(
dy
)
sm
=
tensor
.
as_tensor_variable
(
sm
)
sm
=
tensor
.
as_tensor_variable
(
sm
)
y_idx
=
tensor
.
as_tensor_variable
(
y_idx
)
y_idx
=
tensor
.
as_tensor_variable
(
y_idx
)
return
gof
.
Apply
(
self
,
[
dy
,
sm
,
y_idx
],[
sm
.
type
.
make_variable
()])
return
Apply
(
self
,
[
dy
,
sm
,
y_idx
],[
sm
.
type
.
make_variable
()])
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
def
perform
(
self
,
node
,
input_storage
,
output_storage
):
dy
,
sm
,
y_idx
=
input_storage
dy
,
sm
,
y_idx
=
input_storage
dx
=
numpy
.
zeros_like
(
sm
)
dx
=
numpy
.
zeros_like
(
sm
)
...
@@ -765,7 +766,7 @@ class CrossentropyCategorical1HotGrad(gof.Op):
...
@@ -765,7 +766,7 @@ class CrossentropyCategorical1HotGrad(gof.Op):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
def
make_node
(
self
,
g_y
,
coding_dist
,
true_one_of_n
):
def
make_node
(
self
,
g_y
,
coding_dist
,
true_one_of_n
):
return
gof
.
Apply
(
self
,
[
g_y
,
coding_dist
,
true_one_of_n
],
[
coding_dist
.
type
()])
return
Apply
(
self
,
[
g_y
,
coding_dist
,
true_one_of_n
],
[
coding_dist
.
type
()])
def
perform
(
self
,
node
,
(
g_y
,
coding_dist
,
true_one_of_n
),
(
g_coding_strg
,)):
def
perform
(
self
,
node
,
(
g_y
,
coding_dist
,
true_one_of_n
),
(
g_coding_strg
,)):
g_coding
=
numpy
.
zeros_like
(
coding_dist
)
g_coding
=
numpy
.
zeros_like
(
coding_dist
)
for
i
in
xrange
(
len
(
g_y
)):
for
i
in
xrange
(
len
(
g_y
)):
...
@@ -813,7 +814,7 @@ class CrossentropyCategorical1Hot(gof.Op):
...
@@ -813,7 +814,7 @@ class CrossentropyCategorical1Hot(gof.Op):
'(got type:
%
s instead of:
%
s)'
%
(
_true_one_of_n
.
type
,
'(got type:
%
s instead of:
%
s)'
%
(
_true_one_of_n
.
type
,
tensor
.
lvector
))
tensor
.
lvector
))
return
gof
.
Apply
(
self
,
[
_coding_dist
,
_true_one_of_n
],
return
Apply
(
self
,
[
_coding_dist
,
_true_one_of_n
],
[
tensor
.
Tensor
(
dtype
=
_coding_dist
.
dtype
,
broadcastable
=
[
False
])()])
[
tensor
.
Tensor
(
dtype
=
_coding_dist
.
dtype
,
broadcastable
=
[
False
])()])
def
perform
(
self
,
node
,
(
coding
,
one_of_n
),
(
y_out
,)):
def
perform
(
self
,
node
,
(
coding
,
one_of_n
),
(
y_out
,)):
...
@@ -1270,7 +1271,7 @@ class Prepend_scalar_constant_to_each_row(gof.Op):
...
@@ -1270,7 +1271,7 @@ class Prepend_scalar_constant_to_each_row(gof.Op):
if
x
.
type
.
dtype
!=
y
.
type
.
dtype
:
if
x
.
type
.
dtype
!=
y
.
type
.
dtype
:
TypeError
(
"the value to prepend don't have the same type as the matrix"
)
TypeError
(
"the value to prepend don't have the same type as the matrix"
)
node
=
gof
.
Apply
(
op
=
self
,
inputs
=
[
mat
],
outputs
=
[
tensor
.
matrix
()])
node
=
Apply
(
op
=
self
,
inputs
=
[
mat
],
outputs
=
[
tensor
.
matrix
()])
return
node
return
node
def
perform
(
self
,
node
,
(
mat
,
),
(
output
,
)):
def
perform
(
self
,
node
,
(
mat
,
),
(
output
,
)):
...
@@ -1311,7 +1312,7 @@ class Prepend_scalar_to_each_row(gof.Op):
...
@@ -1311,7 +1312,7 @@ class Prepend_scalar_to_each_row(gof.Op):
if
x
.
type
.
dtype
!=
y
.
type
.
dtype
:
if
x
.
type
.
dtype
!=
y
.
type
.
dtype
:
TypeError
(
"the value to prepend don't have the same type as the matrix"
)
TypeError
(
"the value to prepend don't have the same type as the matrix"
)
node
=
gof
.
Apply
(
op
=
self
,
inputs
=
[
val
,
mat
],
outputs
=
[
tensor
.
matrix
()])
node
=
Apply
(
op
=
self
,
inputs
=
[
val
,
mat
],
outputs
=
[
tensor
.
matrix
()])
return
node
return
node
def
perform
(
self
,
node
,
(
val
,
mat
),
(
output
,
)):
def
perform
(
self
,
node
,
(
val
,
mat
),
(
output
,
)):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论