(vector, perturbation_degree)
| 188 | |
| 189 | |
| 190 | def perturb_vector(vector, perturbation_degree): |
| 191 | # Generate the perturbation |
| 192 | perturbation = np.random.uniform( |
| 193 | -perturbation_degree, perturbation_degree, len(vector["values"]) |
| 194 | ) |
| 195 | # Apply the perturbation and clamp the values within the range of -1 to 1 |
| 196 | perturbed_values = np.array(vector["values"]) + perturbation |
| 197 | clamped_values = np.clip(perturbed_values, -1, 1) |
| 198 | vector["values"] = clamped_values.tolist() |
| 199 | return vector |
| 200 | |
| 201 | |
| 202 | def dot_product(vec1, vec2): |