Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
e24cf5f6
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看板
提交
e24cf5f6
编写于
6月 30, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 30, 2020
浏览文件
操作
浏览文件
下载
差异文件
!44 fix issue
Merge pull request !44 from zheng-huanhuan/master
上级
92165efc
89a5c90a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
25 deletion
+14
-25
mindarmour/diff_privacy/mechanisms/mechanisms.py
mindarmour/diff_privacy/mechanisms/mechanisms.py
+14
-25
未找到文件。
mindarmour/diff_privacy/mechanisms/mechanisms.py
浏览文件 @
e24cf5f6
...
...
@@ -17,6 +17,7 @@ Noise Mechanisms.
from
mindspore
import
Tensor
from
mindspore.nn
import
Cell
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
functional
as
F
from
mindspore.common.parameter
import
Parameter
from
mindspore.common
import
dtype
as
mstype
...
...
@@ -202,7 +203,6 @@ class AdaGaussianRandom(Mechanisms):
initial_noise_multiplier
=
Tensor
(
initial_noise_multiplier
,
mstype
.
float32
)
self
.
_initial_noise_multiplier
=
Parameter
(
initial_noise_multiplier
,
name
=
'initial_noise_multiplier'
)
self
.
_stddev
=
P
.
Mul
()(
self
.
_norm_bound
,
self
.
_initial_noise_multiplier
)
self
.
_noise_multiplier
=
Parameter
(
initial_noise_multiplier
,
name
=
'noise_multiplier'
)
mean
=
check_param_type
(
'mean'
,
mean
,
float
)
...
...
@@ -222,24 +222,7 @@ class AdaGaussianRandom(Mechanisms):
self
.
_dtype
=
mstype
.
float32
self
.
_normal
=
P
.
Normal
(
seed
=
seed
)
self
.
_assign
=
P
.
Assign
()
def
_update_multiplier
(
self
):
""" Update multiplier. """
if
self
.
_decay_policy
==
'Time'
:
temp
=
self
.
_div
(
self
.
_initial_noise_multiplier
,
self
.
_noise_multiplier
)
temp
=
self
.
_add
(
temp
,
self
.
_noise_decay_rate
)
self
.
_noise_multiplier
=
self
.
_assign
(
self
.
_noise_multiplier
,
self
.
_div
(
self
.
_initial_noise_multiplier
,
temp
))
else
:
one
=
Tensor
(
1
,
self
.
_dtype
)
temp
=
self
.
_sub
(
one
,
self
.
_noise_decay_rate
)
self
.
_noise_multiplier
=
self
.
_assign
(
self
.
_noise_multiplier
,
self
.
_mul
(
temp
,
self
.
_noise_multiplier
))
return
self
.
_noise_multiplier
def
_update_stddev
(
self
):
self
.
_stddev
=
self
.
_assign
(
self
.
_stddev
,
self
.
_mul
(
self
.
_noise_multiplier
,
self
.
_norm_bound
))
return
self
.
_stddev
self
.
_one
=
Tensor
(
1
,
self
.
_dtype
)
def
construct
(
self
,
gradients
):
"""
...
...
@@ -252,9 +235,15 @@ class AdaGaussianRandom(Mechanisms):
Tensor, generated noise with shape like given gradients.
"""
shape
=
P
.
Shape
()(
gradients
)
noise
=
self
.
_normal
(
shape
,
self
.
_mean
,
self
.
_stddev
)
# pylint: disable=unused-variable
mt
=
self
.
_update_multiplier
()
# pylint: disable=unused-variable
std
=
self
.
_update_stddev
()
return
noise
noise
=
self
.
_normal
(
shape
,
self
.
_mean
,
self
.
_mul
(
self
.
_noise_multiplier
,
self
.
_norm_bound
))
if
self
.
_decay_policy
==
'Time'
:
temp
=
self
.
_div
(
self
.
_initial_noise_multiplier
,
self
.
_noise_multiplier
)
temp
=
self
.
_add
(
temp
,
self
.
_noise_decay_rate
)
multiplier
=
self
.
_assign
(
self
.
_noise_multiplier
,
self
.
_div
(
self
.
_initial_noise_multiplier
,
temp
))
else
:
temp
=
self
.
_sub
(
self
.
_one
,
self
.
_noise_decay_rate
)
multiplier
=
self
.
_assign
(
self
.
_noise_multiplier
,
self
.
_mul
(
temp
,
self
.
_noise_multiplier
))
return
F
.
depend
(
noise
,
multiplier
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录