secretflow.utils package#
Subpackages#
Submodules#
secretflow.utils.compressor module#
Classes:
Abstract base class for cross device data compressor |
|
|
|
|
Random sparse compressor compress data by randomly set element to zero. |
|
Topk sparse compressor use topK algorithm to transfer dense matrix into sparse matrix. |
- class secretflow.utils.compressor.Compressor[source]#
Bases:
ABC
Abstract base class for cross device data compressor
Methods:
compress
(data)Compress data before send.
decompress
(data)Decompress data after receive.
- class secretflow.utils.compressor.SparseCompressor(sparse_rate: float)[source]#
Bases:
Compressor
Methods:
__init__
(sparse_rate)Initialize
compress
(data)Compress data to sparse matrix before send.
decompress
(data)Decompress data from sparse matrix to dense after received.
- __init__(sparse_rate: float)[source]#
Initialize
- Parameters
sparse_rate – the percentage of cells are zero.
- compress(data: Union[ndarray, List[ndarray]]) Union[spmatrix, List[spmatrix]] [source]#
Compress data to sparse matrix before send.
- Parameters
data (Union[np.ndarray, List[np.ndarray]]) – data need to compress.
- Returns
compressed data.
- Return type
Union[sparse.spmatrix, List[sparse.spmatrix]]
- decompress(data: Union[spmatrix, List[spmatrix]]) Union[ndarray, List[ndarray]] [source]#
Decompress data from sparse matrix to dense after received.
- Parameters
data (Union[sparse.spmatrix, List[sparse.spmatrix]]) – data need to decompress.
- Returns
decompressed data.
- Return type
Union[np.ndarray, List[np.ndarray]]
- class secretflow.utils.compressor.RandomSparse(sparse_rate: float)[source]#
Bases:
SparseCompressor
Random sparse compressor compress data by randomly set element to zero.
Methods:
__init__
(sparse_rate)Initialize
- class secretflow.utils.compressor.TopkSparse(sparse_rate: float)[source]#
Bases:
SparseCompressor
Topk sparse compressor use topK algorithm to transfer dense matrix into sparse matrix.
Methods:
__init__
(sparse_rate)Initialize
secretflow.utils.errors module#
Exceptions:
Raise when already exists. |
|
Raise when invalid argument. |
|
Raise if not found. |
|
Raise if party not found. |
|
Raise when unexpected. |
|
Raise if http code is not 200 |
- exception secretflow.utils.errors.AlreadyExistsError[source]#
Bases:
Exception
Raise when already exists.
- exception secretflow.utils.errors.InvalidArgumentError[source]#
Bases:
Exception
Raise when invalid argument.
secretflow.utils.hash module#
Functions:
|
secretflow.utils.io module#
Functions:
|
get rows count from file |
secretflow.utils.ndarray_bigint module#
Functions:
|
|
|
|
|
|
|
Classes:
|
secretflow.utils.ndarray_encoding module#
Functions:
|
Encode float ndarray to uint64 finite field. |
|
Decode ndarray from uint64 finite field to the float. |
- secretflow.utils.ndarray_encoding.encode(m: ndarray, fxp_bits: int) ndarray [source]#
Encode float ndarray to uint64 finite field. Float will times 2**fxp_bits firstly.
- Parameters
m (np.ndarray) – the ndarray to encode.
fraction_precision (int) – keep how many decimal digits after the dot. Must provide if ndarray dtype is float.
- Returns
the encoded ndarray.
- Return type
np.ndarray
- secretflow.utils.ndarray_encoding.decode(m: ndarray, fxp_bits: int) ndarray [source]#
Decode ndarray from uint64 finite field to the float. Fraction precision shall be corresponding to encoding fraction precision.
- Parameters
m (np.ndarray) – the ndarray to decode.
fxp_bits (int) – the decimal digits to keep when encoding float. Must provide if the original dtype is float.
- Returns
the decoded float ndarray.
- Return type
np.ndarray
secretflow.utils.sigmoid module#
Functions:
|
taylor series referenced from: https://mortendahl.github.io/2017/04/17/private-deep-learning-with-mpc/ |
|
taylor series referenced from: https://mortendahl.github.io/2017/04/17/private-deep-learning-with-mpc/ |
|
taylor series referenced from: https://mortendahl.github.io/2017/04/17/private-deep-learning-with-mpc/ |
|
f(x) = 0.5 + 0.125x if -4 <= x <= 4 |
|
https://dergipark.org.tr/en/download/article-file/54559 Dataflow implementation of sigmoid function: F(x) = 0.5 * ( x / ( 1 + |x| ) ) + 0.5 df_sig has higher precision than sr_sig if x in [-2, 2] |
|
https://en.wikipedia.org/wiki/Sigmoid_function#Examples Square Root approximation functions: F(x) = 0.5 * ( x / ( 1 + x^2 )^0.5 ) + 0.5 sr_sig almost perfect fit to sigmoid if x out of range [-3,3] |
|
Polynomial fitting |
|
mix ls7 & sr sig, use ls7 if |x| < 4 , else use sr. |
|
|
|
Classes:
|
An enumeration. |
- secretflow.utils.sigmoid.t1_sig(x, limit: bool = True)[source]#
taylor series referenced from: https://mortendahl.github.io/2017/04/17/private-deep-learning-with-mpc/
- secretflow.utils.sigmoid.t3_sig(x, limit: bool = True)[source]#
taylor series referenced from: https://mortendahl.github.io/2017/04/17/private-deep-learning-with-mpc/
- secretflow.utils.sigmoid.t5_sig(x, limit: bool = True)[source]#
taylor series referenced from: https://mortendahl.github.io/2017/04/17/private-deep-learning-with-mpc/
- secretflow.utils.sigmoid.seg3_sig(x)[source]#
- f(x) = 0.5 + 0.125x if -4 <= x <= 4
1 if x > 4 0 if -4 > x
- secretflow.utils.sigmoid.df_sig(x)[source]#
https://dergipark.org.tr/en/download/article-file/54559 Dataflow implementation of sigmoid function: F(x) = 0.5 * ( x / ( 1 + |x| ) ) + 0.5 df_sig has higher precision than sr_sig if x in [-2, 2]
- secretflow.utils.sigmoid.sr_sig(x)[source]#
https://en.wikipedia.org/wiki/Sigmoid_function#Examples Square Root approximation functions: F(x) = 0.5 * ( x / ( 1 + x^2 )^0.5 ) + 0.5 sr_sig almost perfect fit to sigmoid if x out of range [-3,3]
- secretflow.utils.sigmoid.mix_sig(x)[source]#
mix ls7 & sr sig, use ls7 if |x| < 4 , else use sr. has higher precision in all input range. NOTICE: this method is very expensive, only use for hessian matrix.
secretflow.utils.testing module#
Functions:
Return an unused port |
|
|
Generate SPU cluster_def for testing |
|