Skip to content

Commit

Permalink
feat: add function to get all the sub-parts of the correlation matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
strixy16 committed Dec 19, 2024
1 parent 206ffd6 commit bec3ab4
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/readii/analyze/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,40 @@ def getCrossCorrelationMatrix(correlation_matrix:pd.DataFrame,
logger.exception(msg)
raise e

return correlation_matrix.iloc[0:num_vertical_features, num_vertical_features:]
return correlation_matrix.iloc[0:num_vertical_features, num_vertical_features:]



def getSelfAndCrossCorrelations(correlation_matrix:pd.DataFrame,
num_vertical_features:int,
num_horizontal_features:int) -> pd.DataFrame:
"""Get the vertical and horizontal self correlations and cross correlations from a correlation matrix.
Parameters
----------
correlation_matrix : pd.DataFrame
Dataframe containing the correlation matrix to get the self and cross correlations from.
num_vertical_features : int
Number of vertical features in the correlation matrix.
num_horizontal_features : int
Number of horizontal features in the correlation matrix.
Returns
-------
vertical_correlations : pd.DataFrame
Dataframe containing the vertical self correlations from the correlation matrix.
horizontal_correlations : pd.DataFrame
Dataframe containing the horizontal self correlations from the correlation matrix.
cross_correlations : pd.DataFrame
Dataframe containing the cross correlations from the correlation matrix.
"""
try:
vertical_correlations = getVerticalSelfCorrelations(correlation_matrix, num_vertical_features)
horizontal_correlations = getHorizontalSelfCorrelations(correlation_matrix, num_horizontal_features)
cross_correlations = getCrossCorrelationMatrix(correlation_matrix, num_vertical_features)
except Exception as e:
msg = f"Error getting self and cross correlations from correlation matrix: {e}"
logger.exception(msg)
raise e

return vertical_correlations, horizontal_correlations, cross_correlations

0 comments on commit bec3ab4

Please sign in to comment.