def test_nearest_neighbors(self): a, b, c = self.a, self.b, self.c ns = list(nearest_neighbors([a, b, c], .25)) self.assertEqual(len(ns), 0) ns = list(nearest_neighbors([a, b, c], 1.4)) self.assertEqual(len(ns), 2) ns = list(nearest_neighbors([a,b,c], 2.1)) self.assertEqual(len(ns), 3) self.assertEqual(ns, [[a, b], [a, c], [c, b]])
def time_everything(n_samples, dim, epsilon, max_dim): points = [sample_torus(dim) for i in range(n_samples)] now = time.time() one_skel = list(nearest_neighbors(points, epsilon)) nn_time = time.time() - now now = time.time() # exp_ind = expand_inductive(points, one_skel, max_dim) exp_ind_time = time.time() - now now = time.time() inc_vr = incremental_vr(points, one_skel, max_dim) inc_vr_time = time.time() - now def sxs_size(d): for k in d: print "{0}: {1}".format(k, len(d[k])) sxs_size(inc_vr) return (nn_time, exp_ind_time, inc_vr_time)
def vr(n_samples, dim, epsilon, max_dim): points = [sample_torus(dim) for i in range(n_samples)] one_skel = list(nearest_neighbors(points, epsilon)) return incremental_vr(points, one_skel, max_dim)