def test_bulk_get_min_distance(self): """Verify that bulk version returns the same as regular version. This function checks that the bulk version of get_min_distance on a number of randomly generated points returns the same result as the regular version. """ for i in range(50): dim = np.random.randint(1, 20) num_points_1 = np.random.randint(10, 50) num_points_2 = np.random.randint(10, 50) points = np.random.uniform(-100, 100, size=(num_points_1,dim)) other_points = np.random.uniform(-100, 100, size=(num_points_2,dim)) dist1 = [ru.get_min_distance(point, other_points) for point in points] dist2 = ru.bulk_get_min_distance(points, other_points) for j in range(num_points_1): msg='Failed random test {:d} point {:d}'.format(i, j) self.assertAlmostEqual(dist1[j], dist2[j], 12, msg=msg)
def test_bulk_get_min_distance(self): """Verify that bulk version returns the same as regular version. This function checks that the bulk version of get_min_distance on a number of randomly generated points returns the same result as the regular version. """ for i in range(50): dim = np.random.randint(1, 20) num_points_1 = np.random.randint(10, 50) num_points_2 = np.random.randint(10, 50) points = np.random.uniform(-100, 100, size=(num_points_1, dim)) other_points = np.random.uniform(-100, 100, size=(num_points_2, dim)) dist1 = [ ru.get_min_distance(point, other_points) for point in points ] dist2 = ru.bulk_get_min_distance(points, other_points) for j in range(num_points_1): msg = 'Failed random test {:d} point {:d}'.format(i, j) self.assertAlmostEqual(dist1[j], dist2[j], 12, msg=msg)
def addPoints(pointFilePath, valueFilePath, model): points, values = readPoints(pointFilePath, valueFilePath) #Check that points have correct dimensionality assert len(points[0]) == len( model.l_lower), "Model has %d dimensions, but point file has %d" % ( len(model.l_lower), len(points[0])) #Scale points points_scaled = rbfopt_utils.bulk_transform_domain(model.l_settings, model.l_lower, model.l_upper, points) #Add the points (last entry is for fast evals) #add_node(self, point, orig_point, value, is_fast) for i in range(len(points)): #Distance test if (rbfopt_utils.get_min_distance(points[i], model.all_node_pos) > model.l_settings.min_dist): model.add_node(points_scaled[i], points[i], values[i]) else: print("Point too close to add to model!")
def test_get_min_distance(self): """Test some extreme cases for get_min_distance.""" self.assertEqual( ru.get_min_distance( np.array([i for i in range(5)]), np.array([[i + j for i in range(5)] for j in range(10)])), 0.0)
def test_get_min_distance(self): """Test some extreme cases for get_min_distance.""" self.assertEqual(ru.get_min_distance(np.array([i for i in range(5)]), np.array([[i+j for i in range(5)] for j in range(10)])), 0.0)