【问题标题】:Minimization of an equation using Python使用 Python 最小化方程
【发布时间】:2018-12-02 20:46:37
【问题描述】:

我有四个向量。

x = [0.4, -0.3, 0.9]
y1 = [0.3, 1, 0]
y2 = [1, -0.9, 0.5]
y3 =[0.6, 0.01, 0.8]

我需要最小化以下等式:

在哪里0 <= a,b,g <= 1。我曾尝试使用scipy.minimize,但我无法理解如何将其用于此等式。是否有任何我可以使用的优化库,或者 Python 中有没有更简单的方法来做到这一点?

我的最终目标是在0-1 之间找到a,b,g 的值,给定这四个向量作为输入的最小值。

【问题讨论】:

  • x - y1a - y2b - y3c 是一个向量,那么如何最小化这个向量呢?
  • 感谢您的回复。我已经用实际方程快照更新了这个问题。我相信这是凸优化问题并且可以解决。如果没有,请告诉我,以便我可以跳过它。
  • alfa = 5.25692e-11 beta= 0.159281gamma= 0.799072 ?

标签: python convex-optimization


【解决方案1】:

编辑 0:我通过使用 Bounds 实例解决了这个问题。数组x 应该是您正在寻找的。这是答案。

      fun: 0.34189582276366093
 hess_inv: <3x3 LbfgsInvHessProduct with dtype=float64>
      jac: array([ 6.91014296e-01,  3.49720253e-07, -2.88657986e-07])
  message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
     nfev: 40
      nit: 8
   status: 0
  success: True
        x: array([0.        , 0.15928136, 0.79907217])

我在这方面做了一些工作。我遇到了一个错误,但我觉得我正在以正确的方式解决它。这是代码。

import numpy as np   
from scipy.optimize import Bounds,minimize

def cost_function(ini):

    x = np.array([0.4, -0.3, 0.9])
    y1 = np.array([0.3, 1, 0])
    y2 = np.array([1, -0.9, 0.5])
    y3 =np.array([0.6, 0.01, 0.8])

    L = np.linalg.norm(np.transpose(x) - np.dot(ini[0],y1) - np.dot(ini[1],y2) - np.dot(ini[2],y3))
    return L

ini = np.random.rand(3)
min_b= np.zeros(3)
max_b= np.ones(3)
bnds=Bounds(min_b,max_b)

print(minimize(cost_function,x0 =ini,bounds=bnds))

但是,尽管长度相等,但我收到了错误 ValueError: length of x0 != length of bounds。我找不到解决方案,也许你找到了。祝你好运!如果您找到解决方案以及是否可行,请告诉我!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多