Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fcfa049f
提交
fcfa049f
authored
12月 21, 2015
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
7197ebcd
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
31 行增加
和
29 行删除
+31
-29
multinomial.py
theano/sandbox/multinomial.py
+0
-1
test_rng_mrg.py
theano/sandbox/tests/test_rng_mrg.py
+31
-27
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/sandbox/multinomial.py
浏览文件 @
fcfa049f
...
@@ -172,7 +172,6 @@ class MultinomialFromUniform(Op):
...
@@ -172,7 +172,6 @@ class MultinomialFromUniform(Op):
nb_multi
=
pvals
.
shape
[
0
]
nb_multi
=
pvals
.
shape
[
0
]
nb_outcomes
=
pvals
.
shape
[
1
]
nb_outcomes
=
pvals
.
shape
[
1
]
# For each multinomial, loop over each possible outcome
# For each multinomial, loop over each possible outcome
for
c
in
range
(
n_samples
):
for
c
in
range
(
n_samples
):
for
n
in
range
(
nb_multi
):
for
n
in
range
(
nb_multi
):
...
...
theano/sandbox/tests/test_rng_mrg.py
浏览文件 @
fcfa049f
...
@@ -15,13 +15,12 @@ from theano import tensor, config
...
@@ -15,13 +15,12 @@ from theano import tensor, config
from
theano.sandbox
import
rng_mrg
from
theano.sandbox
import
rng_mrg
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
from
theano.sandbox.cuda
import
cuda_available
from
theano.sandbox.cuda
import
cuda_available
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests.unittest_tools
import
attr
if
cuda_available
:
if
cuda_available
:
from
theano.sandbox.cuda
import
float32_shared_constructor
from
theano.sandbox.cuda
import
float32_shared_constructor
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests.unittest_tools
import
attr
# TODO: test gpu
# TODO: test gpu
# Done in test_consistency_GPU_{serial,parallel}
# Done in test_consistency_GPU_{serial,parallel}
...
@@ -474,8 +473,8 @@ def basictest(f, steps, sample_size, prefix="", allow_01=False, inputs=None,
...
@@ -474,8 +473,8 @@ def basictest(f, steps, sample_size, prefix="", allow_01=False, inputs=None,
else
:
else
:
alpha
=
1.0
/
(
1
+
i
)
alpha
=
1.0
/
(
1
+
i
)
mean
=
alpha
*
ival
+
(
1
-
alpha
)
*
mean
mean
=
alpha
*
ival
+
(
1
-
alpha
)
*
mean
avg_var
=
(
alpha
*
numpy
.
mean
((
ival
-
target_avg
)
**
2
)
avg_var
=
(
alpha
*
numpy
.
mean
((
ival
-
target_avg
)
**
2
)
+
+
(
1
-
alpha
)
*
avg_var
)
(
1
-
alpha
)
*
avg_var
)
min_
=
min
(
min_
,
ival
.
min
())
min_
=
min
(
min_
,
ival
.
min
())
max_
=
max
(
max_
,
ival
.
max
())
max_
=
max
(
max_
,
ival
.
max
())
if
not
allow_01
:
if
not
allow_01
:
...
@@ -487,7 +486,8 @@ def basictest(f, steps, sample_size, prefix="", allow_01=False, inputs=None,
...
@@ -487,7 +486,8 @@ def basictest(f, steps, sample_size, prefix="", allow_01=False, inputs=None,
# print prefix, 'mean diff with mean', diff
# print prefix, 'mean diff with mean', diff
assert
numpy
.
all
(
diff
<
mean_rtol
*
(
1
+
abs
(
target_avg
))),
(
assert
numpy
.
all
(
diff
<
mean_rtol
*
(
1
+
abs
(
target_avg
))),
(
'bad mean?
%
s
%
s'
%
(
mean
,
target_avg
))
'bad mean?
%
s
%
s'
%
(
mean
,
target_avg
))
else
:
# if target_avg is a scalar, then we can do the mean of
else
:
# if target_avg is a scalar, then we can do the mean of
# `mean` to get something more precise
# `mean` to get something more precise
mean
=
numpy
.
mean
(
mean
)
mean
=
numpy
.
mean
(
mean
)
# print prefix, 'mean', mean
# print prefix, 'mean', mean
...
@@ -507,11 +507,11 @@ def basictest(f, steps, sample_size, prefix="", allow_01=False, inputs=None,
...
@@ -507,11 +507,11 @@ def basictest(f, steps, sample_size, prefix="", allow_01=False, inputs=None,
def
test_uniform
():
def
test_uniform
():
# TODO: test param low, high
# TODO: test param low, high
# TODO: test size=None
# TODO: test size=None
# TODO: test ndim!=size.ndim
# TODO: test ndim!=size.ndim
# TODO: test bad seed
# TODO: test bad seed
# TODO: test size=Var, with shape that change from call to call
# TODO: test size=Var, with shape that change from call to call
if
(
mode
in
[
'DEBUG_MODE'
,
'DebugMode'
,
'FAST_COMPILE'
]
or
if
(
mode
in
[
'DEBUG_MODE'
,
'DebugMode'
,
'FAST_COMPILE'
]
or
mode
==
'Mode'
and
config
.
linker
in
[
'py'
]):
mode
==
'Mode'
and
config
.
linker
in
[
'py'
]):
sample_size
=
(
10
,
100
)
sample_size
=
(
10
,
100
)
...
@@ -531,7 +531,7 @@ def test_uniform():
...
@@ -531,7 +531,7 @@ def test_uniform():
((),
(),
[],
[]),
((),
(),
[],
[]),
]:
]:
#
### TEST CPU IMPLEMENTATION ####
#
TEST CPU IMPLEMENTATION
# The python and C implementation are tested with DebugMode
# The python and C implementation are tested with DebugMode
# print ''
# print ''
# print 'ON CPU with size=(%s):' % str(size)
# print 'ON CPU with size=(%s):' % str(size)
...
@@ -598,13 +598,13 @@ def test_uniform():
...
@@ -598,13 +598,13 @@ def test_uniform():
@attr
(
'slow'
)
@attr
(
'slow'
)
def
test_binomial
():
def
test_binomial
():
# TODO: test size=None, ndim=X
# TODO: test size=None, ndim=X
# TODO: test size=X, ndim!=X.ndim
# TODO: test size=X, ndim!=X.ndim
# TODO: test random seed in legal value(!=0 and other)
# TODO: test random seed in legal value(!=0 and other)
# TODO: test sample_size not a multiple of guessed #streams
# TODO: test sample_size not a multiple of guessed #streams
# TODO: test size=Var, with shape that change from call to call
# TODO: test size=Var, with shape that change from call to call
# we test size in a tuple of int and a tensor.shape.
# we test size in a tuple of int and a tensor.shape.
# we test the param p with int.
# we test the param p with int.
if
(
mode
in
[
'DEBUG_MODE'
,
'DebugMode'
,
'FAST_COMPILE'
]
or
if
(
mode
in
[
'DEBUG_MODE'
,
'DebugMode'
,
'FAST_COMPILE'
]
or
mode
==
'Mode'
and
config
.
linker
in
[
'py'
]):
mode
==
'Mode'
and
config
.
linker
in
[
'py'
]):
...
@@ -617,7 +617,6 @@ def test_binomial():
...
@@ -617,7 +617,6 @@ def test_binomial():
rtol
=
0.01
rtol
=
0.01
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
v
=
tensor
.
vector
()
for
mean
in
[
0.1
,
0.5
]:
for
mean
in
[
0.1
,
0.5
]:
for
size
,
const_size
,
var_input
,
input
in
[
for
size
,
const_size
,
var_input
,
input
in
[
(
sample_size
,
sample_size
,
[],
[]),
(
sample_size
,
sample_size
,
[],
[]),
...
@@ -821,7 +820,8 @@ def test_multinomial():
...
@@ -821,7 +820,8 @@ def test_multinomial():
f
=
theano
.
function
([],
m
,
mode
=
mode_
)
f
=
theano
.
function
([],
m
,
mode
=
mode_
)
# theano.printing.debugprint(f)
# theano.printing.debugprint(f)
out
=
f
()
out
=
f
()
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
n_samples
=
1
,
prefix
=
'mrg '
)
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
n_samples
=
1
,
prefix
=
'mrg '
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
...
@@ -842,7 +842,8 @@ def test_multinomial():
...
@@ -842,7 +842,8 @@ def test_multinomial():
# theano.printing.debugprint(f)
# theano.printing.debugprint(f)
gpu_out
=
f
()
gpu_out
=
f
()
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
n_samples
=
1
,
prefix
=
'gpu mrg '
)
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
n_samples
=
1
,
prefix
=
'gpu mrg '
)
numpy
.
testing
.
assert_array_almost_equal
(
out
,
gpu_out
,
decimal
=
6
)
numpy
.
testing
.
assert_array_almost_equal
(
out
,
gpu_out
,
decimal
=
6
)
...
@@ -863,15 +864,18 @@ def test_multinomial_n_samples():
...
@@ -863,15 +864,18 @@ def test_multinomial_n_samples():
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
for
n_samples
,
steps
in
zip
([
5
,
10
,
100
,
1000
],
[
20
,
10
,
1
,
1
]):
for
n_samples
,
steps
in
zip
([
5
,
10
,
100
,
1000
],
[
20
,
10
,
1
,
1
]):
m
=
R
.
multinomial
(
pvals
=
pvals
,
n
=
n_samples
,
dtype
=
config
.
floatX
,
nstreams
=
30
*
256
)
m
=
R
.
multinomial
(
pvals
=
pvals
,
n
=
n_samples
,
dtype
=
config
.
floatX
,
nstreams
=
30
*
256
)
f
=
theano
.
function
([],
m
,
mode
=
mode_
)
f
=
theano
.
function
([],
m
,
mode
=
mode_
)
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
n_samples
,
prefix
=
'mrg '
)
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
n_samples
,
prefix
=
'mrg '
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
if
mode
!=
'FAST_COMPILE'
and
cuda_available
:
if
mode
!=
'FAST_COMPILE'
and
cuda_available
:
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
pvals
=
numpy
.
asarray
(
pvals
,
dtype
=
'float32'
)
pvals
=
numpy
.
asarray
(
pvals
,
dtype
=
'float32'
)
n
=
R
.
multinomial
(
pvals
=
pvals
,
n
=
n_samples
,
dtype
=
'float32'
,
nstreams
=
30
*
256
)
n
=
R
.
multinomial
(
pvals
=
pvals
,
n
=
n_samples
,
dtype
=
'float32'
,
nstreams
=
30
*
256
)
assert
n
.
dtype
==
'float32'
assert
n
.
dtype
==
'float32'
f
=
theano
.
function
(
f
=
theano
.
function
(
[],
[],
...
@@ -879,7 +883,8 @@ def test_multinomial_n_samples():
...
@@ -879,7 +883,8 @@ def test_multinomial_n_samples():
mode
=
mode_
.
including
(
'gpu'
))
mode
=
mode_
.
including
(
'gpu'
))
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
n_samples
,
prefix
=
'gpu mrg '
)
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
n_samples
,
prefix
=
'gpu mrg '
)
class
T_MRG
(
unittest
.
TestCase
):
class
T_MRG
(
unittest
.
TestCase
):
...
@@ -1039,7 +1044,6 @@ def test_seed_fn():
...
@@ -1039,7 +1044,6 @@ def test_seed_fn():
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
rng
=
MRG_RandomStreams
(
numpy
.
random
.
randint
(
2147462579
))
rng
=
MRG_RandomStreams
(
numpy
.
random
.
randint
(
2147462579
))
import
time
print
(
theano
.
__file__
)
print
(
theano
.
__file__
)
pvals
=
theano
.
tensor
.
fmatrix
()
pvals
=
theano
.
tensor
.
fmatrix
()
for
i
in
range
(
10
):
for
i
in
range
(
10
):
...
...
theano/tests/test_flake8.py
浏览文件 @
fcfa049f
...
@@ -102,7 +102,6 @@ whitelist_flake8 = [
...
@@ -102,7 +102,6 @@ whitelist_flake8 = [
"sandbox/debug.py"
,
"sandbox/debug.py"
,
"sandbox/tests/test_theano_object.py"
,
"sandbox/tests/test_theano_object.py"
,
"sandbox/tests/test_scan.py"
,
"sandbox/tests/test_scan.py"
,
"sandbox/tests/test_rng_mrg.py"
,
"sandbox/tests/test_neighbourhoods.py"
,
"sandbox/tests/test_neighbourhoods.py"
,
"sandbox/tests/__init__.py"
,
"sandbox/tests/__init__.py"
,
"sandbox/cuda/var.py"
,
"sandbox/cuda/var.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论