Last active
June 3, 2025 09:48
-
-
Save davidlandry93/d52cbf3e0c30018e2fba8b0c5ebbdea3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tqdm | |
from scipy.sparse.csgraph import minimum_spanning_tree | |
def prerank_minimum_spanning_tree(ensemble): | |
n_samples = ensemble.shape[0] | |
n_members = ensemble.shape[1] | |
preranks = np.zeros((n_samples, n_members)) | |
for i in tqdm.tqdm(list(range(n_samples))): | |
for j in range(n_members): | |
ensemble_omit_j = np.delete(ensemble[i], j, axis=0) | |
ensemble_omit_j_t1 = ensemble_omit_j[:, np.newaxis, :] | |
ensemble_omit_j_t2 = ensemble_omit_j[np.newaxis, :, :] | |
distances = np.sqrt( | |
np.square(ensemble_omit_j_t1 - ensemble_omit_j_t2).sum(axis=-1) | |
) | |
mst = minimum_spanning_tree(distances).toarray() | |
preranks[i, j] = mst.sum() | |
return preranks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment