@@ -359,27 +359,6 @@ struct NewtonState {
359359 */
360360 bool final_loop = false ;
361361
362- /* *
363- * @brief Constructs Newton state with given dimensions and functors.
364- *
365- * @tparam ThetaInitializer Type of the initial theta provider
366- * @param theta_size Dimension of the latent space
367- * @param obj_fun Objective function: (a, theta) -> double
368- * @param theta_grad_f Gradient function: theta -> grad
369- * @param theta_init Initial theta value or provider
370- */
371- template <typename ObjFun, typename ThetaGradFun, typename ThetaInitializer>
372- NewtonState (int theta_size, ObjFun&& obj_fun, ThetaGradFun&& theta_grad_f,
373- ThetaInitializer&& theta_init)
374- : wolfe_info(std::forward<ObjFun>(obj_fun), theta_size,
375- std::forward<ThetaInitializer>(theta_init),
376- std::forward<ThetaGradFun>(theta_grad_f)),
377- b (theta_size),
378- B(theta_size, theta_size),
379- prev_g(theta_size) {
380- wolfe_status.num_backtracks_ = -1 ; // Safe initial value for BB step
381- }
382-
383362 /* *
384363 * @brief Constructs Newton state with a consistent (a_init, theta_init) pair.
385364 *
@@ -392,12 +371,12 @@ struct NewtonState {
392371 * @param a_init Initial a value consistent with theta_init
393372 * @param theta_init Initial theta value
394373 */
395- template <typename ObjFun, typename ThetaGradFun, typename ThetaInitializer>
374+ template <typename ObjFun, typename ThetaGradFun, typename CovarianceT, typename ThetaInitializer>
396375 NewtonState (int theta_size, ObjFun&& obj_fun, ThetaGradFun&& theta_grad_f,
397- const Eigen::VectorXd& a_init , ThetaInitializer&& theta_init)
398- : wolfe_info(std::forward<ObjFun>(obj_fun), a_init ,
376+ CovarianceT&& covariance , ThetaInitializer&& theta_init)
377+ : wolfe_info(std::forward<ObjFun>(obj_fun), covariance.llt().solve(theta_init) ,
399378 std::forward<ThetaInitializer>(theta_init),
400- std::forward<ThetaGradFun>(theta_grad_f), 0 ),
379+ std::forward<ThetaGradFun>(theta_grad_f)),
401380 b (theta_size),
402381 B(theta_size, theta_size),
403382 prev_g(theta_size) {
@@ -1213,16 +1192,7 @@ inline auto laplace_marginal_density_est(
12131192 // the prior term -0.5 * a'*theta vanishes (a=0 while theta!=0), inflating
12141193 // the initial objective and causing the Wolfe line search to reject the
12151194 // first Newton step.
1216- auto make_state = [&](auto && theta_0) {
1217- if constexpr (InitTheta) {
1218- Eigen::VectorXd a_init = covariance.llt ().solve (Eigen::VectorXd (theta_0));
1219- return internal::NewtonState (theta_size, obj_fun, theta_grad_f, a_init,
1220- theta_0);
1221- } else {
1222- return internal::NewtonState (theta_size, obj_fun, theta_grad_f, theta_0);
1223- }
1224- };
1225- auto state = make_state (theta_init);
1195+ auto state = NewtonState (theta_size, obj_fun, theta_grad_f, covariance, theta_init);
12261196 // Start with safe step size
12271197 auto update_fun = create_update_fun (
12281198 std::move (obj_fun), std::move (theta_grad_f), covariance, options);
0 commit comments