(vector, perturbation_degree)
| 196 | |
| 197 | |
| 198 | def perturb_vector(vector, perturbation_degree): |
| 199 | # Generate the perturbation |
| 200 | perturbation = np.random.uniform( |
| 201 | -perturbation_degree, perturbation_degree, len(vector["values"]) |
| 202 | ) |
| 203 | # Apply the perturbation and clamp the values within the range of -1 to 1 |
| 204 | perturbed_values = np.array(vector["values"]) + perturbation |
| 205 | clamped_values = np.clip(perturbed_values, -1, 1) |
| 206 | vector["values"] = clamped_values.tolist() |
| 207 | return vector |
| 208 | |
| 209 | |
| 210 | def dot_product(vec1, vec2): |
nothing calls this directly
no outgoing calls
no test coverage detected