Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bc578962
提交
bc578962
authored
1月 25, 2012
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #385 from delallea/minor
Minor stuff Thanks Olivier :) Is great to have someone like you involved in the project, that is able to notice and fix all the small details.
上级
f2743791
cdcef8f2
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
30 行增加
和
24 行删除
+30
-24
scan_utils.py
theano/sandbox/scan_module/scan_utils.py
+2
-2
test_scan.py
theano/sandbox/scan_module/tests/test_scan.py
+22
-16
scan_utils.py
theano/scan_module/scan_utils.py
+2
-2
test_scan.py
theano/scan_module/tests/test_scan.py
+4
-4
没有找到文件。
theano/sandbox/scan_module/scan_utils.py
浏览文件 @
bc578962
...
...
@@ -110,7 +110,7 @@ def get_updates_and_outputs(ls):
raise
ValueError
((
'Scan can not parse the return value'
' of your constructive function given to scan'
))
ls
=
list
(
ls
)
depr
i
cation_msg
=
(
'The return value of the lambda function'
depr
e
cation_msg
=
(
'The return value of the lambda function'
' has been restricted. you have to always return first the'
' outputs (if any), afterwards the updates (if any) and'
' at the end the condition'
)
...
...
@@ -126,7 +126,7 @@ def get_updates_and_outputs(ls):
raise
ValueError
(
error_msg
)
elif
is_updates
(
ls
[
0
]):
if
is_outputs
(
ls
[
1
]):
raise
ValueError
(
depr
i
cation_msg
)
raise
ValueError
(
depr
e
cation_msg
)
elif
is_condition
(
ls
[
1
]):
return
(
ls
[
1
]
.
condition
,
[],
dict
(
ls
[
0
]))
else
:
...
...
theano/sandbox/scan_module/tests/test_scan.py
浏览文件 @
bc578962
...
...
@@ -135,7 +135,7 @@ class TestScan(unittest.TestCase):
else
:
shared_outs
=
[
sh
*
5
for
sh
in
shared_vars
]
states_out
=
[
x
for
x
in
states_out
]
pure_outs
=
[
2
for
x
in
xrange
(
n_outputs
)]
pure_outs
=
[
2
for
x
in
xrange
(
n_outputs
)]
return
states_out
+
pure_outs
,
dict
(
zip
(
shared_vars
,
shared_outs
))
...
...
@@ -220,7 +220,7 @@ class TestScan(unittest.TestCase):
if
to_add
is
not
None
:
shared_values
=
[
sh
*
5
+
to_add
for
sh
in
shared_values
]
for
state
in
nw_states_outs
:
state
[
step
]
+=
to_add
state
[
step
]
+=
to_add
for
out
in
out_mem_buffers
:
out
[
step
]
=
to_add
**
2
else
:
...
...
@@ -249,7 +249,7 @@ class TestScan(unittest.TestCase):
if
n_steps
is
not
None
and
abs
(
n_steps
)
==
1
:
all_nodes
=
my_f
.
maker
.
env
.
toposort
()
assert
len
([
x
for
x
in
all_nodes
if
isinstance
(
x
.
op
,
ScanOp
)])
==
0
if
isinstance
(
x
.
op
,
ScanOp
)])
==
0
print
>>
sys
.
stderr
,
' n_steps'
,
n_steps
print
>>
sys
.
stderr
,
' go_backwards'
,
go_backwards
...
...
@@ -300,12 +300,14 @@ class TestScan(unittest.TestCase):
try
:
assert
numpy
.
allclose
(
th_out
,
num_out
)
except
:
import
ipdb
;
ipdb
.
set_trace
()
#import ipdb; ipdb.set_trace()
raise
for
th_out
,
num_out
in
zip
(
shared_vars
,
numpy_shared
):
try
:
assert
numpy
.
allclose
(
th_out
.
get_value
(),
num_out
)
except
:
import
ipdb
;
ipdb
.
set_trace
()
#import ipdb; ipdb.set_trace()
raise
# Scenario 2 : Loose fit (sequences longer then required)
print
>>
sys
.
stderr
,
' Scenario 2. Loose shapes'
input_values
=
[]
...
...
@@ -319,7 +321,8 @@ class TestScan(unittest.TestCase):
if
n_steps
is
not
None
:
# loose inputs make sense only when n_steps is
# defined
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
+
pos
+
1
,
4
))
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
+
pos
+
1
,
4
))
else
:
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
,
4
))
input_values
.
append
(
data
)
...
...
@@ -400,9 +403,9 @@ class TestScan(unittest.TestCase):
[
dict
(
tap
=-
2
,
use
=
True
),
dict
(
tap
=
3
,
use
=
True
)]]
test_nb
=
0
for
n_ins
in
[
1
,
2
]:
for
n_ins
in
[
1
,
2
]:
# Randomly pick up 4*n_ins combinations of arguments
for
k
in
xrange
(
4
*
n_ins
):
for
k
in
xrange
(
4
*
n_ins
):
inp
=
[]
for
inp_nb
in
xrange
(
n_ins
):
...
...
@@ -424,9 +427,9 @@ class TestScan(unittest.TestCase):
dict
(
tap
=-
2
,
use
=
True
)],
[
dict
(
tap
=-
4
,
use
=
False
),
dict
(
tap
=-
2
,
use
=
True
)]]
for
n_ins
in
[
1
,
2
]:
for
n_ins
in
[
1
,
2
]:
# Randomly pick up 4*n_ins combinations of arguments
for
k
in
xrange
(
4
*
n_ins
):
for
k
in
xrange
(
4
*
n_ins
):
state
=
[]
for
state_nb
in
xrange
(
n_ins
):
pos
=
rng
.
randint
(
len
(
possible_taps_use_pairs
))
...
...
@@ -442,8 +445,8 @@ class TestScan(unittest.TestCase):
# The test will also have to be changesd following some further
# restriction of scan and reduction of the number of corner cases
return
for
n_outputs
in
[
0
,
1
,
2
]:
for
n_shared_updates
in
[
0
,
1
,
2
]:
for
n_outputs
in
[
0
,
1
,
2
]:
for
n_shared_updates
in
[
0
,
1
,
2
]:
for
n_random_combinations
in
xrange
(
1
):
pos_inp
=
rng
.
randint
(
len
(
all_inputs_info
))
pos_st
=
rng
.
randint
(
len
(
all_states_info
))
...
...
@@ -463,14 +466,14 @@ class TestScan(unittest.TestCase):
n_outputs
=
n_outputs
,
n_shared_updates
=
n_shared_updates
)
def
test002_generator_one_scalar_output
(
self
):
# The test fails, because the `work-in-progress` ScanOp always runs in
# place (even when told not to by DebugMode). As this op will change
# soon, and it is in the sandbox and not for user consumption, the
# error is marked as KnownFailure
raise
KnownFailureTest
raise
KnownFailureTest
(
'Work-in-progress sandbox ScanOp is not fully '
'functional yet'
)
def
f_pow2
(
x_tm1
):
return
2
*
x_tm1
...
...
@@ -505,7 +508,10 @@ class TestScan(unittest.TestCase):
# place (even when told not to by DebugMode). As this op will change
# soon, and it is in the sandbox and not for user consumption, the
# error is marked as KnownFailure
raise
KnownFailureTest
raise
KnownFailureTest
(
'Work-in-progress sandbox ScanOp is not fully '
'functional yet'
)
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
return
u_t
*
W_in
+
x_tm1
*
W
u
=
theano
.
tensor
.
vector
(
'u'
)
...
...
theano/scan_module/scan_utils.py
浏览文件 @
bc578962
...
...
@@ -225,7 +225,7 @@ def get_updates_and_outputs(ls):
if
not
isinstance
(
ls
,
(
list
,
tuple
)):
raise
ValueError
(
error_msg
)
ls
=
list
(
ls
)
depr
i
cation_msg
=
(
'The return value of the lambda function'
depr
e
cation_msg
=
(
'The return value of the lambda function'
' has been restricted. you have to always return first the'
' outputs (if any), afterwards the updates (if any) and'
' at the end the conclusion'
)
...
...
@@ -239,7 +239,7 @@ def get_updates_and_outputs(ls):
raise
ValueError
(
error_msg
)
elif
is_updates
(
ls
[
0
]):
if
is_outputs
(
ls
[
1
]):
raise
ValueError
(
depr
i
cation_msg
)
raise
ValueError
(
depr
e
cation_msg
)
elif
is_condition
(
ls
[
1
]):
return
(
ls
[
1
]
.
condition
,
[],
dict
(
ls
[
0
]))
else
:
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
bc578962
...
...
@@ -1571,7 +1571,7 @@ class T_Scan(unittest.TestCase):
# trng = theano.tensor.shared_randomstreams.RandomStreams(
# utt.fetch_seed())
def
f_rnn_cmpl
(
u_t
,
x_tm1
,
W_in
):
def
f_rnn_cmpl
(
u_t
,
x_tm1
,
W_in
):
trng1
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
123
)
x_t
=
theano
.
dot
(
u_t
,
W_in
)
+
x_tm1
+
\
trng1
.
uniform
(
low
=-.
1
,
high
=.
1
)
...
...
@@ -2896,11 +2896,11 @@ class T_Scan(unittest.TestCase):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
# If numbers are small, the gradients with respect to x are small
# and the numeric differentiation becomes unstable.
# To fix this issue I
u
nsure we are sampling numbers larger in
# absolute value than 1
# To fix this issue I
e
nsure we are sampling numbers larger in
# absolute value than 1
.
v_x
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
5
,
2
,
2
),
low
=
1.
,
high
=
3.
),
dtype
=
theano
.
config
.
floatX
)
#
making some entries to be negative
#
Making some entries to be negative.
pos
=
rng
.
uniform
(
size
=
(
5
,
2
,
2
),
low
=
0.
,
high
=
1
)
<
.
5
v_x
[
pos
]
=
-
1
*
v_x
[
pos
]
v_w
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
2
,
2
),
low
=
1.
,
high
=
3.
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论