Jump to content

File:Coordinate descent.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file (SVG file, nominally 900 × 900 pixels, file size: 56 KB)

Summary

Description
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
 
The SVG code is valid.
 
This plot was created with Matplotlib.
 
The file size of this SVG plot may be irrationally large because its text has been converted to paths inhibiting translations.
Source code
InfoField

Python code

from __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:
w:en:Creative Commons
attribution
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/TimeThumbnailDimensionsUserComment
current00:10, 10 January 2016Thumbnail for version as of 00:10, 10 January 2016900 × 900 (56 KB)NicoguaroAdd labels to the contours.
23:19, 9 January 2016Thumbnail for version as of 23:19, 9 January 2016900 × 900 (50 KB)NicoguaroUser created page with UploadWizard

The following 2 pages use this file:

Global file usage

The following other wikis use this file:

Metadata