Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve quadprog #1896

Closed
wants to merge 14 commits into from
Prev Previous commit
Smaller epsilon value
  • Loading branch information
spinkney committed May 19, 2020
commit 78c33987dc5022337bb4e2dfeb44cb50d3189325
24 changes: 8 additions & 16 deletions stan/math/rev/fun/solve_quadprog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@ solve_quadprog(const Eigen::Matrix<T0, -1, -1> &G,
/* compute the inverse of the factorized matrix G^-1, this is the initial
* value for H */
//J = L^-T
Eigen::Matrix<T0, -1, -1> Li = (1e-9 < L.array().abs()).select(L, 0.0f);
auto J = stan::math::transpose(stan::math::mdivide_left_tri_low(Li));
Eigen::Matrix<T0, -1, -1> Li = (1e-14 < L.array().abs()).select(L, 0.0f);
auto J = stan::math::mdivide_left_tri_low(Li);
J.transposeInPlace();
auto c2 = J.trace();
#ifdef TRACE_SOLVER
print_matrix("J", J, n);
Expand Down Expand Up @@ -629,18 +630,8 @@ auto
*/

/* compute the trace of the original matrix G */
/* can remove this auto chol = L;
* can provide the trace already so don't need
* to compute G again
* auto G = tcrossprod(L);
* auto c1 = G.trace(); */

/* tr(AB^T) = sum( A hadamard_prod B)
* https://en.wikipedia.org/wiki/Trace_(linear_algebra)
*/
// auto c1 = elt_multiply(L, L).sum();
auto c1 = tcrossprod(L).trace();
/* initialize the matrix R */
/* initialize the matrix R */
d.setZero();

/* compute the trace of the original matrix G */
Expand All @@ -655,8 +646,9 @@ auto
/* **CHANGE HERE**
* J is only called once and trace is the same regardless of transpose
* also change chol to L */
Eigen::Matrix<T0, -1, -1> Li = (1e-9 < L.array().abs()).select(L, 0.0f);
auto J = stan::math::transpose(stan::math::mdivide_left_tri_low(Li));
Eigen::Matrix<T0, -1, -1> Li = (1e-14 < L.array().abs()).select(L, 0.0f);
auto J = stan::math::mdivide_left_tri_low(Li);
J.transposeInPlace();
auto c2 = J.trace();
// std::cout << c2 << "\n";
#ifdef TRACE_SOLVER
Expand Down Expand Up @@ -936,4 +928,4 @@ auto
}
}
}
#endif
#endif