예제 #1
0
def axis_aligned_experiment():
    """
    Compare  random kd-tree with axis-aligned kd-tree.
    """
    print("Compare with basic axis-aligned tree")

    data_1 = uniform_distribution(20000, 10, 3)
    data_2 = uniform_distribution(20000, 10, 3)
    data_3 = uniform_distribution(20000, 20, 3)
    data_4 = uniform_distribution(20000, 20, 3)

    print("generate kd_tree 1")
    t_1 = kd_tree_paper(data_1, approx_diameter=0.25)
    print("generate kd_tree 2")
    t_2 = kd_tree_axis(data_2, approx_diameter=0.25)
    print("generate kd_tree 3")
    t_3 = kd_tree_paper(data_3, approx_diameter=0.25)
    print("generate kd_tree 4")
    t_4 = kd_tree_axis(data_4, approx_diameter=0.25)
    print("done")

    distrib1, stats_1 = get_tree_statistics(t_1)
    distrib2, stats_2 = get_tree_statistics(t_2)
    distrib3, stats_3 = get_tree_statistics(t_3)
    distrib4, stats_4 = get_tree_statistics(t_4)

    avg_1 = np.array(stats_1[0][:20])
    avg_2 = np.array(stats_2[0][:20])
    avg_3 = np.array(stats_3[0][:20])
    avg_4 = np.array(stats_4[0][:20])

    avg_1 /= avg_1[0]
    avg_2 /= avg_2[0]
    avg_3 /= avg_3[0]
    avg_4 /= avg_4[0]

    plt.figure()
    plt.title("Random kd-tree vs axis-aligned tree, uniform distribution")
    plt.plot(np.log(avg_1),
             linestyle="--",
             marker="o",
             label="Random, D=10, d=3")
    plt.plot(np.log(avg_2),
             linestyle="--",
             marker="o",
             label="Axis, D=10, d=3")
    plt.plot(np.log(avg_3),
             linestyle="--",
             marker="o",
             label="Random, D=20, d=3")
    plt.plot(np.log(avg_4),
             linestyle="--",
             marker="o",
             label="Axis aligned, D=20, d=3")
    plt.ylabel("Average log-Diameter (rescaled at depth 0 = 0)")
    plt.xlabel("Depth of tree node")
    plt.legend(loc=3)
    plt.savefig(output_folder + 'fig8.png', bbox_inches='tight')
예제 #2
0
def rp_tree_experiment():
    """
    Compare random kd-tree of the paper with random projection trees.
    """
    print("Compare with RP-tree")

    data_1 = uniform_distribution(20000, 10, 3)
    data_2 = uniform_distribution(20000, 10, 3)
    data_3 = uniform_distribution(20000, 50, 3)
    data_4 = uniform_distribution(20000, 50, 3)

    print("generate kd_tree 1")
    t_1 = kd_tree_paper(data_1, approx_diameter=0.25)
    print("generate kd_tree 2")
    t_2 = rp_tree(data_2, approx_diameter=0.25)
    print("generate kd_tree 3")
    t_3 = kd_tree_paper(data_3, approx_diameter=0.25)
    print("generate kd_tree 4")
    t_4 = rp_tree(data_4, approx_diameter=0.25)
    print("done")

    distrib1, stats_1 = get_tree_statistics(t_1)
    distrib2, stats_2 = get_tree_statistics(t_2)
    distrib3, stats_3 = get_tree_statistics(t_3)
    distrib4, stats_4 = get_tree_statistics(t_4)

    avg_1 = np.array(stats_1[0][:17])
    avg_2 = np.array(stats_2[0][:17])
    avg_3 = np.array(stats_3[0][:17])
    avg_4 = np.array(stats_4[0][:17])

    avg_1 /= avg_1[0]
    avg_2 /= avg_2[0]
    avg_3 /= avg_3[0]
    avg_4 /= avg_4[0]

    plt.figure()
    plt.title("Random kd-tree vs RP tree, uniform distribution")
    plt.plot(np.log(avg_1),
             linestyle="--",
             marker="o",
             label="Random, D=10, d=3")
    plt.plot(np.log(avg_2), linestyle="--", marker="o", label="RP, D=10, d=3")
    plt.plot(np.log(avg_3),
             linestyle="--",
             marker="o",
             label="Random, D=50, d=3")
    plt.plot(np.log(avg_4), linestyle="--", marker="o", label="RP, D=50, d=3")
    plt.ylabel("Average log-Diameter (rescaled at depth 0 = 0)")
    plt.xlabel("Depth of tree node")
    plt.legend()
    plt.savefig(output_folder + 'fig7.png', bbox_inches='tight')
