Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
3a11d123
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3a11d123
编写于
8月 12, 2020
作者:
P
peixu_ren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update random uniform op invocation
上级
64b0feb7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
23 addition
and
15 deletion
+23
-15
mindspore/nn/probability/distribution/bernoulli.py
mindspore/nn/probability/distribution/bernoulli.py
+4
-4
mindspore/nn/probability/distribution/exponential.py
mindspore/nn/probability/distribution/exponential.py
+7
-4
mindspore/nn/probability/distribution/geometric.py
mindspore/nn/probability/distribution/geometric.py
+6
-3
mindspore/nn/probability/distribution/uniform.py
mindspore/nn/probability/distribution/uniform.py
+6
-4
未找到文件。
mindspore/nn/probability/distribution/bernoulli.py
浏览文件 @
3a11d123
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
"""Bernoulli Distribution"""
"""Bernoulli Distribution"""
from
mindspore.common
import
dtype
as
mstype
from
mindspore.common
import
dtype
as
mstype
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
composite
as
C
from
.distribution
import
Distribution
from
.distribution
import
Distribution
from
._utils.utils
import
cast_to_tensor
,
check_prob
,
check_type
from
._utils.utils
import
cast_to_tensor
,
check_prob
,
check_type
...
@@ -116,7 +117,7 @@ class Bernoulli(Distribution):
...
@@ -116,7 +117,7 @@ class Bernoulli(Distribution):
self
.
select
=
P
.
Select
()
self
.
select
=
P
.
Select
()
self
.
sq
=
P
.
Square
()
self
.
sq
=
P
.
Square
()
self
.
sqrt
=
P
.
Sqrt
()
self
.
sqrt
=
P
.
Sqrt
()
self
.
uniform
=
P
.
UniformReal
(
seed
=
seed
)
self
.
uniform
=
C
.
uniform
def
extend_repr
(
self
):
def
extend_repr
(
self
):
if
self
.
is_scalar_batch
:
if
self
.
is_scalar_batch
:
...
@@ -256,7 +257,6 @@ class Bernoulli(Distribution):
...
@@ -256,7 +257,6 @@ class Bernoulli(Distribution):
probs1
=
self
.
probs
if
probs
is
None
else
probs
probs1
=
self
.
probs
if
probs
is
None
else
probs
l_zero
=
self
.
const
(
0.0
)
l_zero
=
self
.
const
(
0.0
)
h_one
=
self
.
const
(
1.0
)
h_one
=
self
.
const
(
1.0
)
sample_uniform
=
self
.
uniform
(
shape
+
self
.
shape
(
probs1
),
l_zero
,
h_one
)
sample_uniform
=
self
.
uniform
(
shape
+
self
.
shape
(
probs1
),
l_zero
,
h_one
,
self
.
seed
)
sample
=
self
.
less
(
sample_uniform
,
probs1
)
sample
=
self
.
less
(
sample_uniform
,
probs1
)
sample
=
self
.
cast
(
sample
,
self
.
dtype
)
return
self
.
cast
(
sample
,
self
.
dtype
)
return
sample
mindspore/nn/probability/distribution/exponential.py
浏览文件 @
3a11d123
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
"""Exponential Distribution"""
"""Exponential Distribution"""
import
numpy
as
np
import
numpy
as
np
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
composite
as
C
from
mindspore.common
import
dtype
as
mstype
from
mindspore.common
import
dtype
as
mstype
from
.distribution
import
Distribution
from
.distribution
import
Distribution
from
._utils.utils
import
cast_to_tensor
,
check_greater_zero
,
check_type
from
._utils.utils
import
cast_to_tensor
,
check_greater_zero
,
check_type
...
@@ -107,7 +108,8 @@ class Exponential(Distribution):
...
@@ -107,7 +108,8 @@ class Exponential(Distribution):
self
.
minval
=
np
.
finfo
(
np
.
float
).
tiny
self
.
minval
=
np
.
finfo
(
np
.
float
).
tiny
# ops needed for the class
# ops needed for the class
self
.
cast
=
P
.
Cast
()
self
.
const
=
P
.
ScalarToArray
()
self
.
const
=
P
.
ScalarToArray
()
self
.
dtypeop
=
P
.
DType
()
self
.
dtypeop
=
P
.
DType
()
self
.
exp
=
P
.
Exp
()
self
.
exp
=
P
.
Exp
()
...
@@ -118,7 +120,7 @@ class Exponential(Distribution):
...
@@ -118,7 +120,7 @@ class Exponential(Distribution):
self
.
shape
=
P
.
Shape
()
self
.
shape
=
P
.
Shape
()
self
.
sqrt
=
P
.
Sqrt
()
self
.
sqrt
=
P
.
Sqrt
()
self
.
sq
=
P
.
Square
()
self
.
sq
=
P
.
Square
()
self
.
uniform
=
P
.
UniformReal
(
seed
=
seed
)
self
.
uniform
=
C
.
uniform
def
extend_repr
(
self
):
def
extend_repr
(
self
):
if
self
.
is_scalar_batch
:
if
self
.
is_scalar_batch
:
...
@@ -251,5 +253,6 @@ class Exponential(Distribution):
...
@@ -251,5 +253,6 @@ class Exponential(Distribution):
rate
=
self
.
rate
if
rate
is
None
else
rate
rate
=
self
.
rate
if
rate
is
None
else
rate
minval
=
self
.
const
(
self
.
minval
)
minval
=
self
.
const
(
self
.
minval
)
maxval
=
self
.
const
(
1.0
)
maxval
=
self
.
const
(
1.0
)
sample
=
self
.
uniform
(
shape
+
self
.
shape
(
rate
),
minval
,
maxval
)
sample_uniform
=
self
.
uniform
(
shape
+
self
.
shape
(
rate
),
minval
,
maxval
,
self
.
seed
)
return
-
self
.
log
(
sample
)
/
rate
sample
=
-
self
.
log
(
sample_uniform
)
/
rate
return
self
.
cast
(
sample
,
self
.
dtype
)
mindspore/nn/probability/distribution/geometric.py
浏览文件 @
3a11d123
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
"""Geometric Distribution"""
"""Geometric Distribution"""
import
numpy
as
np
import
numpy
as
np
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
composite
as
C
from
mindspore.common
import
dtype
as
mstype
from
mindspore.common
import
dtype
as
mstype
from
.distribution
import
Distribution
from
.distribution
import
Distribution
from
._utils.utils
import
cast_to_tensor
,
check_prob
,
check_type
from
._utils.utils
import
cast_to_tensor
,
check_prob
,
check_type
...
@@ -109,6 +110,7 @@ class Geometric(Distribution):
...
@@ -109,6 +110,7 @@ class Geometric(Distribution):
self
.
minval
=
np
.
finfo
(
np
.
float
).
tiny
self
.
minval
=
np
.
finfo
(
np
.
float
).
tiny
# ops needed for the class
# ops needed for the class
self
.
cast
=
P
.
Cast
()
self
.
const
=
P
.
ScalarToArray
()
self
.
const
=
P
.
ScalarToArray
()
self
.
dtypeop
=
P
.
DType
()
self
.
dtypeop
=
P
.
DType
()
self
.
fill
=
P
.
Fill
()
self
.
fill
=
P
.
Fill
()
...
@@ -121,7 +123,7 @@ class Geometric(Distribution):
...
@@ -121,7 +123,7 @@ class Geometric(Distribution):
self
.
shape
=
P
.
Shape
()
self
.
shape
=
P
.
Shape
()
self
.
sq
=
P
.
Square
()
self
.
sq
=
P
.
Square
()
self
.
sqrt
=
P
.
Sqrt
()
self
.
sqrt
=
P
.
Sqrt
()
self
.
uniform
=
P
.
UniformReal
(
seed
=
seed
)
self
.
uniform
=
C
.
uniform
def
extend_repr
(
self
):
def
extend_repr
(
self
):
if
self
.
is_scalar_batch
:
if
self
.
is_scalar_batch
:
...
@@ -269,5 +271,6 @@ class Geometric(Distribution):
...
@@ -269,5 +271,6 @@ class Geometric(Distribution):
probs
=
self
.
probs
if
probs
is
None
else
probs
probs
=
self
.
probs
if
probs
is
None
else
probs
minval
=
self
.
const
(
self
.
minval
)
minval
=
self
.
const
(
self
.
minval
)
maxval
=
self
.
const
(
1.0
)
maxval
=
self
.
const
(
1.0
)
sample_uniform
=
self
.
uniform
(
shape
+
self
.
shape
(
probs
),
minval
,
maxval
)
sample_uniform
=
self
.
uniform
(
shape
+
self
.
shape
(
probs
),
minval
,
maxval
,
self
.
seed
)
return
self
.
floor
(
self
.
log
(
sample_uniform
)
/
self
.
log
(
1.0
-
probs
))
sample
=
self
.
floor
(
self
.
log
(
sample_uniform
)
/
self
.
log
(
1.0
-
probs
))
return
self
.
cast
(
sample
,
self
.
dtype
)
mindspore/nn/probability/distribution/uniform.py
浏览文件 @
3a11d123
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
# ============================================================================
# ============================================================================
"""Uniform Distribution"""
"""Uniform Distribution"""
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
composite
as
C
from
mindspore.common
import
dtype
as
mstype
from
mindspore.common
import
dtype
as
mstype
from
.distribution
import
Distribution
from
.distribution
import
Distribution
from
._utils.utils
import
convert_to_batch
,
check_greater
,
check_type
from
._utils.utils
import
convert_to_batch
,
check_greater
,
check_type
...
@@ -108,7 +109,8 @@ class Uniform(Distribution):
...
@@ -108,7 +109,8 @@ class Uniform(Distribution):
self
.
_low
=
low
self
.
_low
=
low
self
.
_high
=
high
self
.
_high
=
high
# ops needed for the class
# ops needed for the class
self
.
cast
=
P
.
Cast
()
self
.
const
=
P
.
ScalarToArray
()
self
.
const
=
P
.
ScalarToArray
()
self
.
dtypeop
=
P
.
DType
()
self
.
dtypeop
=
P
.
DType
()
self
.
exp
=
P
.
Exp
()
self
.
exp
=
P
.
Exp
()
...
@@ -121,8 +123,8 @@ class Uniform(Distribution):
...
@@ -121,8 +123,8 @@ class Uniform(Distribution):
self
.
shape
=
P
.
Shape
()
self
.
shape
=
P
.
Shape
()
self
.
sq
=
P
.
Square
()
self
.
sq
=
P
.
Square
()
self
.
sqrt
=
P
.
Sqrt
()
self
.
sqrt
=
P
.
Sqrt
()
self
.
uniform
=
P
.
UniformReal
(
seed
=
seed
)
self
.
zeroslike
=
P
.
ZerosLike
()
self
.
zeroslike
=
P
.
ZerosLike
()
self
.
uniform
=
C
.
uniform
def
extend_repr
(
self
):
def
extend_repr
(
self
):
if
self
.
is_scalar_batch
:
if
self
.
is_scalar_batch
:
...
@@ -284,6 +286,6 @@ class Uniform(Distribution):
...
@@ -284,6 +286,6 @@ class Uniform(Distribution):
broadcast_shape
=
self
.
shape
(
low
+
high
)
broadcast_shape
=
self
.
shape
(
low
+
high
)
l_zero
=
self
.
const
(
0.0
)
l_zero
=
self
.
const
(
0.0
)
h_one
=
self
.
const
(
1.0
)
h_one
=
self
.
const
(
1.0
)
sample_uniform
=
self
.
uniform
(
shape
+
broadcast_shape
,
l_zero
,
h_one
)
sample_uniform
=
self
.
uniform
(
shape
+
broadcast_shape
,
l_zero
,
h_one
,
self
.
seed
)
sample
=
(
high
-
low
)
*
sample_uniform
+
low
sample
=
(
high
-
low
)
*
sample_uniform
+
low
return
s
ample
return
s
elf
.
cast
(
sample
,
self
.
dtype
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录