File:Coordinate descent.svg
From testwiki
Jump to navigation
Jump to search
Original file (SVG file, nominally 900 × 900 pixels, file size: 56 KB)
Contents
This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.
Summary
| DescriptionCoordinate descent.svg |
English: Coordinate descent with cyclic iteration of the coordinates. In each iteration a line search is done to find the step. |
| Date | |
| Source | Own work |
| Author | Nicoguaro |
| SVG development InfoField | |
| Source code InfoField | Python codefrom __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import line_search
from matplotlib import rcParams
rcParams['font.family'] = 'serif'
rcParams['font.size'] = 16
def fun(x, y):
return 5*x**2 - 6*x*y + 5*y**2
def f(x):
x1 = x[0]
x2 = x[1]
return fun(x1, x2)
def g(x):
x1 = x[0]
x2 = x[1]
g1 = 10*x1 - 6*x2
g2 = -6*x1 + 10*x2
return [g1, g2]
X, Y = np.mgrid[-1.5:1.5:101j, -1.5:1.5:101j]
Z = fun(X, Y)
levels = np.linspace(0.5, 5, 6)
plt.figure(figsize=(10, 10))
CS = plt.contour(X, Y, Z, levels=levels, colors='k')
plt.clabel(CS)
xk = np.array([-0.5, -1])
pk = np.array([0., 1.])
for k in range(10):
res = line_search(f, g, xk, pk)
alpha = res[0]
xnew = xk + 0.6*alpha*pk
pk = pk[::-1]
plt.arrow(xk[0], xk[1], xnew[0] - xk[0], xnew[1] - xk[1],
fc='r', ec='r',
length_includes_head=True)
xk = xnew
plt.axis('image')
plt.xlabel(r'$x$', size=18)
plt.ylabel(r'$y$', size=18)
plt.title(r'$f(x,y) = 5x^2 - 6xy + 5y^2$')
plt.savefig('coordinate descent.svg')
plt.show()
|
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
Captions
Add a one-line explanation of what this file represents
Items portrayed in this file
depicts
9 January 2016
image/svg+xml
8aa4708e79cc2d206b2113e4eb039473c69399c9
56,909 byte
900 pixel
900 pixel
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 01:10, 10 January 2016 | 900 × 900 (56 KB) | wikimediacommons>Nicoguaro | Add labels to the contours. |
File usage
There are no pages that use this file.