neural-networks-and-deep-learning misleading_gradient.py

来源:互联网 发布:手机淘宝标题模块 编辑:程序博客网 时间:2024/05/20 18:01

梯度下降

虽然纯看代码看不出来是干什么的,但是还是能学到一些语法的。

ax即

gca(self, **kwargs) method of matplotlib.figure.Figure instance    Get the current axes, creating one if necessary

surf即在ax上绘制一个平面

ax.set_xlim3d就是各个维度的长度

ax.w_xaxis.set_major_locator就是设置显示几个坐标点来定位

ax.text就是在当前坐标系上的某个三维坐标中显示字符串的内容。

"""misleading_gradient~~~~~~~~~~~~~~~~~~~Plots a function which misleads the gradient descent algorithm."""#### Libraries# Third party librariesfrom matplotlib.ticker import LinearLocator# Note that axes3d is not explicitly used in the code, but is needed# to register the 3d plot type correctlyfrom mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as pltimport numpyfig = plt.figure()ax = fig.gca(projection='3d')X = numpy.arange(-1, 1, 0.025)Y = numpy.arange(-1, 1, 0.025)X, Y = numpy.meshgrid(X, Y)Z = X**2 + 10*Y**2colortuple = ('w', 'b')colors = numpy.empty(X.shape, dtype=str)for x in xrange(len(X)):    for y in xrange(len(Y)):        colors[x, y] = colortuple[(x + y) % 2]surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,        linewidth=0)ax.set_xlim3d(-2, 2)ax.set_ylim3d(-2, 2)ax.set_zlim3d(0, 20)ax.w_xaxis.set_major_locator(LinearLocator(6))ax.w_yaxis.set_major_locator(LinearLocator(6))ax.w_zaxis.set_major_locator(LinearLocator(6))ax.text(0.05, -1.8, 0, "$w_1$", fontsize=20)ax.text(1.5, -0.25, 0, "$w_2$", fontsize=20)ax.text(1.79, 0, 9.62, "$C$", fontsize=20)plt.show()
0 0
原创粉丝点击