Last active
January 10, 2020 14:08
-
-
Save psycharo-zz/6a7d94404aed0be0112bf9751876f36b to your computer and use it in GitHub Desktop.
This file contains 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
n_masks = 100 | |
n_channels = 100 | |
# do not sample more masks than this | |
n_max_samples = 50 | |
target_corr = 0.1 | |
target_corr_eps = 1.0e-2 | |
rate = target_corr | |
min_corr = target_corr - target_corr_eps | |
max_corr = target_corr + target_corr_eps | |
n_indices = int(n_channels * rate) | |
masks = np.zeros((n_masks, n_channels)) | |
indices = np.random.choice(n_channels, n_indices, replace=False) | |
masks[0,indices] = 1.0 | |
n_samples = 1 | |
def _sample_mask(): | |
indices = np.random.choice(n_channels, n_indices, replace=False) | |
mask = np.zeros((n_channels)) | |
mask[indices] = 1.0 | |
return mask | |
for i in range(1, n_masks): | |
# generating the next mask | |
prev_masks = masks[:n_samples] | |
for j in range(n_max_samples): | |
mask = _sample_mask() | |
mean_corr = np.mean(np.dot(prev_masks, mask) / n_indices) | |
if min_corr < mean_corr and mean_corr < max_corr: | |
break | |
# checking if it satisfies our constraints | |
masks[n_samples,:] = mask | |
n_samples += 1 | |
corr = np.dot(masks, masks.T) / n_indices | |
np.mean(corr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment