Coordinate_descent.svg
Size of this PNG preview of this SVG file:
600 × 600 pixels
.
Other resolutions:
240 × 240 pixels
|
480 × 480 pixels
|
768 × 768 pixels
|
1,024 × 1,024 pixels
|
2,048 × 2,048 pixels
|
900 × 900 pixels
.
Summary
Description Coordinate 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
|
This plot was created with
Matplotlib
.
|
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.