fips.matrices#

Classes

CovarianceMatrix(data)

Covariance matrix class wrapping pandas DataFrames.

SymmetricMatrix(data)

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

dims#

Dimension names of the symmetric matrix.

Type:

tuple

values#

Underlying data as a NumPy array.

Type:

np.ndarray

shape#

Dimensionality of the symmetric matrix.

Type:

tuple

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:

SymmetricMatrix

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:

tuple

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:

tuple

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:

SymmetricMatrix

reorder_levels(order)[source]#

Reorder the levels of a MultiIndex symmetric matrix.

Parameters:

order (list) – New order for the levels.

Returns:

SymmetricMatrix instance with reordered levels.

Return type:

SymmetricMatrix

Raises:

TypeError – If the index is not a MultiIndex.

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:

SymmetricMatrix

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:

SymmetricMatrix

__add__(other)[source]#

Add two SymmetricMatrix instances.

Parameters:

other (SymmetricMatrix) – Another SymmetricMatrix instance.

Returns:

Sum of the two SymmetricMatrix instances.

Return type:

SymmetricMatrix

class fips.matrices.CovarianceMatrix(data)[source]#

Covariance matrix class wrapping pandas DataFrames.

variance#

Series containing the variances (diagonal elements).

Type:

pd.Series

property variances: Series#

Returns the diagonal of the covariance matrix (the variances).

Returns:

Series containing the variances.

Return type:

pd.Series

classmethod from_variances(variances, index=None, **kwargs)[source]#
Return type:

Self