Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DataScienceUWL
GitHub Repository: DataScienceUWL/DS775
Path: blob/main/Lessons/Lesson 05 - Local Optimization/scripts/rastrigin_2d.py
871 views
1
import plotly.graph_objs as go
2
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
3
import numpy as np
4
5
x = np.linspace(-5.12, 5.12, 401)
6
y = np.linspace(-5.12, 5.12, 401)
7
X, Y = np.meshgrid(x, y)
8
Z = (X**2 - 10 * np.cos(2 * np.pi * X)) + \
9
(Y**2 - 10 * np.cos(2 * np.pi * Y)) + 20
10
11
data = [
12
go.Surface( x = X, y = Y, z = Z, colorscale = 'Jet',
13
contours=go.surface.Contours(
14
z=go.surface.contours.Z(
15
show=True,
16
usecolormap=True,
17
highlightcolor="#42f462",
18
project=dict(z=True)
19
)
20
)
21
)
22
]
23
24
layout = go.Layout(title='Rastrigin',width=600,height=600)
25
fig = go.Figure(data=data, layout=layout)
26
iplot(fig)
27