-
Notifications
You must be signed in to change notification settings - Fork 4
Updates for find pairs #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,11 +88,31 @@ def find_match_iteration( | |
|
|
||
| s_subset_mask = make_s_subset_mask(m_dist_thresholded, k_dist_thresholded, m_dist_hard, k_dist_hard, required) | ||
|
|
||
| logging.info("Done make_s_subset_mask. s_subset_mask.shape: %s", s_subset_mask.shape) | ||
| s_subset_mask_true = np.zeros(m_set.shape[0], dtype=np.bool_) | ||
|
|
||
| # Randomly select 100 potential pixels per K, these pixels are similar | ||
| # to the particular k and so we should end up with similar distributions | ||
| # for the matching variables. | ||
| no_potentials = np.zeros(k_subset.shape[0], dtype=np.bool_) | ||
| for k in range(s_subset_mask.shape[0]): | ||
| masks = s_subset_mask[k] | ||
| indices = np.argwhere(masks) | ||
| np.random.shuffle(indices) | ||
| idx = indices[:100] | ||
| if len(idx) == 0: | ||
| no_potentials[k] = True | ||
| else: | ||
| for i in idx: | ||
| s_subset_mask_true[i[0]] = True | ||
|
patricoferris marked this conversation as resolved.
|
||
|
|
||
| logging.info(f"Done make_s_subset_mask. s_subset_mask.shape: {s_subset_mask.shape}") | ||
| logging.info(f"Actual indexes {np.cumsum(s_subset_mask_true)}") | ||
|
|
||
| s_subset = m_set[s_subset_mask].reset_index() | ||
| s_subset = m_set[s_subset_mask_true] | ||
| potentials = np.invert(no_potentials) | ||
|
|
||
| logging.info("Finished preparing s_subset. shape: %s", s_subset.shape) | ||
| k_subset = k_subset[potentials] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to |
||
| logging.info(f"Finished preparing s_subset. shape: {s_subset.shape}") | ||
|
|
||
| # Notes: | ||
| # 1. Not all pixels may have matches | ||
|
|
@@ -165,21 +185,10 @@ def find_match_iteration( | |
| logging.info("Finished find match iteration") | ||
|
|
||
| @jit(nopython=True, fastmath=True, error_model="numpy") | ||
| def make_s_subset_mask( | ||
| m_dist_thresholded: np.ndarray, | ||
| k_dist_thresholded: np.ndarray, | ||
| m_dist_hard: np.ndarray, | ||
| k_dist_hard: np.ndarray, | ||
| number_required: int, | ||
| ): | ||
| s_include = np.zeros((m_dist_thresholded.shape[0],), dtype=np.bool_) | ||
| # create an array that is the indexes of the rows in s_dist_thresholded and shuffle it | ||
| m_indexes = np.arange(m_dist_thresholded.shape[0]) | ||
| np.random.shuffle(m_indexes) | ||
| found = 0 | ||
|
|
||
| for position in range(m_dist_thresholded.shape[0]): | ||
| i = m_indexes[position] | ||
| def make_s_subset_mask(m_dist_thresholded: np.ndarray, k_dist_thresholded: np.ndarray, m_dist_hard: np.ndarray, k_dist_hard: np.ndarray, n: int): | ||
| s_include = np.zeros((k_dist_thresholded.shape[0], m_dist_thresholded.shape[0]), dtype=np.bool_) | ||
|
|
||
| for i in range(m_dist_thresholded.shape[0]): | ||
| m_row = m_dist_thresholded[i, :] | ||
| m_hard = m_dist_hard[i] | ||
|
|
||
|
|
@@ -203,13 +212,7 @@ def make_s_subset_mask( | |
| should_include = False | ||
|
|
||
| if should_include: | ||
| s_include[i] = True | ||
| break | ||
|
|
||
| if s_include[i]: | ||
| found += 1 | ||
| if found >= number_required: | ||
| break | ||
| s_include[k][i] = True | ||
|
patricoferris marked this conversation as resolved.
|
||
|
|
||
| return s_include | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to match the methodology step 6.5.4? I don't see anything that then limits to |K| * 10 but maybe I've misunderstood.
Also, that part of the methodology mentions choosing from R "alternating between randomly or stratified by land cover class" - I'm not sure what "stratified by land cover class" means, but we only seem to do randomly.