-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong code in [7] to plot the Rosenbrock function ? #628
Comments
Thank you very much for noticing the problem and proposing a fix! It most likely is related to the release of numpy 2.0.0. |
Installed numpy on my windows: 1.26.4. |
I can not reproduce the problem in my environment. What are your Python, matplotlib versions? |
Reduced code from https://github.com/SMTorg/smt/blob/master/tutorial/SMT_Tutorial.ipynb import numpy as np
from matplotlib import cm
import matplotlib.pyplot as plt
from smt.problems import Rosenbrock
from smt.sampling_methods import LHS
########### Initialization of the problem, construction of the training and validation points
ndim = 2
ndoe = 20 # int(10*ndim)
# Define the function
fun = Rosenbrock(ndim=ndim)
# Construction of the DOE
# in order to have the always same LHS points, random_state=1
sampling = LHS(xlimits=fun.xlimits, criterion='ese', random_state=1)
xt = sampling(ndoe)
# Compute the outputs
yt = fun(xt)
# Construction of the validation points
ntest = 200 #500
sampling = LHS(xlimits=fun.xlimits, criterion='ese', random_state=1)
xtest = sampling(ntest)
ytest = fun(xtest)
# To plot the Rosenbrock function
x = np.linspace(-2, 2, 50)
res = []
for x0 in x:
for x1 in x:
res.append(fun(np.array([[x0, x1]])))
res = np.array(res)
res = res.reshape((50, 50)).T
X, Y = np.meshgrid(x, x)
fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(projection="3d")
surf = ax.plot_surface(
X, Y, res, cmap=cm.viridis, linewidth=0, antialiased=False, alpha=0.5
)
# Bad statements
ax.scatter(xt[:, 0], xt[:, 1], yt, zdir="z", marker="x", c="b", s=200, label="Training point")
ax.scatter(xtest[:, 0], xtest[:, 1], ytest, zdir="z", marker=".", c="k", s=200, label="Validation point")
# Updated statements
# ax.scatter(xt[:, 0], xt[:, 1], yt[:, 0], zdir='z', marker='x', c='b', s=200, label='Training point')
# ax.scatter(xtest[:, 0], xtest[:, 1], ytest[:, 0], zdir='z', marker='.', c='k', s=200, label='Validation point')
plt.title("Rosenbrock function")
plt.xlabel("x1")
plt.ylabel("x2")
plt.legend()
plt.show() Note: Same result for Numpy 1.26.4 |
I've upgraded from matplotlib 3.8.3 to 3.9.2 and succeeded in reproducing the bug. Your change fixes it, thanks. We leave this issue opened till the notebook is fixed. |
For statements in [7] of https://github.com/SMTorg/smt/blob/master/tutorial/SMT_Tutorial.ipynb, the shapes for x, y are different from z, and it will get following figure which is different from the figure shown on that web page.
Maybe it should be revised as following, but it looks like that there's still a little different.
The text was updated successfully, but these errors were encountered: