赞
踩
深度学习中最常使用的便是秘密定点数sfix,有关定点数的高级运算协议请参阅Paper: Secure Computation With Fixed-Point Numbers.
SPDZ的深度学习框架主要基于TensorFlow实现,其中使用的容器是张量Tensor,在库中的定义如下:
- def Tensor(cls, shape):
- """
- Type-dependent tensor of any dimension::
- a = sfix.Tensor([10, 10])
- """
- if len(shape) == 1:
- return Array(shape[0], cls)
- else:
- return MultiArray(shape, cls)
可以看出使用Tensor在大多数情况就是在使用MultiArray,类比Python基础类型的多维列表。
这里举一个例子:
- a = sint.Tensor([3, 10, 10]) #创建张量,类型为sint,内容是3个10×10的矩阵
- a[0].input_from(0) #第一个矩阵从第0方读取数据
- a[1].input_from(1) #第二个矩阵从第1方读取数据
- a[2][:] = a[0][:] * a[1][:] #第三个矩阵由前两个矩阵元素对应相乘实现;[:] 表示选择这个矩阵的所有元素。
assign(other, base=0)
Assign container to content. Not implemented for floating-point.
Parameters other – container of matching size and type
assign_all(value)
Assign the same value to all entries.
Parameters value – convertible to relevant basic type
assign_part_vector(vector, base=0)
Assign vector from range of the first dimension, including all entries in further dimensions. Parameters
• vector – updated entries
• base – index in first dimension (regint/cint/int)
assign_vector(vector, base=0)
Assign vector to content. Not implemented for floating-point.
Parameters
• vector – vector of matching size convertible to relevant basic type
• base – compile-time (int)
direct_mul(other, reduce=True, indices=None, res_type=None)
Matrix multiplication in the virtual machine. Unlike dot(), this only works for sint and sfix, and it returns a vector instead of a data structure.
Parameters
• self – Matrix / 2-dimensional MultiArray
• other – Matrix / 2-dimensional MultiArray
• indices – 4-tuple of regint vectors for index selection (default is complete multiplication)
Returns Matrix as vector of relevant type (row-major)
PS: 不常用,因为泛用性很差,只能针对二维数组;也是库里自带函数的通病,以至于很多tf的很多高级函数在库中都是不存在的。
dot(other, res_params=None, n_threads=None)
Matrix-matrix and matrix-vector multiplication.
Parameters
• self – two-dimensional
• other – Matrix or Array of matching size and type
• n_threads – number of threads (default: all in same thread)
Return type Matrix or Array of appropriate size and type
input_from(player, budget=None, raw=False, **kwargs)
Fill with inputs from player if supported by type.
Parameters player – public (regint/cint/int)
randomize(*args, n_threads=None)
Randomize according to data type. If it is sfix, the following will sample an individual uniformly random entry of the multi-array M roughly in the range [
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。