mirror of
https://github.com/gonum/gonum.git
synced 2025-10-05 15:16:59 +08:00
blas,lapack: clean up docs and comments
Apply (with manual curation after the fact): * s/^T/U+1d40/g * s/^H/U+1d34/g * s/, {2,3}if / $1/g Some additional manual editing of odd formatting.
This commit is contained in:
@@ -157,10 +157,10 @@ func (b *BFGS) NextDirection(loc *Location, dir []float64) (stepSize float64) {
|
||||
// Update the inverse Hessian according to the formula
|
||||
//
|
||||
// B_{k+1}^-1 = B_k^-1
|
||||
// + (s_k^T y_k + y_k^T B_k^-1 y_k) / (s_k^T y_k)^2 * (s_k s_k^T)
|
||||
// - (B_k^-1 y_k s_k^T + s_k y_k^T B_k^-1) / (s_k^T y_k).
|
||||
// + (s_kᵀ y_k + y_kᵀ B_k^-1 y_k) / (s_kᵀ y_k)^2 * (s_k s_kᵀ)
|
||||
// - (B_k^-1 y_k s_kᵀ + s_k y_kᵀ B_k^-1) / (s_kᵀ y_k).
|
||||
//
|
||||
// Note that y_k^T B_k^-1 y_k is a scalar, and that the third term is a
|
||||
// Note that y_kᵀ B_k^-1 y_k is a scalar, and that the third term is a
|
||||
// rank-two update where B_k^-1 y_k is one vector and s_k is the other.
|
||||
yBy := mat.Inner(&b.y, b.invHess, &b.y)
|
||||
b.tmp.MulVec(b.invHess, &b.y)
|
||||
|
@@ -19,11 +19,11 @@ import (
|
||||
|
||||
// Convert converts a General-form LP into a standard form LP.
|
||||
// The general form of an LP is:
|
||||
// minimize c^T * x
|
||||
// minimize cᵀ * x
|
||||
// s.t G * x <= h
|
||||
// A * x = b
|
||||
// And the standard form is:
|
||||
// minimize cNew^T * x
|
||||
// minimize cNewᵀ * x
|
||||
// s.t aNew * x = bNew
|
||||
// x >= 0
|
||||
// If there are no constraints of the given type, the inputs may be nil.
|
||||
@@ -64,11 +64,11 @@ func Convert(c []float64, g mat.Matrix, h []float64, a mat.Matrix, b []float64)
|
||||
// Convert the general form LP.
|
||||
// Derivation:
|
||||
// 0. Start with general form
|
||||
// min. c^T * x
|
||||
// min. cᵀ * x
|
||||
// s.t. G * x <= h
|
||||
// A * x = b
|
||||
// 1. Introduce slack variables for each constraint
|
||||
// min. c^T * x
|
||||
// min. cᵀ * x
|
||||
// s.t. G * x + s = h
|
||||
// A * x = b
|
||||
// s >= 0
|
||||
@@ -77,7 +77,7 @@ func Convert(c []float64, g mat.Matrix, h []float64, a mat.Matrix, b []float64)
|
||||
// x = xp - xn
|
||||
// xp >= 0, xn >= 0
|
||||
// This makes the LP
|
||||
// min. c^T * xp - c^T xn
|
||||
// min. cᵀ * xp - cᵀ xn
|
||||
// s.t. G * xp - G * xn + s = h
|
||||
// A * xp - A * xn = b
|
||||
// xp >= 0, xn >= 0, s >= 0
|
||||
@@ -85,19 +85,19 @@ func Convert(c []float64, g mat.Matrix, h []float64, a mat.Matrix, b []float64)
|
||||
// xt = [xp
|
||||
// xn
|
||||
// s ]
|
||||
// min. [c^T, -c^T, 0] xt
|
||||
// min. [cᵀ, -cᵀ, 0] xt
|
||||
// s.t. [G, -G, I] xt = h
|
||||
// [A, -A, 0] xt = b
|
||||
// x >= 0
|
||||
|
||||
// In summary:
|
||||
// Original LP:
|
||||
// min. c^T * x
|
||||
// min. cᵀ * x
|
||||
// s.t. G * x <= h
|
||||
// A * x = b
|
||||
// Standard Form:
|
||||
// xt = [xp; xn; s]
|
||||
// min. [c^T, -c^T, 0] xt
|
||||
// min. [cᵀ, -cᵀ, 0] xt
|
||||
// s.t. [G, -G, I] xt = h
|
||||
// [A, -A, 0] xt = b
|
||||
// x >= 0
|
||||
|
@@ -59,7 +59,7 @@ const (
|
||||
|
||||
// Simplex solves a linear program in standard form using Danzig's Simplex
|
||||
// algorithm. The standard form of a linear program is:
|
||||
// minimize c^T x
|
||||
// minimize cᵀ x
|
||||
// s.t. A*x = b
|
||||
// x >= 0 .
|
||||
// The input tol sets how close to the optimal solution is found (specifically,
|
||||
@@ -209,7 +209,7 @@ func simplex(initialBasic []int, c []float64, A mat.Matrix, b []float64, tol flo
|
||||
// Algorithm:
|
||||
// 1) Compute the "reduced costs" for the non-basic variables. The reduced
|
||||
// costs are the lagrange multipliers of the constraints.
|
||||
// r = cn - an^T * ab^-T * cb
|
||||
// r = cn - anᵀ * ab¯ᵀ * cb
|
||||
// 2) If all of the reduced costs are positive, no improvement is possible,
|
||||
// and the solution is optimal (xn can only increase because of
|
||||
// non-negativity constraints). Otherwise, the solution can be improved and
|
||||
@@ -231,7 +231,7 @@ func simplex(initialBasic []int, c []float64, A mat.Matrix, b []float64, tol flo
|
||||
// the intersection of several constraints. Use the Bland rule instead
|
||||
// of the rule in step 4 to avoid cycling.
|
||||
for {
|
||||
// Compute reduced costs -- r = cn - an^T ab^-T cb
|
||||
// Compute reduced costs -- r = cn - anᵀ ab¯ᵀ cb
|
||||
var tmp mat.VecDense
|
||||
err = tmp.SolveVec(ab.T(), cbVec)
|
||||
if err != nil {
|
||||
|
@@ -207,14 +207,14 @@ func testSimplex(t *testing.T, initialBasic []int, c []float64, a mat.Matrix, b
|
||||
|
||||
// Construct and solve the dual LP.
|
||||
// Standard Form:
|
||||
// minimize c^T * x
|
||||
// minimize cᵀ * x
|
||||
// subject to A * x = b, x >= 0
|
||||
// The dual of this problem is
|
||||
// maximize -b^T * nu
|
||||
// subject to A^T * nu + c >= 0
|
||||
// maximize -bᵀ * nu
|
||||
// subject to Aᵀ * nu + c >= 0
|
||||
// Which is
|
||||
// minimize b^T * nu
|
||||
// subject to -A^T * nu <= c
|
||||
// minimize bᵀ * nu
|
||||
// subject to -Aᵀ * nu <= c
|
||||
|
||||
negAT := &mat.Dense{}
|
||||
negAT.CloneFrom(a.T())
|
||||
@@ -238,7 +238,7 @@ func testSimplex(t *testing.T, initialBasic []int, c []float64, a mat.Matrix, b
|
||||
|
||||
// If the primal problem is feasible, then the primal and the dual should
|
||||
// be the same answer. We have flopped the sign in the dual (minimizing
|
||||
// b^T *nu instead of maximizing -b^T*nu), so flip it back.
|
||||
// bᵀ * nu instead of maximizing -bᵀ * nu), so flip it back.
|
||||
if errPrimal == nil {
|
||||
if errDual != nil {
|
||||
t.Errorf("Primal feasible but dual errored: %s", errDual)
|
||||
|
Reference in New Issue
Block a user