Skip to content

Instantly share code, notes, and snippets.

@vlavorini
Last active September 27, 2017 17:00
Show Gist options
  • Save vlavorini/898021b6fa0ee42ff539f045bbf3b97e to your computer and use it in GitHub Desktop.
Save vlavorini/898021b6fa0ee42ff539f045bbf3b97e to your computer and use it in GitHub Desktop.
def __shift(points, sigma, beg, end):
dists=dist_batch(points, beg, end)
weights = gaussian(dists, sigma)
expd_w=np.dot(weights.T, points)
summed_weight=np.sum(weights,0)
return expd_w/np.expand_dims(summed_weight,1), beg, end # we return also the position of the starting and ending vectors
def meanshift_parallel(points, batches)
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
future_shifting = {executor.submit(__shift, points, sigma, d_beg, min(d_beg+batches, n_samples)):
d_beg for d_beg in range(0, n_samples, batches)} # the dictionary with the functions which are going to be executed
for future in concurrent.futures.as_completed(future_shifting): # for each function we wait for the execution
points[future.result()[1]:future.result()[2]]=future.result()[0] # when a function is actually executed, we update the dataset with the results
return points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment