Пример #1
0
    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)
    plot(ng, n, p)
    axes = plt.subplot(132, frameon=False)
    plot(som, n, p)
    axes = plt.subplot(133, frameon=False)
Пример #2
0
    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)
    axes = fig.add_subplot(1, 3, 2)
    som.plot(axes)
    axes = fig.add_subplot(1, 3, 3)
Пример #3
0
    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)

    axes = plt.subplot(1,3,1)
    ng.plot(axes)
    axes = plt.subplot(1,3,2)