Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dd6d2b15
提交
dd6d2b15
authored
4月 24, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
7c91cce4
d2324428
全部展开
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
140 行增加
和
0 行删除
+140
-0
basic.py
theano/scalar/basic.py
+12
-0
nnet.py
theano/tensor/nnet.py
+0
-0
test_nnet.py
theano/tensor/tests/test_nnet.py
+128
-0
没有找到文件。
theano/scalar/basic.py
浏览文件 @
dd6d2b15
...
@@ -378,6 +378,8 @@ class LT(LogicalComparison):
...
@@ -378,6 +378,8 @@ class LT(LogicalComparison):
associative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
<
y
return
x
<
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = (
%(x)
s <
%(y)
s);"
%
locals
()
lt
=
LT
()
lt
=
LT
()
class
GT
(
LogicalComparison
):
class
GT
(
LogicalComparison
):
...
@@ -386,6 +388,8 @@ class GT(LogicalComparison):
...
@@ -386,6 +388,8 @@ class GT(LogicalComparison):
associative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
>
y
return
x
>
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = (
%(x)
s >
%(y)
s);"
%
locals
()
gt
=
GT
()
gt
=
GT
()
class
LE
(
LogicalComparison
):
class
LE
(
LogicalComparison
):
...
@@ -394,6 +398,8 @@ class LE(LogicalComparison):
...
@@ -394,6 +398,8 @@ class LE(LogicalComparison):
associative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
<=
y
return
x
<=
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = (
%(x)
s <=
%(y)
s);"
%
locals
()
le
=
LE
()
le
=
LE
()
class
GE
(
LogicalComparison
):
class
GE
(
LogicalComparison
):
...
@@ -402,6 +408,8 @@ class GE(LogicalComparison):
...
@@ -402,6 +408,8 @@ class GE(LogicalComparison):
associative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
>=
y
return
x
>=
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = (
%(x)
s >=
%(y)
s);"
%
locals
()
ge
=
GE
()
ge
=
GE
()
class
EQ
(
LogicalComparison
):
class
EQ
(
LogicalComparison
):
...
@@ -410,6 +418,8 @@ class EQ(LogicalComparison):
...
@@ -410,6 +418,8 @@ class EQ(LogicalComparison):
associative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
==
y
return
x
==
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = (
%(x)
s ==
%(y)
s);"
%
locals
()
eq
=
EQ
()
eq
=
EQ
()
class
NEQ
(
LogicalComparison
):
class
NEQ
(
LogicalComparison
):
...
@@ -418,6 +428,8 @@ class NEQ(LogicalComparison):
...
@@ -418,6 +428,8 @@ class NEQ(LogicalComparison):
associative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
!=
y
return
x
!=
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = (
%(x)
s !=
%(y)
s);"
%
locals
()
neq
=
NEQ
()
neq
=
NEQ
()
class
InRange
(
LogicalComparison
):
class
InRange
(
LogicalComparison
):
...
...
theano/tensor/nnet.py
浏览文件 @
dd6d2b15
差异被折叠。
点击展开。
theano/tensor/tests/test_nnet.py
浏览文件 @
dd6d2b15
...
@@ -123,5 +123,133 @@ class T_solve(unittest.TestCase):
...
@@ -123,5 +123,133 @@ class T_solve(unittest.TestCase):
#print numpy.dot(A,x)
#print numpy.dot(A,x)
class
T_CrossentropyCategorical1Hot
(
unittest
.
TestCase
):
def
setUp
(
self
):
utt
.
seed_rng
()
def
test_grad
(
self
):
x
=
tensor
.
matrix
(
'x'
)
one_of_n
=
tensor
.
lvector
(
'one_of_n'
)
op
=
crossentropy_categorical_1hot
xe
=
op
(
x
,
one_of_n
)
f
=
theano
.
function
([
x
,
one_of_n
],
xe
)
xe_val
=
f
(
numpy
.
asarray
([[
.
4
,
.
6
,
.
0
],
[
.
1
,
.
8
,
.
1
]]),
[
0
,
1
])
assert
numpy
.
allclose
(
xe_val
,
-
numpy
.
log
([
.
4
,
.
8
]))
def
oplike
(
x
):
return
op
(
x
,
[
0
,
1
])
tensor
.
verify_grad
(
oplike
,
[
numpy
.
asarray
([[
.
4
,
.
6
,
.
0
],
[
.
1
,
.
8
,
.
1
]])],
rng
=
numpy
.
random
)
def
test_softmax_optimizations
(
self
):
x
=
tensor
.
matrix
(
'x'
)
one_of_n
=
tensor
.
lvector
(
'one_of_n'
)
op
=
crossentropy_categorical_1hot
xe
=
op
(
x
,
one_of_n
)
env
=
gof
.
Env
(
[
x
,
one_of_n
],
[
op
(
softmax
(
x
),
one_of_n
)])
assert
env
.
outputs
[
0
]
.
owner
.
op
==
op
theano
.
compile
.
mode
.
optdb
.
query
(
theano
.
compile
.
mode
.
OPT_FAST_RUN
)
.
optimize
(
env
)
assert
env
.
outputs
[
0
]
.
owner
.
op
==
crossentropy_softmax_argmax_1hot_with_bias
def
test_softmax_optimizations_w_bias
(
self
):
x
=
tensor
.
matrix
(
'x'
)
b
=
tensor
.
vector
(
'b'
)
one_of_n
=
tensor
.
lvector
(
'one_of_n'
)
op
=
crossentropy_categorical_1hot
xe
=
op
(
x
,
one_of_n
)
env
=
gof
.
Env
(
[
x
,
b
,
one_of_n
],
[
op
(
softmax
(
x
+
b
),
one_of_n
)])
assert
env
.
outputs
[
0
]
.
owner
.
op
==
op
print
'BEFORE'
for
node
in
env
.
toposort
():
print
node
.
op
print
'----'
theano
.
compile
.
mode
.
optdb
.
query
(
theano
.
compile
.
mode
.
OPT_FAST_RUN
)
.
optimize
(
env
)
assert
len
(
env
.
toposort
())
==
1
assert
env
.
outputs
[
0
]
.
owner
.
op
==
crossentropy_softmax_argmax_1hot_with_bias
def
test_softmax_grad_optimizations
(
self
):
x
=
tensor
.
matrix
(
'x'
)
one_of_n
=
tensor
.
lvector
(
'one_of_n'
)
op
=
crossentropy_categorical_1hot
xe
=
op
(
softmax
(
x
),
one_of_n
)
sum_xe
=
tensor
.
sum
(
xe
)
g_x
=
tensor
.
grad
(
sum_xe
,
x
)
env
=
gof
.
Env
(
[
x
,
one_of_n
],
[
g_x
])
print
'BEFORE'
for
node
in
env
.
toposort
():
print
node
.
op
print
'----'
theano
.
compile
.
mode
.
optdb
.
query
(
theano
.
compile
.
mode
.
OPT_FAST_RUN
)
.
optimize
(
env
)
print
'AFTER'
for
node
in
env
.
toposort
():
print
node
.
op
assert
env
.
toposort
()[
3
]
.
op
==
crossentropy_softmax_argmax_1hot_with_bias
assert
env
.
toposort
()[
5
]
.
op
==
crossentropy_softmax_1hot_with_bias_dx
assert
len
(
env
.
toposort
())
==
6
#shorthand for actually checking what I really
def
test_argmax_pushdown
():
x
=
tensor
.
dmatrix
()
env
=
gof
.
Env
(
[
x
],
[
tensor
.
max
(
softmax
(
tensor
.
exp
(
tensor
.
tanh
(
sigmoid
(
x
)))))])
theano
.
compile
.
mode
.
optdb
.
query
(
theano
.
compile
.
mode
.
OPT_FAST_RUN
)
.
optimize
(
env
)
#print 'AFTER'
#for node in env.toposort():
#print node.op
assert
len
(
env
.
toposort
())
==
1
assert
env
.
toposort
()[
0
]
.
op
==
tensor
.
_max_and_argmax
def
test_argmax_pushdown_bias
():
x
=
tensor
.
dmatrix
()
b
=
tensor
.
dvector
()
env
=
gof
.
Env
(
[
x
,
b
],
[
tensor
.
max
(
softmax_with_bias
(
x
,
b
))])
theano
.
compile
.
mode
.
optdb
.
query
(
theano
.
compile
.
mode
.
OPT_FAST_RUN
)
.
optimize
(
env
)
#print 'AFTER'
#for node in env.toposort():
#print node.op
assert
len
(
env
.
toposort
())
==
3
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论