###### null的专栏

Keep your eyes open and your feet moving forward. You'll find what you need.

# 一、坐标上升法算法原理

maxαW(α1,α2,,αm)

(图片来自参考文献1)

f(x1,x2)=x213x22+2x1x2+6

fx1=2x1+2x2

x1=x2

fx2=6x2+2x1

x2=13x1

'''
Date: 20160406
@author: zhaozhiyong
'''
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = -(X**2)
Z2 = -(Y**2)
Z = 1.0 * (Z1 + 3 * Z2 + 2 * X * Y)+6.0

plt.figure()

CS = plt.contour(X, Y, Z)

a = []
b = []

a.append(2.0)
b.append(2.0)

j = 1

for i in xrange(200):
a_tmp = b[j-1]
a.append(a_tmp)
b.append(b[j-1])

j = j+1

b_tmp = a[j-1] / 3
a.append(a[j-1])
b.append(b_tmp)

plt.plot(a,b)

plt.title('Coordinate Ascent')
plt.xlabel('x')
plt.ylabel('y')
plt.show()

# 二、坐标上升法在函数优化中的应用

argmaxx1,x2,x3f(x1,x2,x3)=x212x223x23+2x1x2+2x1x34x2x3+6

x1=x2+x3

x2=12x1x3

x3=13x123x2

#!/bin/python
'''
Date: 20160406
@author: zhaozhiyong
'''

def f(x):
x_1 = x[0]
x_2 = x[1]
x_3 = x[2]

result = -(x_1*x_1)-2*(x_2*x_2)-3*(x_3*x_3)+2*x_1*x_2+2*x_1*x_3-4*x_2*x_3+6

return result

if __name__ == "__main__":
#print "hello world"
err = 1.0e-10
x = [1.0, 1.0, 1.0]
f_0 = f(x)
while 1:
#print "Hello"
x[0] = x[1] + x[2]
x[1] = x[0] / 2 - x[2]
x[2] = x[0] / 3 - 2 * x[1] / 3

f_t = f(x)

if (abs(f_t - f_0) < err):
break

f_0 = f_t

print "max: " + str(f_0)
print x

# 参考文章

#### SVM求解之坐标上升算法（Coordinate Ascent）

2013-12-01 14:50:39

#### 坐标上升/下降算法

2017-07-13 10:14:20

#### 公开课机器学习笔记（15）支持向量机五 坐标上升法 SMO优化算法

2015-03-28 15:56:36

#### 坐标上升算法（Coordinate Ascent）及C++编程实现

2012-12-20 13:43:10

#### 坐标轴下降法（解决L1正则化不可导的问题）

2017-04-06 16:20:26

#### 坐标下降法（坐标上升法）matlab程序

2017-06-12 20:28:48

#### 坐标上升算法总结(文档c++代码)

2012年12月20日 1.08MB 下载

#### 坐标上升法算法

2017-11-01 17:30:05

#### 坐标下降法(Coordinate descent)

2014-10-26 15:20:14

#### 最大似然估计、梯度下降、EM算法、坐标上升

2017-03-01 21:31:12