예제 #3
0
def uniform_experiment():
    """
    Experiment with uniformly distributed points in affine subspace.    
    
    Generate uniformly distributed points in affine subspace with same intrinsic
    dimension but different ambiant dimensions and evaluate the diameter 
    reduction rate of the kd-tree with increased depth.
    """
    print("Uniform distribution")

    data_1 = uniform_distribution(20000, 4, 3)
    data_2 = uniform_distribution(20000, 12, 3)
    data_3 = uniform_distribution(20000, 32, 3)

    print("generate kd_tree 1")
    t_1 = kd_tree_paper(data_1, approx_diameter=0.25)
    print("generate kd_tree 2")
    t_2 = kd_tree_paper(data_2, approx_diameter=0.25)
    print("generate kd_tree 3")
    t_3 = kd_tree_paper(data_3, approx_diameter=0.25)

    distrib1, stats_1 = get_tree_statistics(t_1)
    distrib2, stats_2 = get_tree_statistics(t_2)
    distrib3, stats_3 = get_tree_statistics(t_3)

    avg_1 = np.array(stats_1[0][:20])
    avg_2 = np.array(stats_2[0][:20])
    avg_3 = np.array(stats_3[0][:20])

    avg_1 /= avg_1[0]
    avg_2 /= avg_2[0]
    avg_3 /= avg_3[0]

    plt.figure()
    plt.title("Experiment with Uniform distribution in 3D affine subspace")
    plt.plot(np.log(avg_1), linestyle="--", marker="o", label="D=4, d=3")
    plt.plot(np.log(avg_2), linestyle="--", marker="o", label="D=12, d=3")
    plt.plot(np.log(avg_3), linestyle="--", marker="o", label="D=32 d=3")
    plt.ylabel("Average log-Diameter (rescaled at depth 0 = 0)")
    plt.xlabel("Depth of tree node")
    plt.legend()
    plt.savefig(output_folder + 'fig3.png', bbox_inches='tight')
예제 #4
0
def mecharm_smooth1D_uniform_experiment():
    """
    Experiment with uniformly distributed points on a hypersphere's surface.    
    
    Generate uniformly points on an hypersphare and compare it with other point
    sets of similar expected intrinsic dimension in term of diameter reduction 
    rate of the kd-tree with increased depth.
    """
    print(
        "Mechanical Arm vs 1D smooth manifold vs Uniform Distribution (1D manifold)"
    )

    data_1 = mechanical_arm(20000, 3, 1)
    data_2 = smooth_1d_manifold(20000, 8)
    data_3 = uniform_distribution(20000, 16, 1)

    print("generate kd_tree 1")
    t_1 = kd_tree_paper(data_1, approx_diameter=0.25)
    print("generate kd_tree 2")
    t_2 = kd_tree_paper(data_2, approx_diameter=0.25)
    print("generate kd_tree 3")
    t_3 = kd_tree_paper(data_3, approx_diameter=0.25)

    distrib1, stats_1 = get_tree_statistics(t_1)
    distrib2, stats_2 = get_tree_statistics(t_2)
    distrib3, stats_3 = get_tree_statistics(t_3)

    avg_1 = np.array(stats_1[0][:20])
    avg_2 = np.array(stats_2[0][:20])
    avg_3 = np.array(stats_3[0][:20])

    avg_1 /= avg_1[0]
    avg_2 /= avg_2[0]
    avg_3 /= avg_3[0]

    plt.figure()
    plt.title("Comparison with Mechanical Arm, 1D smooth manifold and Uniform")
    plt.plot(np.log(avg_1),
             linestyle="--",
             marker="o",
             label="Mechanical Arm, D=3, d=1")
    plt.plot(np.log(avg_2),
             linestyle="--",
             marker="o",
             label="1D Smooth, D=8, d=1")
    plt.plot(np.log(avg_3),
             linestyle="--",
             marker="o",
             label="Uniform, D=16 d=1")
    plt.ylabel("Average log-Diameter (rescaled at depth 0 = 0)")
    plt.xlabel("Depth of tree node")
    plt.legend()
    plt.savefig(output_folder + 'fig5.png', bbox_inches='tight')
