Skip to content
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

H3Neighbourhood undeterminism #441

Open
Calychas opened this issue Apr 20, 2024 · 0 comments
Open

H3Neighbourhood undeterminism #441

Calychas opened this issue Apr 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Calychas
Copy link
Collaborator

Calychas commented Apr 20, 2024

After changes in #436 the H3Neighbourhood became undeterministic. The underlying library (h3py) returns from 4.0.0.b3 - uber/h3-py#339 neighbours in random order. That means that downstream models cannot be forced to return the same results between different sessions.

Potential solutions:

  1. sort values from neighbourhoods inside the models - easiest for now, but that needs to be remembered across the models
  2. change interface and logic of neighbourhoods to return sorted results (probably list instead of set) - preferred, one fix and done

e.g. a solution for 1. for Hex2VecEmbedder can look like that

def _build_lookup_tables(self, data: pd.DataFrame, neighbourhood: Neighbourhood[T]) -> None:
  anchor_df_locs_lookup: list[int] = []
  positive_df_locs_lookup: list[int] = []
  
  for region_df_loc, region_index in tqdm(enumerate(data.index), total=len(data)):
      region_direct_neighbours = sorted(neighbourhood.get_neighbours(region_index))
      neighbours_df_locs = {
          self._region_index_to_df_loc[neighbour_index]
          for neighbour_index in region_direct_neighbours
      }
      anchor_df_locs_lookup.extend([region_df_loc] * len(neighbours_df_locs))
      positive_df_locs_lookup.extend(neighbours_df_locs)
  
      indices_excluded_from_negatives = sorted(neighbourhood.get_neighbours_up_to_distance(
          region_index, self._negative_sample_k_distance
      ))
      self._excluded_from_negatives[region_df_loc] = {
          self._region_index_to_df_loc[excluded_index]
          for excluded_index in indices_excluded_from_negatives
      }
  
  self._anchor_df_locs_lookup = np.array(anchor_df_locs_lookup)
  self._positive_df_locs_lookup = np.array(positive_df_locs_lookup)
@Calychas Calychas added the bug Something isn't working label Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant