我在使用 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)
低于指定的下限。