Exemplo n.º 1
0
def test_clustering():
    from ultranest.mlfriends import update_clusters
    for i in range(5):
        np.random.seed(i * 100)

        points = np.random.uniform(size=(100, 2))

        nclusters, clusteridxs, overlapped_points = update_clusters(
            points, points, 0.1**2)

        for i in np.unique(clusteridxs):
            x, y = points[clusteridxs == i].transpose()
            plt.scatter(x, y)
        plt.savefig('testclustering_0p1.pdf', bbox_inches='tight')
        plt.close()
        assert 1 < nclusters < 30

        nclusters, clusteridxs, overlapped_points = update_clusters(
            points, points, 0.2**2)

        for i in np.unique(clusteridxs):
            x, y = points[clusteridxs == i].transpose()
            plt.scatter(x, y)
        plt.savefig('testclustering_0p2.pdf', bbox_inches='tight')
        plt.close()
        assert 1 <= nclusters < 2
Exemplo n.º 2
0
def test_overclustering_eggbox_txt():
    from ultranest.mlfriends import update_clusters, ScalingLayer, MLFriends
    np.random.seed(1)
    for i in [20, 23, 24, 27, 49]:
        print()
        print("==== TEST CASE %d =====================" % i)
        print()
        points = np.loadtxt(os.path.join(here, "overclustered_u_%d.txt" % i))

        for k in range(3):
            transformLayer = ScalingLayer(wrapped_dims=[])
            transformLayer.optimize(points, points)
            region = MLFriends(points, transformLayer)
            maxr = region.compute_maxradiussq(nbootstraps=30)
            region.maxradiussq = maxr
            nclusters = transformLayer.nclusters

            print("manual: r=%e nc=%d" % (region.maxradiussq, nclusters))
            # assert 1e-10 < maxr < 5e-10
            nclusters, clusteridxs, overlapped_points = update_clusters(
                points, points, maxr)
            print("reclustered: nc=%d" % (nclusters))

        if False:
            plt.title('nclusters: %d' % nclusters)
            for k in np.unique(clusteridxs):
                x, y = points[clusteridxs == k].transpose()
                plt.scatter(x, y)
            plt.savefig('testoverclustering_eggbox_%d.pdf' % i,
                        bbox_inches='tight')
            plt.close()
        assert 14 < nclusters < 20, (nclusters, i)

        for j in range(3):
            nclusters, clusteridxs, overlapped_points = update_clusters(
                points, points, maxr)
            assert 14 < nclusters < 20, (nclusters, i)
Exemplo n.º 3
0
def test_clusteringcase_eggbox():
    from ultranest.mlfriends import update_clusters, ScalingLayer, MLFriends
    points = np.loadtxt(os.path.join(here, "eggboxregion.txt"))
    transformLayer = ScalingLayer()
    transformLayer.optimize(points, points)
    region = MLFriends(points, transformLayer)
    maxr = region.compute_maxradiussq(nbootstraps=30)
    assert 1e-10 < maxr < 5e-10
    print('maxradius:', maxr)
    nclusters, clusteridxs, overlapped_points = update_clusters(
        points, points, maxr)
    # plt.title('nclusters: %d' % nclusters)
    # for i in np.unique(clusteridxs):
    #    x, y = points[clusteridxs == i].transpose()
    #    plt.scatter(x, y)
    # plt.savefig('testclustering_eggbox.pdf', bbox_inches='tight')
    # plt.close()
    assert 14 < nclusters < 20, nclusters
Exemplo n.º 4
0
def test_clusteringcase():
    from ultranest.mlfriends import update_clusters
    here = os.path.dirname(__file__)
    points = np.loadtxt(os.path.join(here, "clusters2.txt"))
    maxr = np.loadtxt(os.path.join(here, "clusters2_radius.txt"))
    #transformLayer = ScalingLayer()
    #transformLayer.optimize(points)
    #region = MLFriends(points, transformLayer)
    #maxr = region.compute_maxradiussq(nbootstraps=30)
    print('maxradius:', maxr)
    nclusters, clusteridxs, overlapped_points = update_clusters(
        points, points, maxr)
    plt.title('nclusters: %d' % nclusters)
    for i in np.unique(clusteridxs):
        x, y = points[clusteridxs == i].transpose()
        plt.scatter(x, y)
    plt.savefig('testclustering_2.pdf', bbox_inches='tight')
    plt.close()