Jan Mühlnikel commited on
Commit
dda6e4a
·
1 Parent(s): ae68b70

experiment

Browse files
Files changed (1) hide show
  1. functions/calc_matches.py +27 -0
functions/calc_matches.py CHANGED
@@ -53,6 +53,32 @@ def calc_matches(filtered_df, project_df, similarity_matrix, top_x):
53
  # Select submatrix based on indices from both dataframes
54
  match_matrix = similarity_matrix[filtered_df_indices, :][:, project_df_indices]
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  # Get the linear indices of the top 'top_x' values
57
  # (flattened index to handle the sparse matrix more effectively)
58
  linear_indices = np.argsort(match_matrix.data)[-top_x:]
@@ -74,4 +100,5 @@ def calc_matches(filtered_df, project_df, similarity_matrix, top_x):
74
  print("finished calc matches")
75
 
76
  return p1_df, p2_df
 
77
 
 
53
  # Select submatrix based on indices from both dataframes
54
  match_matrix = similarity_matrix[filtered_df_indices, :][:, project_df_indices]
55
 
56
+ st.write(match_matrix.shape)
57
+
58
+ flattened_indices = np.argsort(match_matrix, axis=None)[-15:]
59
+
60
+ # Step 2: Convert flattened indices to 2D indices
61
+ row_indices, col_indices = np.unravel_index(flattened_indices, match_matrix.shape)
62
+
63
+ # Step 3: Extract the top 15 values and their corresponding indices
64
+ top_values = match_matrix[row_indices, col_indices]
65
+ top_indices = list(zip(row_indices, col_indices, top_values))
66
+
67
+ # Step 4: Sort the indices and values based on the values in descending order
68
+ top_15_indices_sorted = sorted(top_indices, key=lambda x: x[2], reverse=True)
69
+
70
+ # Display the results
71
+ for idx, (row, col, value) in enumerate(top_15_indices_sorted):
72
+ st.write(f"Rank {idx + 1}: Value = {value}, Row Index = {row}, Column Index = {col}")
73
+
74
+ p1_df = filtered_df.iloc[row_indices].copy()
75
+ p1_df['similarity'] = top_values
76
+ p2_df = project_df.iloc[col_indices].copy()
77
+ p2_df['similarity'] = top_values
78
+
79
+ return p1_df, p2_df
80
+
81
+ """
82
  # Get the linear indices of the top 'top_x' values
83
  # (flattened index to handle the sparse matrix more effectively)
84
  linear_indices = np.argsort(match_matrix.data)[-top_x:]
 
100
  print("finished calc matches")
101
 
102
  return p1_df, p2_df
103
+ """
104