318 const ContainerType1& copyable,
319 double tol = 1e-8,
unsigned max_iter = 1000)
321 unsigned num_p = x0.size();
322 auto x1 = x0, W = x0;
323 auto rs(copyable), rs1(rs);
324 std::vector<ContainerType1> jacs(num_p, copyable);
326 thrust::host_vector<double> evs( num_p), grad(num_p), gradbar(num_p),
327 pk(num_p), pkbar(num_p);
328 thrust::host_vector<double> work( 3*num_p-1);
333 for(
unsigned p=0; p<num_p; p++)
337 for(
unsigned p=0; p<num_p; p++)
340 delta += grad[p]*grad[p]/W[p];
344 delta = 0.25*f0/sqrt(delta);
347 for (
unsigned k=0; k<max_iter; k++)
352 for(
unsigned l=0; l<num_p; l++)
354 for(
unsigned j=l; j<num_p; j++)
356 WW(l,l) = std::max( WW(l,l), HH(l,l));
360 lapack::sygv( 1,
'V',
'U', num_p, HH.data(), num_p, syWW.
data(), num_p, evs, work);
362 evHH = HH.transpose();
372 auto target = [&](
double lambda)
375 for(
unsigned p=0; p<num_p; p++)
376 pkbar[p]= -gradbar[p]/(evs[p] +lambda == 0 ? 1e-16 : evs[p]+lambda);
378 return 1./delta - 1./normp;
380 auto dtarget = [&](
double lambda)
384 for(
unsigned p=0; p<num_p; p++)
385 dnorm += pkbar[p]*pkbar[p]/(evs[p]+lambda == 0 ? 1e-16 : evs[p]+lambda);
386 return - dnorm/normp/normp/normp;
389 const double sigma = 1e-4;
390 const unsigned max_newton = 100;
391 double phi = target(lambda);
394 for(
unsigned i=0; i<max_newton; i++)
397 if ( fabs(phi) <= sigma/normp || i == max_newton-1)
400 lambda += - phi/dtarget(lambda);
401 phi = target(lambda);
436 double rhok = (1.-f1/f0)/( jp/f0 + 2*lambda*normp*normp/f0);
446 if( rhok > 0.75 && lambda > 0)
450 const double eta = 1e-4;
460 for(
unsigned l=0; l<num_p; l++)
void gemv(get_value_type< ContainerType1 > alpha, MatrixType &&M, const ContainerType1 &x, get_value_type< ContainerType1 > beta, ContainerType2 &y)
unsigned levenberg_marquardt(Func fun, Jacobian jac, ContainerType0 &x0, const ContainerType1 ©able, double tol=1e-8, unsigned max_iter=1000)
The Levenberg Marquardt algorithm.
Definition optimise.h:316
unsigned newton(Gradient grad, InvHessian invhess, ContainerType &x0, double tol=1e-5, unsigned max_iter=1000)
Newton iteration.
Definition optimise.h:81