예제 #5
0
def hollow_gauss_uniform_experiment():
    """
    Experiment with uniformly distributed points on a hypersphere's surface.    
    
    Generate uniformly points on an hypersphare and compare it with other point
    sets of similar expected intrinsic dimension in term of diameter reduction 
    rate of the kd-tree with increased depth.
    """
    print(
        "Hollow hypersphere vs Gaussian Distribution vs Uniform Distribution (4D manifold)"
    )

    data_1 = hollow_hypersphere(20000, 5)
    data_2 = uniform_distribution(20000, 5, 4)
    data_3 = gaussian_distribution(20000, 10, 4)

    print("generate kd_tree 1")
    t_1 = kd_tree_paper(data_1, approx_diameter=0.25)
    print("generate kd_tree 2")
    t_2 = kd_tree_paper(data_2, approx_diameter=0.25)
    print("generate kd_tree 3")
    t_3 = kd_tree_paper(data_3, approx_diameter=0.25)

    distrib1, stats_1 = get_tree_statistics(t_1)
    distrib2, stats_2 = get_tree_statistics(t_2)
    distrib3, stats_3 = get_tree_statistics(t_3)

    avg_1 = np.array(stats_1[0][:20])
    avg_2 = np.array(stats_2[0][:20])
    avg_3 = np.array(stats_3[0][:20])

    avg_1 /= avg_1[0]
    avg_2 /= avg_2[0]
    avg_3 /= avg_3[0]

    plt.figure()
    plt.title("Comparison with Hollow Hypersphere, Gaussian and Uniform")
    plt.plot(np.log(avg_1),
             linestyle="--",
             marker="o",
             label="Hollow Sphere, D=5, d=4")
    plt.plot(np.log(avg_2),
             linestyle="--",
             marker="o",
             label="Uniform, D=5, d=4")
    plt.plot(np.log(avg_3),
             linestyle="--",
             marker="o",
             label="Gaussian, D=10 d=4")
    plt.ylabel("Average log-Diameter (rescaled at depth 0 = 0)")
    plt.xlabel("Depth of tree node")
    plt.legend()
    plt.savefig(output_folder + 'fig4.png', bbox_inches='tight')
예제 #6
0
def swissroll_mecharm_uniform():
    """
    Experiment with randomly distributed points on the swissroll.    
    
    Generate randomly points on a "swissroll" and compare it with other point
    sets of similar expected intrinsic dimension in term of diameter reduction 
    rate of the kd-tree with increased depth.
    """
    print("Swiss Roll vs Mechanical Arm vs Uniform")

    data_1 = swiss_roll(20000)
    data_2 = mechanical_arm(20000, 3, 2)
    data_3 = mechanical_arm(20000, 6, 3)
    data_4 = uniform_distribution(20000, 8, 3)

    print("generate kd_tree 1")
    t_1 = kd_tree_paper(data_1, approx_diameter=0.25)
    print("generate kd_tree 2")
    t_2 = kd_tree_paper(data_2, approx_diameter=0.25)
    print("generate kd_tree 3")
    t_3 = kd_tree_paper(data_3, approx_diameter=0.25)
    print("generate kd_tree 4")
    t_4 = kd_tree_paper(data_4, approx_diameter=0.25)
    print("done")

    distrib1, stats_1 = get_tree_statistics(t_1)
    distrib2, stats_2 = get_tree_statistics(t_2)
    distrib3, stats_3 = get_tree_statistics(t_3)
    distrib4, stats_4 = get_tree_statistics(t_4)

    avg_1 = np.array(stats_1[0][:20])
    avg_2 = np.array(stats_2[0][:20])
    avg_3 = np.array(stats_3[0][:20])
    avg_4 = np.array(stats_4[0][:20])

    avg_1 /= avg_1[0]
    avg_2 /= avg_2[0]
    avg_3 /= avg_3[0]
    avg_4 /= avg_4[0]

    plt.figure()
    plt.title("Swiss Roll vs Mechanical Arm vs Uniform")
    plt.plot(np.log(avg_1),
             linestyle="--",
             marker="o",
             label="Swiss Roll, D=3, d=2")
    plt.plot(np.log(avg_2),
             linestyle="--",
             marker="o",
             label="Mechanical Arm, D=6, d=2")
    plt.plot(np.log(avg_3),
             linestyle="--",
             marker="o",
             label="Mechanical Arm, D=18, d=3")
    plt.plot(np.log(avg_4),
             linestyle="--",
             marker="o",
             label="Uniform, D=8, d=3")
    plt.ylabel("Average log-Diameter (rescaled at depth 0 = 0)")
    plt.xlabel("Depth of tree node")
    plt.legend()
    plt.savefig(output_folder + 'fig6.png', bbox_inches='tight')