matplotlib.use('Agg') import matplotlib.pyplot as plt from network import NG,SOM,DSOM from distribution import uniform, normal, ring n = 8 epochs = 20000 N = 10000 np.random.seed(123) area_1 = np.pi*0.5**2 - np.pi*0.25**2 area_2 = np.pi*0.25**2 n1 = int(area_1*25000) n2 = int(area_2*25000) samples = np.zeros((n1+n2,2)) samples[:n1] = ring(n=n1, radius=(0.25,0.50)) samples[n1:] = ring(n=n2, radius=(0.00,0.25)) print 'Dynamic Self-Organizing Map 1' np.random.seed(123) dsom1 = DSOM((n,n,2), elasticity=1.25, init_method='fixed') dsom1.learn(samples,epochs) n1 = int(area_1*40000) n2 = int(area_2*10000) samples = np.zeros((n1+n2,2)) samples[:n1] = ring(n=n1, radius=(0.25,0.50)) samples[n1:] = ring(n=n2, radius=(0.00,0.25)) print 'Dynamic Self-Organizing Map 2' np.random.seed(123) dsom2 = DSOM((n,n,2), elasticity=1.25, init_method='fixed') dsom2.learn(samples,epochs)
if __name__ == '__main__': import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from network import NG, SOM, DSOM from distribution import uniform, normal, ring n = 8 epochs = 20000 N = 10000 np.random.seed(12345) samples = np.zeros((N, 2)) samples[:N / 2] = ring(n=N / 2, center=(.4, .4), radius=(0.3, 0.4)) samples[N / 2:] = ring(n=N / 2, center=(.6, .6), radius=(0.3, 0.4)) print 'Neural Gas' np.random.seed(123) ng = NG((n, n, 2)) ng.learn(samples, epochs) print 'Self-Organizing Map' np.random.seed(123) som = SOM((n, n, 2)) som.learn(samples, epochs) print 'Dynamic Self-Organizing Map' np.random.seed(123) dsom = DSOM((n, n, 2), elasticity=1.75) dsom.learn(samples, epochs)
# FRANCE if __name__ == '__main__': import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from network import NG, SOM, DSOM from distribution import uniform, normal, ring n = 8 epochs = 20000 N = 10000 np.random.seed(123) samples = ring(n=N, radius=(0.25, 0.5)) print 'Neural Gas' np.random.seed(123) ng = NG((n, n, 2)) ng.learn(samples, epochs) print 'Self-Organizing Map' np.random.seed(123) som = SOM((n, n, 2)) som.learn(samples, epochs) print 'Dynamic Self-Organizing Map' np.random.seed(123) dsom = DSOM((n, n, 2), elasticity=1.75) dsom.learn(samples, epochs) fig = plt.figure(figsize=(21, 8))
import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from network import NG,SOM,DSOM from distribution import uniform, normal, ring n = 8 epochs = 20000 N = 10000 np.random.seed(123) samples = ring(n=N, radius=(0.25,0.5) ) print 'Self-Organizing Map' np.random.seed(123) som = SOM((n,n,2)) som.learn(samples,epochs) print 'Dynamic Self-Organizing Map' np.random.seed(123) 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 = fig.add_subplot(1,3,2) som.plot(axes) axes = fig.add_subplot(1,3,3) dsom.plot(axes)
matplotlib.use('Agg') import matplotlib.pyplot as plt from network import NG, SOM, DSOM from distribution import uniform, normal, ring n = 8 epochs = 20000 N = 10000 np.random.seed(123) area_1 = np.pi * 0.5**2 - np.pi * 0.25**2 area_2 = np.pi * 0.25**2 n1 = int(area_1 * 25000) n2 = int(area_2 * 25000) samples = np.zeros((n1 + n2, 2)) samples[:n1] = ring(n=n1, radius=(0.25, 0.50)) samples[n1:] = ring(n=n2, radius=(0.00, 0.25)) print 'Dynamic Self-Organizing Map 1' np.random.seed(123) dsom1 = DSOM((n, n, 2), elasticity=1.25, init_method='fixed') dsom1.learn(samples, epochs) n1 = int(area_1 * 40000) n2 = int(area_2 * 10000) samples = np.zeros((n1 + n2, 2)) samples[:n1] = ring(n=n1, radius=(0.25, 0.50)) samples[n1:] = ring(n=n2, radius=(0.00, 0.25)) print 'Dynamic Self-Organizing Map 2' np.random.seed(123) dsom2 = DSOM((n, n, 2), elasticity=1.25, init_method='fixed') dsom2.learn(samples, epochs)
if __name__ == '__main__': import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from network import NG,SOM,DSOM from distribution import uniform, normal, ring n = 8 epochs = 20000 N = 10000 np.random.seed(12345) samples = np.zeros((N,2)) samples[:N/2] = ring(n=N/2, center = (.4,.4), radius=(0.3,0.4) ) samples[N/2:] = ring(n=N/2, center = (.6,.6),radius=(0.3,0.4) ) print 'Neural Gas' np.random.seed(123) ng = NG((n,n,2)) ng.learn(samples,epochs) print 'Self-Organizing Map' np.random.seed(123) som = SOM((n,n,2)) som.learn(samples,epochs) print 'Dynamic Self-Organizing Map' np.random.seed(123) dsom = DSOM((n,n,2), elasticity=1.75) dsom.learn(samples,epochs)