File: rastrigin.py

package info (click to toggle)
deap 1.0.2.post2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,816 kB
  • sloc: python: 6,914; cpp: 482; makefile: 84; sh: 10
file content (31 lines) | stat: -rw-r--r-- 633 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt

try:
    import numpy as np
except:
    exit()

from deap import benchmarks

def rastrigin_arg0(sol):
    return benchmarks.rastrigin(sol)[0]

fig = plt.figure()
ax = Axes3D(fig, azim = -29, elev = 50)
X = np.arange(-5, 5, 0.1)
Y = np.arange(-5, 5, 0.1)
X, Y = np.meshgrid(X, Y)
Z = np.zeros(X.shape)

for i in xrange(X.shape[0]):
    for j in xrange(X.shape[1]):
        Z[i,j] = rastrigin_arg0((X[i,j],Y[i,j]))

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet, linewidth=0.2)
 
plt.xlabel("x")
plt.ylabel("y")

plt.show()