MCPcopy Create free account
hub / github.com/cosdata/cosdata / perturb_vector

Function perturb_vector

tests/load-test.py:198–207  ·  view source on GitHub ↗
(vector, perturbation_degree)

Source from the content-addressed store, hash-verified

196
197
198def 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
210def dot_product(vec1, vec2):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected