matrix_inverse.matrix_inverse module¶
The code below is based on the demo ridgeregression.py from the MPyC library on Feb 26th, 2020, as implemented by Frank Blom. https://github.com/lschoe/mpyc/blob/2de1dd76db632bdc2a48acfbbaab841fa73cf8bd/demos/ridgeregression.py. The underlying theory is published in the paper ‘Efficient Secure Ridge Regression from Randomized Gaussian Elimination’ by Frank Blom, Niek J. Bouman, Berry Schoenmakers, and Niels de Vreede, presented at TPMPC 2019 by Frank Blom. See https://eprint.iacr.org/2019/773 (or https://ia.cr/2019/773).
- matrix_inverse.matrix_inverse.bareiss_gaussian_elimination(prime_field, matrix)[source]¶
Bareiss-like integer-preserving Gaussian elimination adapted for Zp. Using exactly one modular inverse in Zp per row of the provided matrix. Apart from variable names, this is an unmodified copy of the code in the demo.
- Parameters:
prime_field (
Type
[PrimeFieldElement
]) – Zpmatrix (
List
[List
[TypeVar
(SecureNumberType
, bound=SecureNumber
)]]) – input matrix containing secure values
- Return type:
Tuple
[List
[List
[TypeVar
(SecureNumberType
, bound=SecureNumber
)]],TypeVar
(SecureNumberType
, bound=SecureNumber
)]- Returns:
inverse matrix of the input matrix
- matrix_inverse.matrix_inverse.convert_matrix_to_large_sec_fxp(input_matrix)[source]¶
Convert a matrix with secure elements to a matrix with secure fixed points with twice as large bit lengths.
- Parameters:
input_matrix (
List
[SecureNumber
]) – input matrix- Return type:
List
[SecureFixedPoint
]- Returns:
the input matrix with each element converted to a fixed point number with large bit length
- matrix_inverse.matrix_inverse.determine_order_secfld(bit_length, dimension)[source]¶
Function to determine the minimal order of a field, based on the bit length and dimension. Based on main() and paper
- Parameters:
bit_length (
int
) – bit length of each element in the fielddimension (
int
) – dimension of the original matrix
- Return type:
int
- Returns:
minimal order
- matrix_inverse.matrix_inverse.matrix_inverse(input_matrix)[source]¶
Function that securely computes the inverse of a matrix with secure fixed point elements.
- Parameters:
input_matrix (
List
[List
[SecureFixedPoint
]]) – input matrix- Return type:
List
[List
[SecureFixedPoint
]]- Returns:
inverse of the input matrix
- matrix_inverse.matrix_inverse.random_matrix_determinant(secure_object_type, dimension)[source]¶
Generate a random d x d matrix from the set of LU decomposable matrices over a given field. Apart from variable names, this is an unmodified copy of the code in the demo.
- Parameters:
secure_object_type (
Type
[TypeVar
(SecureNumberType
, bound=SecureNumber
)]) – Secure typedimension (
int
) – The dimension d
- Return type:
Tuple
[List
[List
[TypeVar
(SecureNumberType
, bound=SecureNumber
)]],TypeVar
(SecureNumberType
, bound=SecureNumber
)]- Returns:
A random invertible matrix and the determinant of its inverse
- matrix_inverse.matrix_inverse.reciprocal_sec_num(sec_num)[source]¶
compute the reciprocal of a secure number.
- Parameters:
sec_num (
TypeVar
(SecureNumberType
, bound=SecureNumber
)) – secure number- Return type:
TypeVar
(SecureNumberType
, bound=SecureNumber
)- Returns:
the reciprocal of the input
- matrix_inverse.matrix_inverse.scale_and_convert_matrix_to_sec_fld(input_matrix)[source]¶
Function that scales and converts each element of a matrix with secure fixed point elements to a secure integer.
- Parameters:
input_matrix (
List
[List
[SecureFixedPoint
]]) – matrix containing secure fixed point numbers- Return type:
List
[List
[SecureFixedPoint
]]- Returns:
matrix containing secure integers
- matrix_inverse.matrix_inverse.scale_and_convert_to_secint(to_convert)[source]¶
Function that scales and converts secure fixed points to secure integers with the same modulus. Effectively removes the point in the fixed point notation.
- Parameters:
to_convert (
Union
[List
[SecureNumber
],SecureNumber
]) – secure fixed point or list of secure fixed points- Return type:
Union
[List
[SecureInteger
],SecureInteger
]- Returns:
secure integer or list of secure integers (depending on the input)