def unif_resample(x,n,tol=1,deg=3): x = np.atleast_2d(x) x = remove_duplicate_rows(x) dl = mu.norms(x[1:] - x[:-1],1) l = np.cumsum(np.r_[0,dl]) (tck,_) = si.splprep(x.T,k=deg,s = tol**2*len(x),u=l) newu = np.linspace(0,l[-1],n) return np.array(si.splev(newu,tck)).T
def unif_resample(x,n,weights,tol=.001,deg=3): x = np.atleast_2d(x) weights = np.atleast_2d(weights) x = mu.remove_duplicate_rows(x) x_scaled = x * weights dl = mu.norms(x_scaled[1:] - x_scaled[:-1],1) l = np.cumsum(np.r_[0,dl]) (tck,_) = si.splprep(x_scaled.T,k=deg,s = tol**2*len(x),u=l) newu = np.linspace(0,l[-1],n) out_scaled = np.array(si.splev(newu,tck)).T out = out_scaled/weights return out
def unif_resample(x, n, weights, tol=.001, deg=3): x = np.atleast_2d(x) weights = np.atleast_2d(weights) x = mu.remove_duplicate_rows(x) x_scaled = x * weights dl = mu.norms(x_scaled[1:] - x_scaled[:-1], 1) l = np.cumsum(np.r_[0, dl]) (tck, _) = si.splprep(x_scaled.T, k=deg, s=tol**2 * len(x), u=l) newu = np.linspace(0, l[-1], n) out_scaled = np.array(si.splev(newu, tck)).T out = out_scaled / weights return out
def nearest_neighbor(x, ys): return mu.norms(ys - x[None,:],1).argmin()