Exemplo n.º 1
0
def example_disk_dimensions(N=100):
    print('\n***mds.example_disk_dimensions()***\n')
    dims = range(1, 11)
    stress = []
    for dim in dims:
        Y = misc.disk(N, dim)
        D = distances.compute(Y)
        mds = MDS(D, dim, verbose=1, label=f'dimension : {dim}')
        mds.initialize_Y()
        mds.optimize(algorithm='agd', max_iters=300)
        stress.append(mds.ncost)
    fig = plt.figure()
    plt.semilogy(dims, stress)
    plt.xlabel('dimension')
    plt.ylabel('stress')
    plt.title('Normalized MDS stress for various dimensions')
    plt.show()
Exemplo n.º 2
0
def example_disk_noisy(N=100, dim=2):
    print('\n***mds.example_disk_noisy()***\n')
    noise_levels = [0.001, 0.005, 0.01, 0.03, 0.07, 0.1, 0.15, 0.2, 0.7, 1.0]
    stress = []
    Y = misc.disk(N, dim)
    D = distances.compute(Y)
    for noise in noise_levels:
        D_noisy = distances.add_noise(D, noise)
        mds = MDS(D_noisy, dim, verbose=1, title=f'noise : {noise:0.2f}')
        mds.initialize()
        mds.optimize(algorithm='agd', max_iters=300, verbose=1)
        stress.append(mds.ncost)
    fig = plt.figure()
    plt.loglog(noise_levels, stress, '.-')
    plt.xlabel('noise level')
    plt.ylabel('stress')
    plt.title('Normalized MDS stress for various noise levels')
    plt.show()
Exemplo n.º 3
0
def embeddability_noise(ax=None):
    print('\n**mds.embeddability_noise()')
    N = 50
    ncost = []
    noise_list = [0] + 10**np.arange(-2, 1, 0.5)
    X = misc.disk(N, 4)
    DD = distances.compute(X)
    for noise in noise_list:
        D = DD * (1 + np.random.randn(N, N) * noise)
        mds = MDS(D, dim=4, verbose=1)
        mds.initialize()
        mds.optimize()
        ncost.append(mds.ncost)
    if ax is None:
        fig, ax = plt.subplots(1)
        plot = True
    else:
        plot = False
    ax.semilogx(noise_list, ncost)
    if plot is True:
        plt.show()
Exemplo n.º 4
0
def embeddability_dims(ax=None):
    print('\n**mds.embeddability_dims()')
    N = 50
    ncost = []
    dims = list(range(2, 50, 5))
    #XX = misc.disk(N,20)
    XX = misc.box(N, 20)
    for dim in dims:
        X = XX[:, 0:dim]
        D = multigraph.coord2dict(X, weights='relative')
        mds = MDS(D, dim=2, verbose=1)
        mds.initialize()
        mds.optimize()
        ncost.append(mds.ncost)
    if ax is None:
        fig, ax = plt.subplots(1)
        plot = True
    else:
        plot = False
    ax.plot(dims, ncost)
    if plot is True:
        plt.show()
Exemplo n.º 5
0
def disk_compare(N=100, dim=2):  ###
    print('\n***mds.disk_compare()***')

    X = misc.disk(N, 2)
    labels = misc.labels(X)

    plt.figure()
    plt.scatter(X[:, 0], X[:, 1], c=labels)
    plt.title('original data')
    plt.draw()
    plt.pause(0.1)

    D = distances.compute(X)

    mds = MDS(D, dim=dim, verbose=1, title='disk experiments', labels=labels)
    mds.initialize()
    mds.figureX(title='initial embedding')

    title = 'full gradient & agd'
    mds.optimize(algorithm='agd', verbose=2, label=title)
    mds.figureX(title=title)
    mds.figureH(title=title)

    mds.forget()
    title = 'approx gradient & gd'
    mds.approximate(algorithm='gd', verbose=2, label=title)
    mds.figureX(title=title)
    mds.figureH(title=title)

    mds.forget()
    title = 'combine'
    mds.approximate(algorithm='gd', verbose=2, label=title)
    mds.optimize(verbose=2, label=title, max_iters=10)
    mds.figureX(title=title)
    mds.figureH(title=title)
    plt.show()