Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
693b6217
提交
693b6217
authored
6月 04, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MRG random, allow for uniform and binomial to have the size being Theano Variable.
Test more case of this Op.
上级
f75f6149
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
128 行增加
和
60 行删除
+128
-60
test_rng_mrg.py
theano/sandbox/test_rng_mrg.py
+128
-60
没有找到文件。
theano/sandbox/test_rng_mrg.py
浏览文件 @
693b6217
...
@@ -278,76 +278,144 @@ def test_consistency_GPU_parallel():
...
@@ -278,76 +278,144 @@ def test_consistency_GPU_parallel():
samples
=
numpy
.
array
(
samples
)
.
flatten
()
samples
=
numpy
.
array
(
samples
)
.
flatten
()
assert
(
numpy
.
allclose
(
samples
,
java_samples
))
assert
(
numpy
.
allclose
(
samples
,
java_samples
))
def
test_rng0
():
def
basictest
(
f
,
steps
,
sample_size
,
prefix
=
""
,
allow_01
=
False
,
inputs
=
[],
mean
=
0.5
,
mean_rtol
=
0.01
):
dt
=
0.0
def
basictest
(
f
,
steps
,
prefix
=
""
,
allow_01
=
False
):
for
i
in
xrange
(
steps
):
dt
=
0.0
t0
=
time
.
time
()
for
i
in
xrange
(
steps
):
ival
=
f
(
*
inputs
)
t0
=
time
.
time
()
dt
+=
time
.
time
()
-
t0
ival
=
f
()
ival
=
numpy
.
asarray
(
ival
)
dt
+=
time
.
time
()
-
t0
if
i
==
0
:
ival
=
numpy
.
asarray
(
ival
)
computed_mean
=
numpy
.
array
(
ival
,
copy
=
True
)
if
i
==
0
:
min_
=
ival
.
min
()
mean
=
numpy
.
array
(
ival
,
copy
=
True
)
max_
=
ival
.
max
()
min_
=
ival
.
min
()
else
:
max_
=
ival
.
max
()
alpha
=
1.0
/
(
1
+
i
)
else
:
computed_mean
=
alpha
*
ival
+
(
1
-
alpha
)
*
computed_mean
alpha
=
1.0
/
(
1
+
i
)
min_
=
min
(
min_
,
ival
.
min
())
mean
=
alpha
*
ival
+
(
1
-
alpha
)
*
mean
max_
=
max
(
max_
,
ival
.
max
())
min_
=
min
(
min_
,
ival
.
min
())
if
not
allow_01
:
max_
=
max
(
max_
,
ival
.
max
())
assert
min_
>
0
if
not
allow_01
:
assert
max_
<
1
assert
min_
>
0
assert
max_
<
1
print
prefix
,
'mean'
,
numpy
.
mean
(
computed_mean
)
assert
abs
(
numpy
.
mean
(
computed_mean
)
-
mean
)
<
mean_rtol
,
'bad mean?'
print
prefix
,
'mean'
,
numpy
.
mean
(
mean
)
print
prefix
,
'time'
,
dt
assert
abs
(
numpy
.
mean
(
mean
)
-
0.5
)
<
.
01
,
'bad mean?'
print
prefix
,
'elements'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
print
prefix
,
'time'
,
dt
print
prefix
,
'samples/sec'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
/
dt
print
prefix
,
'elements'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
print
prefix
,
'min'
,
min_
,
'max'
,
max_
print
prefix
,
'samples/sec'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
/
dt
print
prefix
,
'min'
,
min_
,
'max'
,
max_
def
test_uniform
():
#TODO: test param low, high
#TODO: test size=None
#TODO: test ndim!=size.ndim
#TODO: test bad seed
#TODO: test size=Var, with shape that change from call to call
if
mode
in
[
'DEBUG_MODE'
,
'FAST_COMPILE'
]:
if
mode
in
[
'DEBUG_MODE'
,
'FAST_COMPILE'
]:
sample_size
=
(
10
,
100
)
sample_size
=
(
10
,
100
)
steps
=
int
(
1e2
)
steps
=
int
(
1e2
)
else
:
else
:
sample_size
=
(
10
00
,
100
)
sample_size
=
(
5
00
,
100
)
steps
=
int
(
1e3
)
steps
=
int
(
1e3
)
x
=
tensor
.
matrix
()
for
size
,
var_input
,
input
in
[(
sample_size
,[],[]),
(
x
.
shape
,[
x
],[
numpy
.
zeros
(
sample_size
)])]:
print
''
print
'ON CPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
u
=
R
.
uniform
(
size
=
sample_size
)
f
=
theano
.
function
([],
u
,
mode
=
mode
)
theano
.
printing
.
debugprint
(
f
)
print
'random?[:10]
\n
'
,
f
()[
0
,
0
:
10
]
basictest
(
f
,
steps
,
prefix
=
'mrg cpu'
)
if
mode
!=
'FAST_COMPILE'
:
print
''
print
''
print
'ON
GPU:'
print
'ON
CPU with size=(
%
s):'
%
str
(
size
)
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
x
=
tensor
.
matrix
(
)
u
=
R
.
uniform
(
size
=
sample_size
,
dtype
=
'float32'
)
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
assert
u
.
dtype
==
'float32'
#well, it's really that this test w GPU doesn't make sense otw
u
=
R
.
uniform
(
size
=
size
)
f
=
theano
.
function
(
[],
theano
.
Out
(
f
=
theano
.
function
(
var_input
,
u
,
mode
=
mode
)
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
assert
any
([
isinstance
(
node
.
op
,
theano
.
sandbox
.
rng_mrg
.
mrg_uniform
)
borrow
=
True
),
mode
=
mode
)
for
node
in
f
.
maker
.
env
.
toposort
()]
)
theano
.
printing
.
debugprint
(
f
)
theano
.
printing
.
debugprint
(
f
)
print
'random?[:10]
\n
'
,
numpy
.
asarray
(
f
())[
0
,
0
:
10
]
out
=
f
(
*
input
)
basictest
(
f
,
steps
,
prefix
=
'mrg gpu'
)
print
'random?[:10]
\n
'
,
out
[
0
,
0
:
10
]
#print 'random?[-1,-10:]\n', out[-1,-10:]
print
''
basictest
(
f
,
steps
,
sample_size
,
prefix
=
'mrg cpu'
,
inputs
=
input
)
print
'ON CPU w NUMPY:'
RR
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
234
)
if
mode
!=
'FAST_COMPILE'
:
print
''
uu
=
RR
.
uniform
(
size
=
sample_size
)
print
'ON GPU with size=(
%
s):'
%
str
(
size
)
ff
=
theano
.
function
([],
uu
,
mode
=
mode
)
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
# It's not our problem if numpy generates 0 or 1
u
=
R
.
uniform
(
size
=
size
,
dtype
=
'float32'
)
basictest
(
ff
,
steps
,
prefix
=
'numpy'
,
allow_01
=
True
)
assert
u
.
dtype
==
'float32'
#well, it's really that this test w GPU doesn't make sense otw
f
=
theano
.
function
(
var_input
,
theano
.
Out
(
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
borrow
=
True
),
mode
=
mode
)
assert
any
([
isinstance
(
node
.
op
,
theano
.
sandbox
.
rng_mrg
.
GPU_mrg_uniform
)
for
node
in
f
.
maker
.
env
.
toposort
()])
theano
.
printing
.
debugprint
(
f
)
out
=
numpy
.
asarray
(
f
(
*
input
))
print
'random?[:10]
\n
'
,
out
[
0
,
0
:
10
]
#print 'random?[-1,-10:]\n', out[-1,-10:]
basictest
(
f
,
steps
,
sample_size
,
prefix
=
'mrg gpu'
,
inputs
=
input
)
print
''
print
'ON CPU w Numpy with size=(
%
s):'
%
str
(
size
)
RR
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
234
)
uu
=
RR
.
uniform
(
size
=
size
)
ff
=
theano
.
function
(
var_input
,
uu
,
mode
=
mode
)
# It's not our problem if numpy generates 0 or 1
basictest
(
ff
,
steps
,
sample_size
,
prefix
=
'numpy'
,
allow_01
=
True
,
inputs
=
input
)
def
test_binomial
():
#TODO: test size=None, ndim=X
#TODO: test size=X, ndim!=X.ndim
#TODO: test random seed in legal value(!=0 and other)
#TODO: test sample_size not a multiple of guessed #streams
#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 the param p with int.
if
mode
in
[
'DEBUG_MODE'
,
'FAST_COMPILE'
]:
sample_size
=
(
10
,
50
)
steps
=
int
(
1e2
)
else
:
sample_size
=
(
500
,
100
)
steps
=
int
(
1e3
)
x
=
tensor
.
matrix
()
v
=
tensor
.
vector
()
for
mean
in
[
0.1
,
0.5
]:
for
size
,
var_input
,
input
in
[(
sample_size
,[],[]),
(
x
.
shape
,[
x
],[
numpy
.
zeros
(
sample_size
)])]:
print
''
print
'ON CPU with size=(
%
s) and mean(
%
d):'
%
(
str
(
size
),
mean
)
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
u
=
R
.
binomial
(
size
=
size
,
p
=
mean
)
f
=
theano
.
function
(
var_input
,
u
,
mode
=
mode
)
theano
.
printing
.
debugprint
(
f
)
out
=
f
(
*
input
)
print
'random?[:10]
\n
'
,
out
[
0
,
0
:
10
]
print
'random?[-1,-10:]
\n
'
,
out
[
-
1
,
-
10
:]
basictest
(
f
,
steps
,
sample_size
,
prefix
=
'mrg cpu'
,
inputs
=
input
,
allow_01
=
True
,
mean
=
mean
)
if
mode
!=
'FAST_COMPILE'
:
print
''
print
'ON GPU with size=(
%
s) and mean(
%
d):'
%
(
str
(
size
),
mean
)
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
u
=
R
.
binomial
(
size
=
size
,
p
=
mean
,
dtype
=
'float32'
)
assert
u
.
dtype
==
'float32'
#well, it's really that this test w GPU doesn't make sense otw
f
=
theano
.
function
(
var_input
,
theano
.
Out
(
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
borrow
=
True
),
mode
=
mode
)
theano
.
printing
.
debugprint
(
f
)
out
=
numpy
.
asarray
(
f
(
*
input
))
print
'random?[:10]
\n
'
,
out
[
0
,
0
:
10
]
print
'random?[-1,-10:]
\n
'
,
out
[
-
1
,
-
10
:]
basictest
(
f
,
steps
,
sample_size
,
prefix
=
'mrg gpu'
,
inputs
=
input
,
allow_01
=
True
,
mean
=
mean
)
print
''
print
'ON CPU w NUMPY with size=(
%
s) and mean(
%
d):'
%
(
str
(
size
),
mean
)
RR
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
234
)
uu
=
RR
.
binomial
(
size
=
size
,
p
=
mean
)
ff
=
theano
.
function
(
var_input
,
uu
,
mode
=
mode
)
# It's not our problem if numpy generates 0 or 1
basictest
(
ff
,
steps
,
sample_size
,
prefix
=
'numpy'
,
allow_01
=
True
,
inputs
=
input
,
mean
=
mean
)
def
test_normal0
():
def
test_normal0
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论