fips.matrices#
Classes
|
Covariance matrix class wrapping pandas DataFrames. |
|
Symmetric matrix wrapper class for pandas DataFrames. |
- class fips.matrices.SymmetricMatrix(data)[source]#
Symmetric matrix wrapper class for pandas DataFrames.
- Parameters:
data (pd.DataFrame) – Symmetric matrix with identical row and column indices.
- data#
Symmetric matrix.
- Type:
pd.DataFrame
- index#
Index of the symmetric matrix.
- Type:
pd.Index
- values#
Underlying data as a NumPy array.
- Type:
np.ndarray
- loc#
Custom accessor for label-based selection and assignment.
- Type:
SymmetricMatrix._Indexer
- from_numpy(array: np.ndarray, index: pd.Index) SymmetricMatrix[source]#
Create a SymmetricMatrix from a NumPy array and an index.
- reindex(index: pd.Index, \*\*kwargs) SymmetricMatrix[source]#
Reindex the symmetric matrix, filling new entries with 0.
- reorder_levels(order) SymmetricMatrix[source]#
Reorder the levels of a MultiIndex symmetric matrix.
- __init__(data)[source]#
Initialize the SymmetricMatrix with a square DataFrame.
- Parameters:
data (pd.DataFrame) – Square symmetric matrix.
- classmethod from_numpy(array, index)[source]#
Create a SymmetricMatrix from a NumPy array.
- Parameters:
array (np.ndarray) – Symmetric matrix array.
index (pd.Index) – Index for rows and columns.
- Returns:
SymmetricMatrix instance.
- Return type:
- property data: DataFrame#
Returns the underlying data as a pandas DataFrame.
- Returns:
Underlying symmetric matrix.
- Return type:
pd.DataFrame
- property dims: tuple#
Returns a tuple representing the dimension names of the matrix.
- Returns:
Dimension names of the symmetric matrix.
- Return type:
- property index: Index#
Returns the pandas Index of the matrix.
- Returns:
Index of the symmetric matrix.
- Return type:
pd.Index
- property values: ndarray#
Returns the underlying data as a NumPy array.
- Returns:
Underlying data array.
- Return type:
np.ndarray
- property shape: tuple#
Returns a tuple representing the dimensionality of the matrix.
- Returns:
Dimensionality of the symmetric matrix.
- Return type:
- reindex(index, **kwargs)[source]#
Reindex the symmetric matrix, filling new entries with 0.
- Parameters:
index (pd.Index) – New index for the symmetric matrix.
**kwargs (additional keyword arguments) – Passed to pandas’ reindex method.
- Returns:
Reindexed SymmetricMatrix instance.
- Return type:
- reorder_levels(order)[source]#
Reorder the levels of a MultiIndex symmetric matrix.
- sort_index(**kwargs)[source]#
Sort the index of the symmetric matrix.
- Parameters:
**kwargs (additional keyword arguments) – Passed to pandas’ sort_index method.
- Returns:
SymmetricMatrix instance with sorted index.
- Return type:
- operate(value, operation='replace', diagonal=None, cross=None, **kwargs)[source]#
Operate on specific entries in the symmetric matrix.
- Parameters:
value (float or int) – Value to assign or use in the operation.
operation ({'replace', 'add', 'subtract', 'multiply', 'divide'}, optional) – Operation to perform with the value. Default is ‘replace’.
diagonal (bool, optional) – If True, only operate on diagonal entries. If False, only operate on off-diagonal entries. If None, operate on all selected entries. Default is None.
cross (dict, optional) – Dictionary specifying cross indices for symmetric assignment. Keys are index level names, and values are the corresponding index values. If None, no cross assignment is performed. Default is None.
**kwargs (additional keyword arguments) – Key-value pairs specifying index level names and their corresponding index values to select rows and columns for assignment. Use slice(None) to select all entries along a level.
- Returns:
New SymmetricMatrix instance with the operation applied.
- Return type:
- __add__(other)[source]#
Add two SymmetricMatrix instances.
- Parameters:
other (SymmetricMatrix) – Another SymmetricMatrix instance.
- Returns:
Sum of the two SymmetricMatrix instances.
- Return type:
- class fips.matrices.CovarianceMatrix(data)[source]#
Covariance matrix class wrapping pandas DataFrames.
- variance#
Series containing the variances (diagonal elements).
- Type:
pd.Series