secure_learning.utils.matrix_augmenter module¶
Contains the MatrixAugmenter class
- class secure_learning.utils.matrix_augmenter.MatrixAugmenter[source]¶
Bases:
Sequence
[Sequence
[TemplateType
]]Representation of an augmented matrix build from multiple sequence-of- sequences matrices.
Multiple identical-length matrices can be augmented to the MatrixAugmenter object. The object stores all matrices in a dictionary so that they can be retrieved individually. The MatrixAugmenter itself is a sequence; in particular, it behaves as a larger sequence-of-sequences. An update to the augmented matrix object translates to an update of all of the individual matrices.
- __getitem__(index)[source]¶
Get a row of the augmented matrix.
- Parameters:
index (
Union
[int
,slice
]) – Row index of the augmented matrix- Return type:
Union
[List
[TypeVar
(TemplateType
)],MatrixAugmenter
[TypeVar
(TemplateType
)]]- Returns:
Row of the augmented matrix
- __len__()[source]¶
Length of the augmented matrix.
- Return type:
int
- Returns:
Number of rows in the augmented matrix
- __str__()[source]¶
String representation of the augmented matrix.
States the contents of the augmented matrix, where individual matrices are separated by | and specified by their key in a header.
- Return type:
str
- Returns:
String representation
- augment(key, matrix)[source]¶
Augments a new matrix to the existing augmented matrix.
- Parameters:
key (
str
) – Key used for storing and retrieving the new matrixmatrix (
Sequence
[Sequence
[TypeVar
(TemplateType
)]]) – Matrix to be augmented
- Raises:
KeyError – Key already in use
- Return type:
None
- delete(key)[source]¶
Delete individual matrix.
- Parameters:
key (
str
) – Key of matrix- Return type:
None
- keys()[source]¶
Provide a set-like object providing a view on the keys of the individual matrices.
- Return type:
Any
- Returns:
set-like object providing a view on the keys of the individual matrices
- retrieve(key)[source]¶
Retrieve individual matrix.
- Parameters:
key (
str
) – Key for retrieving the matrix- Return type:
List
[List
[TypeVar
(TemplateType
)]]- Returns:
Requested matrix
- property shape: Tuple[int, int]¶
Return the shape of the augmented matrix.
- Returns:
Number of rows and columns
- update(matrix)[source]¶
Update augmented matrix in its entirety.
All individual matrices are updated accordingly.
- Parameters:
matrix (
Sequence
[Sequence
[TypeVar
(TemplateType
)]]) – New augmented matrix- Raises:
ValueError – Number of columns of new augmented matrix does not agree with old number of columns
- Return type:
None