示例#1
0
    n = 2
    epochs = 5000
    N = 5

    np.random.seed(2)
    samples = np.zeros((N, 2))
    #samples[:,0] = np.array([0.1, 0.1, 0.5, 0.9])
    #samples[:,1] = np.array([0.1, 0.9, 0.5, 0.9])
    samples[:, 0] = np.array([0.1, 0.1, 0.5, 0.9, 0.9])
    samples[:, 1] = np.array([0.1, 0.9, 0.5, 0.1, 0.9])

    print 'Neural Gas'
    np.random.seed(2)
    ng = NG((n, n, 2))
    ng.learn(samples, epochs)
    print 'Self-Organizing Map'
    np.random.seed(2)
    som = SOM((n, n, 2))
    som.learn(samples, epochs)
    print 'Dynamic Self-Organizing Map'
    np.random.seed(2)
    dsom = DSOM((n, n, 2), elasticity=1.0, lrate=0.1)
    #dsom = DSOM((n,n,2), elasticity=1.75)
    dsom.learn(samples, epochs)

    fig = plt.figure(figsize=(21, 8))
    fig.patch.set_alpha(0.0)

    axes = plt.subplot(1, 3, 1)
    ng.plot(axes)
示例#2
0
    n, p = 8, 16
    epochs = 20000
    N = 1000

    np.random.seed(123)
    samples = np.zeros((N, p * p))
    T = np.random.uniform(low=-np.pi / 2, high=np.pi / 2, size=N)
    for i in range(N):
        samples[i] = gaussian(shape=(p, p), sigma=(.5, 2),
                              theta=T[i]).flatten()

    print 'Neural Gas'
    np.random.seed(123)
    ng = NG((n, n, p * p), init_method='fixed')
    ng.learn(samples, epochs, noise=0.1)

    print 'Self-Organizing Map'
    np.random.seed(123)
    som = SOM((n, n, p * p), init_method='fixed')
    som.learn(samples, epochs, noise=0.1)

    print 'Dynamic Self-Organizing Map'
    np.random.seed(123)
    dsom = DSOM((n, n, p * p), elasticity=1.5, init_method='fixed')
    dsom.learn(samples, epochs, noise=0.1)

    fig = plt.figure(figsize=(21, 8))
    fig.patch.set_alpha(0.0)

    axes = plt.subplot(131, frameon=False)
        return Z

    n,p = 8, 16
    epochs = 20000
    N = 1000

    np.random.seed(123)
    samples = np.zeros((N,p*p))
    T = np.random.uniform(low=-np.pi/2, high=np.pi/2, size=N)
    for i in range(N):
        samples[i] = gaussian(shape=(p,p), sigma=(.5,2), theta=T[i]).flatten()

    print 'Neural Gas'
    np.random.seed(123)
    ng = NG((n,n,p*p), init_method='fixed')
    ng.learn(samples,epochs, noise=0.1)

    print 'Self-Organizing Map'
    np.random.seed(123)
    som = SOM((n,n,p*p), init_method='fixed')
    som.learn(samples,epochs, noise=0.1)

    print 'Dynamic Self-Organizing Map'
    np.random.seed(123)
    dsom = DSOM((n,n,p*p), elasticity=1.5, init_method='fixed')
    dsom.learn(samples,epochs, noise=0.1)

    fig = plt.figure(figsize=(21,8))
    fig.patch.set_alpha(0.0)

    axes = plt.subplot(131, frameon=False)
示例#4
0
    from mpl_toolkits.axes_grid import make_axes_locatable
    from mpl_toolkits.axes_grid import AxesGrid
    from network import NG,SOM,DSOM
    from distribution import uniform, normal, ring, image

    n,p = 8, 8
    epochs = 10000
    N = 5000

    np.random.seed(123)
    samples = image(filename='lena.png', shape=(p,p), n=N) 

    print 'Neural Gas'
    np.random.seed(123)
    ng = NG((n,n,p*p), init_method='fixed')
    ng.learn(samples,epochs)

    print 'Self-Organizing Map'
    np.random.seed(123)
    som = SOM((n,n,p*p), init_method='fixed')
    som.learn(samples,epochs)

    print 'Dynamic Self-Organizing Map'
    np.random.seed(123)
    dsom = DSOM((n,n,p*p), elasticity=0.5, init_method='fixed')
    dsom.learn(samples,epochs)

    # fig = plt.figure(figsize=(10,10))
    # axes = plt.subplot(111, frameon=False)
    # plot(dsom,n,p)
示例#5
0
    size = 8
    epochs = 20000
    n = 10000

    np.random.seed(12345)

    samples_1 = uniform(n=n, center=(0.25,0.25), scale=(0.25,0.25))
    samples_2 = uniform(n=n, center=(0.75,0.75), scale=(0.25,0.25))
    samples_3 = uniform(n=n, center=(0.25,0.75), scale=(0.25,0.25))
    samples_4 = uniform(n=n, center=(0.75,0.25), scale=(0.25,0.25))


    print 'Neural gas'
    np.random.seed(12345)
    ng = NG((size,size,2))
    ng.learn([samples_1,   samples_2,   samples_3,   samples_4],
             [2*epochs//8, 2*epochs//8, 2*epochs//8, 2*epochs//8])

    print 'Self-Organizing Map'
    np.random.seed(12345)
    som = SOM((size,size,2))
    som.learn([samples_1,   samples_2,   samples_3,   samples_4],
              [2*epochs//8, 2*epochs//8, 2*epochs//8, 2*epochs//8])

    print 'Dynamic Self-Organizing Map'
    np.random.seed(12345)
    dsom = DSOM((size,size,2), elasticity=2.5)
    dsom.learn([samples_1,   samples_2,   samples_3,   samples_4],
               [2*epochs//8, 2*epochs//8, 2*epochs//8, 2*epochs//8])

    fig = plt.figure(figsize=(21,8))
    fig.patch.set_alpha(0.0)