Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
c995a2c6
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c995a2c6
编写于
9月 27, 2020
作者:
P
pangyoki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
increase the difference between low and high
上级
cfcc45d9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
14 deletion
+31
-14
python/paddle/fluid/tests/unittests/test_distribution.py
python/paddle/fluid/tests/unittests/test_distribution.py
+31
-14
未找到文件。
python/paddle/fluid/tests/unittests/test_distribution.py
浏览文件 @
c995a2c6
...
...
@@ -123,7 +123,7 @@ class UniformTest(unittest.TestCase):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# low ans high are 'float'
self
.
low_np
=
np
.
random
.
uniform
(
-
2
,
1
)
self
.
high_np
=
np
.
random
.
uniform
(
1
,
3
)
self
.
high_np
=
np
.
random
.
uniform
(
2
,
4
)
self
.
values_np
=
np
.
array
([
1.0
]).
astype
(
'float32'
)
def
init_dynamic_data
(
self
,
batch_size
,
dims
):
...
...
@@ -138,7 +138,7 @@ class UniformTest(unittest.TestCase):
self
.
static_values
=
layers
.
data
(
name
=
'values'
,
shape
=
[],
dtype
=
'float32'
)
def
compare_with_numpy
(
self
,
fetch_list
,
sample_shape
=
7
,
tolerance
=
1e-
4
):
def
compare_with_numpy
(
self
,
fetch_list
,
sample_shape
=
7
,
tolerance
=
1e-
6
):
sample
,
entropy
,
log_prob
,
probs
=
fetch_list
np_uniform
=
UniformNumpy
(
self
.
low_np
,
self
.
high_np
)
...
...
@@ -154,7 +154,7 @@ class UniformTest(unittest.TestCase):
log_prob
,
np_lp
,
rtol
=
tolerance
,
atol
=
tolerance
)
np
.
testing
.
assert_allclose
(
probs
,
np_p
,
rtol
=
tolerance
,
atol
=
tolerance
)
def
test_uniform_distribution_dygraph
(
self
,
sample_shape
=
7
,
tolerance
=
1e-
4
):
def
test_uniform_distribution_dygraph
(
self
,
sample_shape
=
7
,
tolerance
=
1e-
6
):
paddle
.
disable_static
(
self
.
place
)
uniform
=
Uniform
(
self
.
dynamic_low
,
self
.
dynamic_high
)
sample
=
uniform
.
sample
([
sample_shape
]).
numpy
()
...
...
@@ -165,7 +165,7 @@ class UniformTest(unittest.TestCase):
self
.
compare_with_numpy
(
fetch_list
)
def
test_uniform_distribution_static
(
self
,
sample_shape
=
7
,
tolerance
=
1e-
4
):
def
test_uniform_distribution_static
(
self
,
sample_shape
=
7
,
tolerance
=
1e-
6
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
self
.
test_program
):
uniform
=
Uniform
(
self
.
static_low
,
self
.
static_high
)
...
...
@@ -193,7 +193,7 @@ class UniformTest2(UniformTest):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# low ans high are 'int'
self
.
low_np
=
int
(
np
.
random
.
uniform
(
-
2
,
1
))
self
.
high_np
=
int
(
np
.
random
.
uniform
(
1
,
3
))
self
.
high_np
=
int
(
np
.
random
.
uniform
(
2
,
4
))
self
.
values_np
=
np
.
array
([
1.0
]).
astype
(
'float32'
)
...
...
@@ -201,7 +201,7 @@ class UniformTest3(UniformTest):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# test broadcast: low is float, high is numpy.ndarray with dtype 'float32'.
self
.
low_np
=
np
.
random
.
uniform
(
-
2
,
1
)
self
.
high_np
=
np
.
random
.
uniform
(
-
5.0
,
5.0
,
self
.
high_np
=
np
.
random
.
uniform
(
5.0
,
1
5.0
,
(
batch_size
,
dims
)).
astype
(
'float32'
)
self
.
values_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float32'
)
...
...
@@ -217,7 +217,7 @@ class UniformTest4(UniformTest):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# low and high are numpy.ndarray with dtype 'float32'.
self
.
low_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float32'
)
self
.
high_np
=
np
.
random
.
uniform
(
-
5.0
,
5.0
,
self
.
high_np
=
np
.
random
.
uniform
(
5.0
,
1
5.0
,
(
batch_size
,
dims
)).
astype
(
'float32'
)
self
.
values_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float32'
)
...
...
@@ -233,7 +233,7 @@ class UniformTest5(UniformTest):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# low and high are numpy.ndarray with dtype 'float64'.
self
.
low_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float64'
)
self
.
high_np
=
np
.
random
.
uniform
(
-
5.0
,
5.0
,
self
.
high_np
=
np
.
random
.
uniform
(
5.0
,
1
5.0
,
(
batch_size
,
dims
)).
astype
(
'float64'
)
self
.
values_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float64'
)
...
...
@@ -254,7 +254,7 @@ class UniformTest6(UniformTest):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# low and high are Tensor with dtype 'VarType.FP32'.
self
.
low_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float32'
)
self
.
high_np
=
np
.
random
.
uniform
(
-
5.0
,
5.0
,
self
.
high_np
=
np
.
random
.
uniform
(
5.0
,
1
5.0
,
(
batch_size
,
dims
)).
astype
(
'float32'
)
self
.
values_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float32'
)
...
...
@@ -277,7 +277,7 @@ class UniformTest7(UniformTest):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# low and high are Tensor with dtype 'VarType.FP64'.
self
.
low_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float64'
)
self
.
high_np
=
np
.
random
.
uniform
(
-
5.0
,
5.0
,
self
.
high_np
=
np
.
random
.
uniform
(
5.0
,
1
5.0
,
(
batch_size
,
dims
)).
astype
(
'float64'
)
self
.
values_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float64'
)
...
...
@@ -300,7 +300,7 @@ class UniformTest8(UniformTest):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# low and high are Tensor with dtype 'VarType.FP64'. value's dtype is 'VarType.FP32'.
self
.
low_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float64'
)
self
.
high_np
=
np
.
random
.
uniform
(
-
5.0
,
5.0
,
self
.
high_np
=
np
.
random
.
uniform
(
5.0
,
1
5.0
,
(
batch_size
,
dims
)).
astype
(
'float64'
)
self
.
values_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float32'
)
...
...
@@ -319,6 +319,23 @@ class UniformTest8(UniformTest):
name
=
'values'
,
shape
=
[
dims
],
dtype
=
'float32'
)
class
UniformTest9
(
UniformTest
):
def
init_numpy_data
(
self
,
batch_size
,
dims
):
# low and high are numpy.ndarray with dtype 'float32'.
# high < low.
self
.
low_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float32'
)
self
.
high_np
=
np
.
random
.
uniform
(
-
10.0
,
-
5.0
,
(
batch_size
,
dims
)).
astype
(
'float32'
)
self
.
values_np
=
np
.
random
.
randn
(
batch_size
,
dims
).
astype
(
'float32'
)
def
init_static_data
(
self
,
batch_size
,
dims
):
self
.
static_low
=
self
.
low_np
self
.
static_high
=
self
.
high_np
with
fluid
.
program_guard
(
self
.
test_program
):
self
.
static_values
=
layers
.
data
(
name
=
'values'
,
shape
=
[
dims
],
dtype
=
'float32'
)
class
NormalTest
(
unittest
.
TestCase
):
def
setUp
(
self
,
use_gpu
=
False
,
batch_size
=
2
,
dims
=
3
):
self
.
use_gpu
=
use_gpu
...
...
@@ -368,7 +385,7 @@ class NormalTest(unittest.TestCase):
self
.
static_values
=
layers
.
data
(
name
=
'values'
,
shape
=
[],
dtype
=
'float32'
)
def
compare_with_numpy
(
self
,
fetch_list
,
sample_shape
=
7
,
tolerance
=
1e-
4
):
def
compare_with_numpy
(
self
,
fetch_list
,
sample_shape
=
7
,
tolerance
=
1e-
6
):
sample
,
entropy
,
log_prob
,
probs
,
kl
=
fetch_list
np_normal
=
NormalNumpy
(
self
.
loc_np
,
self
.
scale_np
)
...
...
@@ -387,7 +404,7 @@ class NormalTest(unittest.TestCase):
np
.
testing
.
assert_allclose
(
probs
,
np_p
,
rtol
=
tolerance
,
atol
=
tolerance
)
np
.
testing
.
assert_allclose
(
kl
,
np_kl
,
rtol
=
tolerance
,
atol
=
tolerance
)
def
test_normal_distribution_dygraph
(
self
,
sample_shape
=
7
,
tolerance
=
1e-
4
):
def
test_normal_distribution_dygraph
(
self
,
sample_shape
=
7
,
tolerance
=
1e-
6
):
paddle
.
disable_static
(
self
.
place
)
normal
=
Normal
(
self
.
dynamic_loc
,
self
.
dynamic_scale
)
...
...
@@ -401,7 +418,7 @@ class NormalTest(unittest.TestCase):
fetch_list
=
[
sample
,
entropy
,
log_prob
,
probs
,
kl
]
self
.
compare_with_numpy
(
fetch_list
)
def
test_normal_distribution_static
(
self
,
sample_shape
=
7
,
tolerance
=
1e-
4
):
def
test_normal_distribution_static
(
self
,
sample_shape
=
7
,
tolerance
=
1e-
6
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
self
.
test_program
):
normal
=
Normal
(
self
.
static_loc
,
self
.
static_scale
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录