def test_load_uniform_ball_cloud(): for n_points in [10, 20, 40, 80, 160]: with warnings.catch_warnings(record=True) as w: points = surface._load_uniform_ball_cloud(n_points=n_points) assert_array_equal(points.shape, (n_points, 3)) assert_equal(len(w), 0) assert_warns(surface.EfficiencyWarning, surface._load_uniform_ball_cloud, n_points=3) for n_points in [3, 10, 20]: computed = surface._uniform_ball_cloud(n_points) loaded = surface._load_uniform_ball_cloud(n_points) assert_array_almost_equal(computed, loaded)
def test_load_uniform_ball_cloud(): for n_points in [10, 20, 40, 80, 160]: with warnings.catch_warnings(record=True) as w: points = surface._load_uniform_ball_cloud(n_points=n_points) assert_array_equal(points.shape, (n_points, 3)) assert_equal(len(w), 0) assert_warns(surface.EfficiencyWarning, surface._load_uniform_ball_cloud, n_points=3) # before 0.18 k-means was computed differently, so the result # would differ from the stored values, computed with version 0.2 if LooseVersion(sklearn.__version__) >= LooseVersion('0.18'): for n_points in [3, 10, 20]: computed = surface._uniform_ball_cloud(n_points) loaded = surface._load_uniform_ball_cloud(n_points) assert_array_almost_equal(computed, loaded)
def test_sample_locations(): # check positions of samples on toy example, with an affine != identity # flat horizontal mesh mesh = flat_mesh(5, 7) affine = np.diagflat([10, 20, 30, 1]) inv_affine = np.linalg.inv(affine) # transform vertices to world space vertices = np.asarray( resampling.coord_transform(*mesh[0].T, affine=affine)).T # compute by hand the true offsets in voxel space # (transformed by affine^-1) ball_offsets = surface._load_uniform_ball_cloud(10) ball_offsets = np.asarray( resampling.coord_transform(*ball_offsets.T, affine=inv_affine)).T line_offsets = np.zeros((10, 3)) line_offsets[:, 2] = np.linspace(1, -1, 10) line_offsets = np.asarray( resampling.coord_transform(*line_offsets.T, affine=inv_affine)).T # check we get the same locations for kind, offsets in [('line', line_offsets), ('ball', ball_offsets)]: locations = surface._sample_locations( [vertices, mesh[1]], affine, 1., kind=kind, n_points=10) true_locations = np.asarray([vertex + offsets for vertex in mesh[0]]) assert_array_equal(locations.shape, true_locations.shape) assert_array_almost_equal(true_locations, locations) pytest.raises(ValueError, surface._sample_locations, mesh, affine, 1., kind='bad_kind')
def test_load_uniform_ball_cloud(): for n_points in [10, 20, 40, 80, 160]: with warnings.catch_warnings(record=True) as w: points = surface._load_uniform_ball_cloud(n_points=n_points) assert_array_equal(points.shape, (n_points, 3)) assert_equal(len(w), 0) assert_warns(surface.EfficiencyWarning, surface._load_uniform_ball_cloud, n_points=3) # before 0.18 k-means was computed differently, so the result # would differ from the stored values, computed with version 0.2 if LooseVersion(sklearn.__version__) >= LooseVersion('0.18'): for n_points in [3, 10, 20]: computed = surface._uniform_ball_cloud(n_points) loaded = surface._load_uniform_ball_cloud(n_points) assert_array_almost_equal(computed, loaded)
def test_sample_locations(): # check positions of samples on toy example, with an affine != identity # flat horizontal mesh mesh = flat_mesh(5, 7) affine = np.diagflat([10, 20, 30, 1]) inv_affine = np.linalg.inv(affine) # transform vertices to world space vertices = np.asarray( resampling.coord_transform(*mesh[0].T, affine=affine)).T # compute by hand the true offsets in voxel space # (transformed by affine^-1) ball_offsets = surface._load_uniform_ball_cloud(10) ball_offsets = np.asarray( resampling.coord_transform(*ball_offsets.T, affine=inv_affine)).T line_offsets = np.zeros((10, 3)) line_offsets[:, 2] = np.linspace(-1, 1, 10) line_offsets = np.asarray( resampling.coord_transform(*line_offsets.T, affine=inv_affine)).T # check we get the same locations for kind, offsets in [('line', line_offsets), ('ball', ball_offsets)]: locations = surface._sample_locations( [vertices, mesh[1]], affine, 1., kind=kind, n_points=10) true_locations = np.asarray([vertex + offsets for vertex in mesh[0]]) assert_array_equal(locations.shape, true_locations.shape) assert_array_almost_equal(true_locations, locations) assert_raises(ValueError, surface._sample_locations, mesh, affine, 1., kind='bad_kind')
def test_load_uniform_ball_cloud(): # Note: computed and shipped point clouds may differ since KMeans results # change after # https://github.com/scikit-learn/scikit-learn/pull/9288 # but the exact position of the points does not matter as long as they are # well spread inside the unit ball for n_points in [10, 20, 40, 80, 160]: with warnings.catch_warnings(record=True) as w: points = surface._load_uniform_ball_cloud(n_points=n_points) assert_array_equal(points.shape, (n_points, 3)) assert len(w) == 0 with pytest.warns(surface.EfficiencyWarning): surface._load_uniform_ball_cloud(n_points=3) for n_points in [3, 7]: computed = surface._uniform_ball_cloud(n_points) loaded = surface._load_uniform_ball_cloud(n_points) assert_array_almost_equal(computed, loaded) assert (np.std(computed, axis=0) > .1).all() assert (np.linalg.norm(computed, axis=1) <= 1).all()