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

Function perturb_vector

tests/rps-test.py:190–199  ·  view source on GitHub ↗
(vector, perturbation_degree)

Source from the content-addressed store, hash-verified

188
189
190def 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
202def dot_product(vec1, vec2):

Callers 1

rps-test.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected