See Algorithm 7.4 (L-BFGS two-loop recursion). @param x_grad the initial value ∇ f k @param rho @param s @param y @param q the location to store the value of H k ∇ f k @param alphas temp space to do work, should be as large as the number of history vectors
(Vec x_grad, List<Double> rho, List<Vec> s, List<Vec> y, Vec q, double[] alphas)
| 66 | * @param alphas temp space to do work, should be as large as the number of history vectors |
| 67 | */ |
| 68 | public static void twoLoopHp(Vec x_grad, List<Double> rho, List<Vec> s, List<Vec> y, Vec q, double[] alphas) |
| 69 | { |
| 70 | //q ← ∇ fk; |
| 71 | x_grad.copyTo(q); |
| 72 | if(s.isEmpty()) |
| 73 | return;//identity, we are done |
| 74 | //for i = k−1,k−2,...,k−m |
| 75 | for(int i = 0; i < s.size(); i++) |
| 76 | { |
| 77 | Vec s_i = s.get(i); |
| 78 | Vec y_i = y.get(i); |
| 79 | double alpha_i = alphas[i] = rho.get(i)*s_i.dot(q); |
| 80 | q.mutableSubtract(alpha_i, y_i); |
| 81 | } |
| 82 | |
| 83 | //r ← Hk0q; and see eq (7.20), done in place in q |
| 84 | q.mutableMultiply(s.get(0).dot(y.get(0))/y.get(0).dot(y.get(0))); |
| 85 | //for i = k−m,k−m+1,...,k−1 |
| 86 | for(int i = s.size()-1; i >= 0; i--) |
| 87 | { |
| 88 | //β ← ρ_i y_i^T r ; |
| 89 | double beta = rho.get(i)*y.get(i).dot(q); |
| 90 | //r ← r + si (αi − β) |
| 91 | q.mutableAdd(alphas[i]-beta, s.get(i)); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public void optimize(double tolerance, Vec w, Vec x0, Function f, FunctionVec fp, FunctionVec fpp) |
no test coverage detected