def setUp(self): np.random.seed(626) points = 100 dim = 1000 self.vector = 99. * (np.random.rand(points, dim) - 0.5) self.label = np.random.randint(0, 5, points) self.dist = euclidean_distance(self.vector) self.dist /= self.dist.max()
def setUp(self): points = 100 dim = 10 self.vector = 99. * (np.random.rand(points, dim) - 0.5) self.label = np.random.randint(0, 5, points) self.dist = euclidean_distance(self.vector) self.SEC_DIST = set(['mp', 'mp_gauss', 'mp_gaussi', 'mp_gammai', 'ls', 'nicdm', 'snn', 'cent', 'wcent', 'lcent', 'dsg', 'dsl', 'orig'])
def setUpMod(self, mode='rnd'): np.random.seed(626) if mode == 'rnd': points = 200 dim = 500 self.vector = 99. * (np.random.rand(points, dim) - 0.5) self.label = np.random.randint(0, 5, points) self.dist = euclidean_distance(self.vector) #self.dist /= (self.dist.max() + 1e-12) elif mode == 'toy': # SNN (k=2) ground truth calculated by hand for this toy example self.dist = squareform([.2, .1, .8, .4, .3, .5, .7, 1., .6, .9]) self.snn_dist_truth = squareform([.5, .5, .5, .5, .5, .5, 0., 0., .5, .5]) self.vector = None self.label = None
def setUpMod(self, mode='rnd'): np.random.seed(626) if mode == 'rnd': points = 200 dim = 500 self.vector = 99. * (np.random.rand(points, dim) - 0.5) self.label = np.random.randint(0, 5, points) self.dist = euclidean_distance(self.vector) elif mode == 'toy': # LS/NICDM ground truth calculated in spreadsheet for toy example self.dist = squareform([.2, .1, .8, .4, .3, .5, .7, 1., .6, .9]) self.ls_dist_truth = squareform( [0.486582881, 0.1535182751, 0.9816843611, 0.7364028619, 0.6321205588, 0.6471339185, 0.9342714714, 0.9844961464, 0.8646647168, 0.8150186001]) self.nicdm_dist_truth = squareform( [0.2936782173, 0.1641711143, 0.7285259947, 0.4153237178, 0.381499195, 0.3526961306, 0.5629896449, 0.7886525234, 0.5395213357, 0.4489088861]) self.vector = None self.label = None
def test_euclidean_dist_equal_to_scipy_pdist_eucl(self): eucl_dist = euclidean_distance(self.vectors) eucl_dist_scipy = squareform(pdist(self.vectors, 'euclidean')) result = np.allclose(eucl_dist, eucl_dist_scipy) return self.assertTrue(result)