~ubuntu-branches/ubuntu/quantal/deap/quantal

« back to all changes in this revision

Viewing changes to doc/_scripts/ackley.py

  • Committer: Package Import Robot
  • Author(s): Miriam Ruiz, Jakub Wilk, Miriam Ruiz
  • Date: 2011-11-17 11:53:15 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20111117115315-k9lkwpqcbsq8n0q7
Tags: 0.7.1-1
[ Jakub Wilk ]
* Add Vcs-* fields.

[ Miriam Ruiz ]
* New Upstream Release
* Upgraded Standards-Version from 3.9.1 to 3.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mpl_toolkits.mplot3d import Axes3D
 
2
from matplotlib import cm
 
3
from matplotlib.colors import LogNorm
 
4
import matplotlib.pyplot as plt
 
5
import sys
 
6
 
 
7
try:
 
8
    import numpy as np
 
9
except:
 
10
    exit()
 
11
 
 
12
 
 
13
sys.path.append("../..")
 
14
from deap import benchmarks
 
15
 
 
16
 
 
17
def ackley_arg0(sol):
 
18
    return benchmarks.ackley(sol)[0]
 
19
 
 
20
fig = plt.figure()
 
21
# ax = Axes3D(fig, azim = -29, elev = 50)
 
22
ax = Axes3D(fig)
 
23
X = np.arange(-30, 30, 0.5)
 
24
Y = np.arange(-30, 30, 0.5)
 
25
X, Y = np.meshgrid(X, Y)
 
26
Z = np.zeros(X.shape)
 
27
 
 
28
for i in xrange(X.shape[0]):
 
29
    for j in xrange(X.shape[1]):
 
30
        Z[i,j] = ackley_arg0((X[i,j],Y[i,j]))
 
31
 
 
32
ax.plot_surface(X, Y, Z, rstride = 1, cstride = 1,  norm = LogNorm(), cmap = cm.jet, linewidth=0.2, )
 
33
 
 
34
plt.xlabel("x")
 
35
plt.ylabel("y")
 
36
 
 
37
plt.show()
 
 
b'\\ No newline at end of file'