Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
5ea2ecb7
M
mindarmour
项目概览
MindSpore
/
mindarmour
通知
4
Star
2
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindarmour
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5ea2ecb7
编写于
7月 23, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
7月 23, 2020
浏览文件
操作
浏览文件
下载
差异文件
!60 fix issue
Merge pull request !60 from zheng-huanhuan/master
上级
0c7dac39
ca524d71
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
20 deletion
+34
-20
mindarmour/diff_privacy/mechanisms/mechanisms.py
mindarmour/diff_privacy/mechanisms/mechanisms.py
+34
-20
未找到文件。
mindarmour/diff_privacy/mechanisms/mechanisms.py
浏览文件 @
5ea2ecb7
...
...
@@ -39,13 +39,21 @@ class ClipMechanismsFactory:
pass
@
staticmethod
def
create
(
mech_name
,
*
args
,
**
kwargs
):
def
create
(
mech_name
,
decay_policy
=
'Linear'
,
learning_rate
=
0.001
,
target_unclipped_quantile
=
0.9
,
fraction_stddev
=
0.01
,
seed
=
0
):
"""
Args:
mech_name(str): Clip noise generated strategy, support 'Gaussian' now.
args(Union[float, str]): Parameters used for creating clip mechanisms.
kwargs(Union[float, str]): Parameters used for creating clip
mechanisms.
decay_policy(str): Decay policy of adaptive clipping, decay_policy must
be in ['Linear', 'Geometric']. Default: Linear.
learning_rate(float): Learning rate of update norm clip. Default: 0.001.
target_unclipped_quantile(float): Target quantile of norm clip. Default: 0.9.
fraction_stddev(float): The stddev of Gaussian normal which used in
empirical_fraction, the formula is $empirical_fraction + N(0, fraction_stddev)$.
Default: 0.01.
seed(int): Original random seed, if seed=0 random normal will use secure
random number. IF seed!=0 random normal will generate values using
given seed. Default: 0.
Raises:
NameError: `mech_name` must be in ['Gaussian'].
...
...
@@ -70,7 +78,8 @@ class ClipMechanismsFactory:
"""
if
mech_name
==
'Gaussian'
:
return
AdaClippingWithGaussianRandom
(
*
args
,
**
kwargs
)
return
AdaClippingWithGaussianRandom
(
decay_policy
,
learning_rate
,
target_unclipped_quantile
,
fraction_stddev
,
seed
)
raise
NameError
(
"The {} is not implement, please choose "
"['Gaussian']"
.
format
(
mech_name
))
...
...
@@ -82,23 +91,23 @@ class NoiseMechanismsFactory:
pass
@
staticmethod
def
create
(
mech_name
=
'Gaussian'
,
norm_bound
=
0.5
,
initial_noise_multiplier
=
1.5
,
seed
=
0
,
noise_decay_rate
=
6e-6
,
def
create
(
mech_name
,
norm_bound
=
1.0
,
initial_noise_multiplier
=
1.0
,
seed
=
0
,
noise_decay_rate
=
6e-6
,
decay_policy
=
None
):
"""
Args:
mech_name(str): Noise generated strategy, could be 'Gaussian' or
'AdaGaussian'. Noise would be decayed with 'AdaGaussian' mechanism
while be constant with 'Gaussian' mechanism.
norm_bound(float): Clipping bound for the l2 norm of the gradients.
norm_bound(float): Clipping bound for the l2 norm of the gradients.
Default: 1.0.
initial_noise_multiplier(float): Ratio of the standard deviation of
Gaussian noise divided by the norm_bound, which will be used to
calculate privacy spent.
calculate privacy spent.
Default: 1.0.
seed(int): Original random seed, if seed=0 random normal will use secure
random number. IF seed!=0 random normal will generate values using
given seed.
noise_decay_rate(float): Hyper parameter for controlling the noise decay.
given seed.
Default: 0.
noise_decay_rate(float): Hyper parameter for controlling the noise decay.
Default: 6e-6.
decay_policy(str): Mechanisms parameters update policy. Default: None, no
parameters need update.
parameters need update.
Default: None.
Raises:
NameError: `mech_name` must be in ['Gaussian', 'AdaGaussian'].
...
...
@@ -170,12 +179,13 @@ class NoiseGaussianRandom(_Mechanisms):
Args:
norm_bound(float): Clipping bound for the l2 norm of the gradients.
Default: 1.0.
initial_noise_multiplier(float): Ratio of the standard deviation of
Gaussian noise divided by the norm_bound, which will be used to
calculate privacy spent.
calculate privacy spent.
Default: 1.0.
seed(int): Original random seed, if seed=0 random normal will use secure
random number. IF seed!=0 random normal will generate values using
given seed.
given seed.
Default: 0.
decay_policy(str): Mechanisms parameters update policy. Default: None.
Returns:
...
...
@@ -192,7 +202,7 @@ class NoiseGaussianRandom(_Mechanisms):
>>> print(res)
"""
def
__init__
(
self
,
norm_bound
,
initial_noise_multiplier
,
seed
,
decay_policy
=
None
):
def
__init__
(
self
,
norm_bound
=
1.0
,
initial_noise_multiplier
=
1.0
,
seed
=
0
,
decay_policy
=
None
):
super
(
NoiseGaussianRandom
,
self
).
__init__
()
self
.
_norm_bound
=
check_value_positive
(
'norm_bound'
,
norm_bound
)
self
.
_norm_bound
=
Tensor
(
norm_bound
,
mstype
.
float32
)
...
...
@@ -230,14 +240,17 @@ class NoiseAdaGaussianRandom(NoiseGaussianRandom):
Args:
norm_bound(float): Clipping bound for the l2 norm of the gradients.
Default: 1.0.
initial_noise_multiplier(float): Ratio of the standard deviation of
Gaussian noise divided by the norm_bound, which will be used to
calculate privacy spent.
calculate privacy spent.
Default: 1.0.
seed(int): Original random seed, if seed=0 random normal will use secure
random number. IF seed!=0 random normal will generate values using
given seed.
given seed.
Default: 0.
noise_decay_rate(float): Hyper parameter for controlling the noise decay.
Default: 6e-6.
decay_policy(str): Noise decay strategy include 'Step', 'Time', 'Exp'.
Default: 'Exp'.
Returns:
Tensor, generated noise with shape like given gradients.
...
...
@@ -248,13 +261,13 @@ class NoiseAdaGaussianRandom(NoiseGaussianRandom):
>>> initial_noise_multiplier = 1.5
>>> seed = 0
>>> noise_decay_rate = 6e-4
>>> decay_policy = "
Time
"
>>> decay_policy = "
Exp
"
>>> net = NoiseAdaGaussianRandom(norm_bound, initial_noise_multiplier, seed, noise_decay_rate, decay_policy)
>>> res = net(gradients)
>>> print(res)
"""
def
__init__
(
self
,
norm_bound
,
initial_noise_multiplier
,
seed
,
noise_decay_rate
,
decay_policy
):
def
__init__
(
self
,
norm_bound
=
1.0
,
initial_noise_multiplier
=
1.0
,
seed
=
0
,
noise_decay_rate
=
6e-6
,
decay_policy
=
'Exp'
):
super
(
NoiseAdaGaussianRandom
,
self
).
__init__
(
norm_bound
=
norm_bound
,
initial_noise_multiplier
=
initial_noise_multiplier
,
seed
=
seed
)
...
...
@@ -293,7 +306,7 @@ class _MechanismsParamsUpdater(Cell):
self
.
_cur_noise_multiplier
=
cur_noise_multiplier
self
.
_init_noise_multiplier
=
init_noise_multiplier
self
.
_div
=
P
.
Sub
()
self
.
_div
=
P
.
Div
()
self
.
_add
=
P
.
TensorAdd
()
self
.
_assign
=
P
.
Assign
()
self
.
_sub
=
P
.
Sub
()
...
...
@@ -335,10 +348,11 @@ class AdaClippingWithGaussianRandom(Cell):
Args:
decay_policy(str): Decay policy of adaptive clipping, decay_policy must
be in ['Linear', 'Geometric']. Default: Linear.
learning_rate(float): Learning rate of update norm clip. Default: 0.01.
learning_rate(float): Learning rate of update norm clip. Default: 0.0
0
1.
target_unclipped_quantile(float): Target quantile of norm clip. Default: 0.9.
fraction_stddev(float): The stddev of Gaussian normal which used in
empirical_fraction, the formula is $empirical_fraction + N(0, fraction_stddev)$.
Default: 0.01.
seed(int): Original random seed, if seed=0 random normal will use secure
random number. IF seed!=0 random normal will generate values using
given seed. Default: 0.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录