Esempio n. 1
0
def plot_anim_ssga(minimum, maximum, dif):
    def sphere_two(x,y):
	return (x**2+y**2)

    dx = dy = dif
    x = arange(minimum, maximum, dx)
    y = arange(minimum, maximum, dy)
    X,Y = meshgrid(x, y)
    Z = sphere_two(X, Y)
    fig = plt.figure()
    ax = subplot(111)
    x, y = (np.random.rand(2, 50))*100
    #ax.plot(x, y, 'wo')
    im = imshow(Z, cmap=cm.jet)
    im.set_interpolation('bilinear')
    #show()

    domain = [-5, 5]
    dim=2
    ea = SSGA(domain=domain, size=50, dim=dim, fitness=fitness_sphere)
    ea.initPopulation(dim)
    population = ea.population()
    x = population[:,0]
    y = population[:,1]
    line, = ax.plot(x, y, 'wo')
    ea.run(maxeval=dim*10000)

    import gobject
    print 'adding idle'
    gobject.idle_add(animate)
    print 'showing'
    plt.show()