(base_vector, idd, perturbation_degree, dimensions)
| 227 | |
| 228 | |
| 229 | def generate_perturbation(base_vector, idd, perturbation_degree, dimensions): |
| 230 | # Generate the perturbation |
| 231 | perturbation = np.random.uniform( |
| 232 | -perturbation_degree, perturbation_degree, dimensions |
| 233 | ) |
| 234 | |
| 235 | # Apply the perturbation and clamp the values within the range of -1 to 1 |
| 236 | # perturbed_values = base_vector["values"] + perturbation |
| 237 | perturbed_values = np.array(base_vector["values"]) + perturbation |
| 238 | clamped_values = np.clip(perturbed_values, -1, 1) |
| 239 | |
| 240 | perturbed_vector = {"id": idd, "values": clamped_values.tolist()} |
| 241 | # print(base_vector["values"][:10]) |
| 242 | # print( perturbed_vector["values"][:10] ) |
| 243 | # cs = cosine_similarity(base_vector["values"], perturbed_vector["values"] ) |
| 244 | # print ("cosine similarity of perturbed vec: ", row_ct, cs) |
| 245 | return perturbed_vector |
| 246 | # if np.random.rand() < 0.01: # 1 in 100 probability |
| 247 | # shortlisted_vectors.append(perturbed_vector) |
| 248 | |
| 249 | |
| 250 | def process_base_vector_batch( |
no outgoing calls
no test coverage detected