二次最小化器总是 returns 一个荒谬的答案

QuadraticMinimizer always returns a non-sensical answer

我在使用 QuadraticMinimizer 时遇到了问题 - 每次执行它时,我都会收到一些无意义的错误。我查看了 scaladoc 和代码,但不确定自己做错了什么。

我有以下代码:

    val lBounds:DenseVector[Double] = DenseVector(Array(Double.NegativeInfinity, 5.0, 0.1, 50.0, 50.0))
  val uBounds:DenseVector[Double] = DenseVector(Array(Double.PositiveInfinity, 500.0, 100.0, 99000.0, 99000.0))

  val inputMatrix:DenseMatrix[Double] = breeze.linalg.csvread(file=new java.io.File(getClass.getResource("/input/zip06latlong.csv").toURI), skipLines=1)

  val y = inputMatrix(::, 0).toDenseVector
  val X = inputMatrix(::, Seq(1,2,3,4,5)).copy.toDenseMatrix
  val T = X.toDenseMatrix.t

  val gram = (T * X)
  val b:Transpose[DenseVector[Double]] = y.t * X

  println(gram)
  println(b.inner)
  breeze.linalg.csvwrite(new java.io.File("grammatrix.csv"), gram)
  val minimizer:QuadraticMinimizer = new QuadraticMinimizer(rank(gram), ProjectBox(lBounds,uBounds))


  val coeffs =  minimizer.minimize(gram, b.inner)
  println(coeffs)

这是克的样子:

    279.0      628207.0       1461245.0        1024.0     729.5      
628207.0   1.569309427E9  3.414471724E9    2449533.0  1755536.5  
1461245.0  3.414471724E9  1.2324155401E10  5511816.0  3846583.0  
1024.0     2449533.0      5511816.0        3980.0     2786.0     
729.5      1755536.5      3846583.0        2786.0     2092.75

b 向量是:

2.917264069193999E8, 7.294450468242601E11, 1.585917338779061E12, 1.131888709844E9, 8.260072757806E8

当我执行我得到的代码时:

DenseVector(-12171.118011368422, -424.79971124882286, -9.565028484748783, 49.3827769217138, 49.536905925364195)

低于指定的下限。

能否请您也添加 H(克矩阵)和 y(线性项)以便我进行测试?此外,初始化模式适用于高级用户(例如我为其编写求解器的 Spark ALS),但您可以使用如下简单模式(我使用了您的边界):

val lb = DenseVector(Array(Double.NegativeInfinity, 5.0, 0.1, 50.0, 50.0))
val ub = DenseVector(Array(Double.PositiveInfinity, 500.0, 100.0, 99000.0, 99000.0))

val n = 5

val ata = new DenseMatrix[Double](5, 5,
  Array(4.377, -3.531, -1.306, -0.139, 3.418,
    -3.531, 4.344, 0.934, 0.305, -2.140,
    -1.306, 0.934, 2.644, -0.203, -0.170,
    -0.139, 0.305, -0.203, 5.883, 1.428,
    3.418, -2.140, -0.170, 1.428, 4.684))

val atb = DenseVector(-1.632, 2.115, 1.094, -1.025, -0.636)

val qpSolverBounds = new QuadraticMinimizer(n, ProjectBox(lb, ub))
val result = qpSolverBounds.minimize(ata, atb)
println(s"Bounds test $result")

我得到的结果是 DenseVector(-33.02749751949581, 5.0, 0.1, 50.0, 50.0),这看起来很合理。

请不要更改默认的 maxIter,因为此控制是为不需要绝对收敛的流提供的。让求解器选择 maxIter。