zoukankan      html  css  js  c++  java
  • 凸优化算法之坐标上升法

    原理

    对于没有约束限制的优化问题,可以每次仅更新函数中的一维,固定其他参数,迭代多次以达到求解优化函数的目的。
    这里写图片描述 (W表示待求凸函数,α向量是待求解)
    具体过程如下
    这里写图片描述

    举例
    求解问题   f(x1,x2) = 3x12 + x22 + 4x1x2 - 8
    迭代次数计数
            {
    1、固定x2更新x1     x1 = - 2/3 x2
    2、固定x1更新x2   x2 = -2 x1
    }
    figure_1-5.png
    # -*- coding: utf-8 -*-
    """
    Created on Wed Apr 05 18:09:41 2017
    @author: LoveDMR
    坐标上升法
    """
    import numpy as np
    import matplotlib.pyplot as plt
    delta = 0.025
    x1 = np.arange( -5 , 5 , delta )
    x2 = np.arange( -5 , 5 , delta )
    X1 , X2 = np.meshgrid( x1 , x2 )
    Y = X1**2 + 5 * X2**2 + 3 * X1 * X2 - 6
    plt.figure()
    bg_fig = plt.contour(X1,X2,Y)
    a , b = [] , []
    a.append(-4)
    b.append(3)
    j = 1
    for i in xrange(1,150):
        a_tmp = - 1.5 * b[j-1]
        a.append( a_tmp )
        b.append( b[j-1] )
        
        j = j + 1
        
        b_tmp = - 0.3 * a[j-1]
        b.append( b_tmp )
        a.append( a[j-1] )
        
    plt.plot(a , b)
    plt.title( "Coordinate Ascent" )
    plt.xlabel('x1')
    plt.ylabel('x2')
    plt.show()
    

      

    另外可以迭代到W的值不再变化或着变化幅度小于某个值即可
     
  • 相关阅读:
    linux 学习随笔-shell基础知识
    linux 学习随笔-压缩和解压缩
    解析xml的4种方法详解
    集合工具类
    Map概述
    List集合概述
    Java集合框架
    Spring JdbcTemplate详解
    关于c3p0数据库连接池的简单使用
    Java通过JDBC封装通用DAO层
  • 原文地址:https://www.cnblogs.com/flyfatty/p/6684305.html
Copyright © 2011-2022 走看看