Skip to content

Instantly share code, notes, and snippets.

@vlavorini
Created September 26, 2017 14:35
Show Gist options
  • Save vlavorini/caa423a88ae1be1a0b1a1bf480a2a3d5 to your computer and use it in GitHub Desktop.
Save vlavorini/caa423a88ae1be1a0b1a1bf480a2a3d5 to your computer and use it in GitHub Desktop.
def dist_batch(points, n_begin, n_end):
expd=np.expand_dims(points,2)
tiled=np.tile(expd, n_end-n_begin) #we tile up only (n_end-n_begin) times
selected=points[n_begin:n_end] # we select only part (a batch) of the whole dataset
trans=np.transpose(selected)
diff=trans-tiled
num=np.sum(np.square(diff), axis=1)
den_sq_norm=1-np.sum(np.square(points),1)
den_selected=den_sq_norm[n_begin:n_end] # we select only part (a batch) of the whole dataset
den_expd=np.expand_dims(den_sq_norm,1)
den=den_expd * den_selected.T
return np.arccosh(1+2*num/ den)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment