MCPcopy Create free account
hub / github.com/FinancialComputingUCL/LOBFrame / mean_tmfg

Function mean_tmfg

data_processing/complete_homological_utils.py:122–153  ·  view source on GitHub ↗

Compute the average similarity matrix for a list of similarity matrices. Parameters ---------- sm_list : List[pandas.DataFrame] The list of similarity matrices to compute the average for. Returns ---------- average_matrix : pandas.DataFrame The average

(sm_list: List[pd.DataFrame])

Source from the content-addressed store, hash-verified

120
121
122def mean_tmfg(sm_list: List[pd.DataFrame]) -> pd.DataFrame:
123 """
124 Compute the average similarity matrix for a list of similarity matrices.
125
126 Parameters
127 ----------
128 sm_list : List[pandas.DataFrame]
129 The list of similarity matrices to compute the average for.
130
131 Returns
132 ----------
133 average_matrix : pandas.DataFrame
134 The average similarity matrix.
135 """
136
137 # Stack the matrices along a new axis (axis=0)
138 stacked_matrices = np.stack(sm_list, axis=0)
139
140 # Calculate the entry-wise average along the new axis
141 average_matrix = np.mean(stacked_matrices, axis=0)
142 np.fill_diagonal(average_matrix, 0)
143
144 average_matrix = pd.DataFrame(average_matrix)
145
146 '''
147 plt.figure(figsize=(10, 8)) # Optional: Adjusts the size of the figure
148 sns.heatmap(average_matrix, annot=True, fmt=".2f", cmap='coolwarm', square=True, linewidths=.5)
149 plt.title("Correlation Matrix Heatmap")
150 plt.show()
151 '''
152
153 return average_matrix
154
155
156def extract_components(

Callers 1

execute_pipelineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected