Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
9f131702
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
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看板
提交
9f131702
编写于
8月 27, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 27, 2020
浏览文件
操作
浏览文件
下载
差异文件
!5295 Fix some doc errors in pp distributions and bijectors
Merge pull request !5295 from peixu_ren/custom_bijector
上级
df611d8e
70b0d415
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
59 addition
and
21 deletion
+59
-21
mindspore/nn/probability/bijector/bijector.py
mindspore/nn/probability/bijector/bijector.py
+9
-6
mindspore/nn/probability/bijector/exp.py
mindspore/nn/probability/bijector/exp.py
+7
-3
mindspore/nn/probability/bijector/power_transform.py
mindspore/nn/probability/bijector/power_transform.py
+8
-2
mindspore/nn/probability/bijector/scalar_affine.py
mindspore/nn/probability/bijector/scalar_affine.py
+5
-4
mindspore/nn/probability/bijector/softplus.py
mindspore/nn/probability/bijector/softplus.py
+5
-4
mindspore/nn/probability/distribution/distribution.py
mindspore/nn/probability/distribution/distribution.py
+3
-2
mindspore/nn/probability/distribution/transformed_distribution.py
...e/nn/probability/distribution/transformed_distribution.py
+22
-0
未找到文件。
mindspore/nn/probability/bijector/bijector.py
浏览文件 @
9f131702
...
...
@@ -101,13 +101,13 @@ class Bijector(Cell):
def
forward_log_jacobian
(
self
,
*
args
,
**
kwargs
):
"""
Logarithm of the derivative of forward transformation.
Logarithm of the derivative of
the
forward transformation.
"""
return
self
.
_forward_log_jacobian
(
*
args
,
**
kwargs
)
def
inverse_log_jacobian
(
self
,
*
args
,
**
kwargs
):
"""
Logarithm of the derivative of
forward
transformation.
Logarithm of the derivative of
the inverse
transformation.
"""
return
self
.
_inverse_log_jacobian
(
*
args
,
**
kwargs
)
...
...
@@ -131,11 +131,14 @@ class Bijector(Cell):
"""
Override construct in Cell.
Args:
*inputs: inputs[0] is always the name of a function.
Note:
Names of supported functions include:
'forward', 'inverse', 'forward_log_jacobian', 'inverse_log_jacobian'.
Notes:
Always raise RuntimeError as Distribution should not be called directly.
Args:
name (str): name of the function.
*args (list): list of positional arguments needed for the function.
**kwargs (dictionary): dictionary of keyword arguments needed for the function.
"""
if
name
==
'forward'
:
return
self
.
forward
(
*
args
,
**
kwargs
)
...
...
mindspore/nn/probability/bijector/exp.py
浏览文件 @
9f131702
...
...
@@ -20,6 +20,9 @@ class Exp(PowerTransform):
Exponential Bijector.
This Bijector performs the operation: Y = exp(x).
Args:
name (str): name of the bijector. Default: 'Exp'.
Examples:
>>> # To initialize a Exp bijector
>>> import mindspore.nn.probability.bijector as msb
...
...
@@ -32,11 +35,12 @@ class Exp(PowerTransform):
>>> self.e1 = msb.Exp()
>>>
>>> def construct(self, value):
>>>
>>> # Similar calls can be made to other probability functions
>>> # by replacing 'forward' with the name of the function
>>> ans1 = self.e1.forward(value)
>>> ans2 = self.e1.backward(value)
>>> ans1 = self.s1.forward(value)
>>> ans2 = self.s1.inverse(value)
>>> ans3 = self.s1.forward_log_jacobian(value)
>>> ans4 = self.s1.inverse_log_jacobian(value)
"""
def
__init__
(
self
,
name
=
'Exp'
):
...
...
mindspore/nn/probability/bijector/power_transform.py
浏览文件 @
9f131702
...
...
@@ -29,8 +29,12 @@ class PowerTransform(Bijector):
This bijector is equivalent to the `Exp` bijector when `c=0`
Raises:
ValueError: If the power is less than 0 or is not known statically.
Args:
power (int or float): scale factor. Default: 0.
name (str): name of the bijector. Default: 'PowerTransform'.
Examples:
>>> # To initialize a PowerTransform bijector of power 0.5
...
...
@@ -44,10 +48,12 @@ class PowerTransform(Bijector):
>>> self.p1 = msb.PowerTransform(0.5)
>>>
>>> def construct(self, value):
>>>
>>> # Similar calls can be made to other probability functions
>>> # by replacing 'forward' with the name of the function
>>> ans = self.p1.forward(, value)
>>> ans1 = self.s1.forward(value)
>>> ans2 = self.s1.inverse(value)
>>> ans3 = self.s1.forward_log_jacobian(value)
>>> ans4 = self.s1.inverse_log_jacobian(value)
"""
def
__init__
(
self
,
...
...
mindspore/nn/probability/bijector/scalar_affine.py
浏览文件 @
9f131702
...
...
@@ -29,6 +29,7 @@ class ScalarAffine(Bijector):
Args:
scale (float): scale factor. Default: 1.0.
shift (float): shift factor. Default: 0.0.
name (str): name of the bijector. Default: 'ScalarAffine'.
Examples:
>>> # To initialize a ScalarAffine bijector of scale 1 and shift 2
...
...
@@ -43,10 +44,10 @@ class ScalarAffine(Bijector):
>>> def construct(self, value):
>>> # Similar calls can be made to other probability functions
>>> # by replacing 'forward' with the name of the function
>>> ans = self.s1.forward(value)
>>> ans = self.s1.inverse(value)
>>> ans = self.s1.forward_log_jacobian(value)
>>> ans = self.s1.inverse_log_jacobian(value)
>>> ans
1
= self.s1.forward(value)
>>> ans
2
= self.s1.inverse(value)
>>> ans
3
= self.s1.forward_log_jacobian(value)
>>> ans
4
= self.s1.inverse_log_jacobian(value)
"""
def
__init__
(
self
,
...
...
mindspore/nn/probability/bijector/softplus.py
浏览文件 @
9f131702
...
...
@@ -33,6 +33,7 @@ class Softplus(Bijector):
Args:
sharpness (float): scale factor. Default: 1.0.
name (str): name of the bijector. Default: 'Softplus'.
Examples:
>>> # To initialize a Softplus bijector of sharpness 2
...
...
@@ -47,10 +48,10 @@ class Softplus(Bijector):
>>> def construct(self, value):
>>> # Similar calls can be made to other probability functions
>>> # by replacing 'forward' with the name of the function
>>> ans = self.sp1.forward(value)
>>> ans = self.sp1.inverse(value)
>>> ans = self.sp1.forward_log_jacobian(value)
>>> ans = self.sp1.inverse_log_jacobian(value)
>>> ans
1
= self.sp1.forward(value)
>>> ans
2
= self.sp1.inverse(value)
>>> ans
3
= self.sp1.forward_log_jacobian(value)
>>> ans
4
= self.sp1.inverse_log_jacobian(value)
"""
def
__init__
(
self
,
...
...
mindspore/nn/probability/distribution/distribution.py
浏览文件 @
9f131702
...
...
@@ -454,13 +454,14 @@ class Distribution(Cell):
Override construct in Cell.
Note:
Names of supported functions:
Names of supported functions
include
:
'prob', 'log_prob', 'cdf', 'log_cdf', 'survival_function', 'log_survival'
'var', 'sd', 'entropy', 'kl_loss', 'cross_entropy', 'sample'.
Args:
name (str): name of the function.
*args (list): list of arguments needed for the function.
*args (list): list of positional arguments needed for the function.
**kwargs (dictionary): dictionary of keyword arguments needed for the function.
"""
if
name
==
'log_prob'
:
...
...
mindspore/nn/probability/distribution/transformed_distribution.py
浏览文件 @
9f131702
...
...
@@ -35,6 +35,28 @@ class TransformedDistribution(Distribution):
The arguments used to initialize the original distribution cannot be None.
For example, mynormal = nn.Normal(dtype=dtyple.float32) cannot be used to initialized a
TransformedDistribution since mean and sd are not specified.
Examples:
>>> # To initialize a transformed distribution, e.g. lognormal distribution,
>>> # using Normal distribution as the base distribution, and Exp bijector as the bijector function.
>>> import mindspore.nn.probability.distribution as msd
>>> import mindspore.nn.probability.bijector as msb
>>> ln = msd.TransformedDistribution(msb.Exp(),
>>> msd.Normal(0.0, 1.0, dtype=mstype.float32),
>>> dtype=mstype.float32)
>>>
>>> # To use a transformed distribution in a network
>>> class net(Cell):
>>> def __init__(self):
>>> super(net, self).__init__():
>>> self.ln = msd.TransformedDistribution(msb.Exp(),
>>> msd.Normal(0.0, 1.0, dtype=mstype.float32),
>>> dtype=mstype.float32)
>>>
>>> def construct(self, value):
>>> # Similar calls can be made to other probability functions
>>> # by replacing 'sample' with the name of the function
>>> ans = self.ln.sample(shape=(2, 3))
"""
def
__init__
(
self
,
bijector
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录