コード例 #1
0
def test_triangle_variance_space_3D_case(sphere):
    """Test the values of the barycentric coordinates (variance space).

    alpha and beta must be close to 0. (so gamme close to 1.)
    """
    pca = PCA().fit(sphere)
    norm_eigenvalues = sum_normalize(pca.singular_values_**2)
    alpha, beta = triangle_variance_space(norm_eigenvalues)
    assert 1 - (alpha + beta) >= 0.95
コード例 #2
0
def test_triangle_variance_space_2D_case(plane):
    """Test the values of the barycentric coordinates (variance space).

    beta must be > alpha and close to 1.0
    """
    pca = PCA().fit(plane)
    norm_eigenvalues = sum_normalize(pca.singular_values_**2)
    alpha, beta = triangle_variance_space(norm_eigenvalues)
    assert alpha < beta
    assert beta >= 0.95
コード例 #3
0
def test_triangle_variance_space_1D_case(line):
    """Test the values of the barycentric coordinates (variance space).

    'alpha' must be >> to 'beta'
    """
    pca = PCA().fit(line)
    norm_eigenvalues = sum_normalize(pca.singular_values_**2)
    alpha, beta = triangle_variance_space(norm_eigenvalues)
    assert alpha > beta
    assert abs(alpha - 1) < 1e-3
コード例 #4
0
def test_3d_features_line(line):
    """Test curvature change, linearity, planarity and scattering for a line.
    """
    pca = PCA().fit(line)
    norm_eigenvalues = sum_normalize(pca.singular_values_**2)
    # close to 1
    assert linearity(norm_eigenvalues) >= 0.9
    # close to zero
    assert curvature_change(norm_eigenvalues) <= 5e-3
    assert planarity(norm_eigenvalues) <= 0.05
    assert scattering(norm_eigenvalues) <= 0.05
コード例 #5
0
def test_3d_features_sphere(sphere):
    """Test curvature change, linearity, planarity and scattering for a sphere.
    """
    pca = PCA().fit(sphere)
    norm_eigenvalues = sum_normalize(pca.singular_values_**2)
    # close to 1/3
    assert abs(curvature_change(norm_eigenvalues) - 1 / 3) <= 0.05
    # close to 1
    assert scattering(norm_eigenvalues) >= 0.9
    # close to 0
    assert linearity(norm_eigenvalues) <= 0.05
    assert planarity(norm_eigenvalues) <= 0.05
コード例 #6
0
def test_sum_triangle_variance_space(plane):
    """Test the values of the barycentric coordinates (variance space).

    The function returns the first two barycentric coordinates but you should have
    `alpha + beta + gamma = 1`
    """
    pca = PCA().fit(plane)
    norm_eigenvalues = sum_normalize(pca.singular_values_**2)
    print(pca.singular_values_)
    print(pca.singular_values_**2)
    print(norm_eigenvalues)
    alpha, beta = triangle_variance_space(norm_eigenvalues)
    assert alpha + beta <= 1.0
コード例 #7
0
def process_full(neighbors, dist_to_neighbors, extra):
    """Build the full feature set for a single point

    Parameters
    ----------
    neighbors : numpy.array
        Coordinates of all points within the point neighborhood; must be a
    2D-shaped array with `point_cloud.shape[1] == 3`
    dist_to_neighbors : numpy.array
        Gives distance between the point and all its neighbors
    extra : ExtraFeatures
        Names and values of extra input features, e.g. the RGB color

    Returns
    ------
    list, OrderedDict generator (features for each point)

    """
    num_neighbors = neighbors.shape[0] - 1
    x, y, z = neighbors[0]
    rad_2D = radius_2D(neighbors[0, :2], neighbors[:, :2])
    rad_3D = radius_3D(dist_to_neighbors)
    if len(neighbors) <= 2:
        return (
            FeatureTuple(
                x, y, z,
                np.nan, np.nan,  # alpha, beta
                rad_3D,
                val_range(neighbors[:, 2]),  # z_range
                std_deviation(neighbors[:, 2]),  # std_dev
                density_3D(rad_3D, len(neighbors)),
                np.nan, np.nan, np.nan, np.nan, np.nan,
                np.nan, np.nan, np.nan, np.nan,
                rad_2D,
                density_2D(rad_2D, len(neighbors)),
                np.nan,  # eigenvalue_sum_2D
                np.nan,  # eigenvalue_ratio_2D
            ),
            extra
        )
    else:
        pca = fit_pca(neighbors)  # PCA on the x,y,z coords
        eigenvalues_3D = pca.singular_values_ ** 2
        norm_eigenvalues_3D = sum_normalize(eigenvalues_3D)
        alpha, beta = triangle_variance_space(norm_eigenvalues_3D)
        pca_2d = fit_pca(neighbors[:, :2])  # PCA just on the x,y coords
        eigenvalues_2D = pca_2d.singular_values_ ** 2
        return (
            FeatureTuple(
                x, y, z,
                num_neighbors,
                alpha, beta,
                rad_3D,
                val_range(neighbors[:, 2]),  # z_range
                std_deviation(neighbors[:, 2]),  # std_dev
                density_3D(rad_3D, len(neighbors)),
                verticality_coefficient(pca),
                curvature_change(norm_eigenvalues_3D),
                linearity(norm_eigenvalues_3D),
                planarity(norm_eigenvalues_3D),
                scattering(norm_eigenvalues_3D),
                omnivariance(norm_eigenvalues_3D),
                anisotropy(norm_eigenvalues_3D),
                eigenentropy(norm_eigenvalues_3D),
                val_sum(eigenvalues_3D),  # eigenvalue sum
                rad_2D,
                density_2D(rad_2D, len(neighbors)),
                val_sum(eigenvalues_2D),  # eigenvalue_sum_2D
                eigenvalue_ratio_2D(eigenvalues_2D)
            ),
            extra
        )