33#ifndef MADNESS_LINALG_SOLVERS_H__INCLUDED
34#define MADNESS_LINALG_SOLVERS_H__INCLUDED
99 const int nvec =
Q.
dim(0);
100 const int m = nvec-1;
110 for (
long i=0; i<
m; ++i) {
112 for (
long j=0; j<
m; ++j) {
113 A(i,j) =
Q(i,j) -
Q(
m,j) -
Q(i,
m) +
Q(
m,
m);
127 gelss(
A,
b, rcond, x, s, rank, sumsq);
134 for (
long i=0; i<
m; ++i) sumC += x(i);
159 throw "not implemented";
185 throw "not implemented";
219 std::shared_ptr<OptimizationTargetInterface>
target;
225 SteepestDescent(
const std::shared_ptr<OptimizationTargetInterface>& tar,
227 double value_precision = 1
e-12,
228 double gradient_precision = 1
e-12);
236 double value()
const;
249 std::shared_ptr<OptimizationTargetInterface>
target;
263 static double line_search(
double a1,
double f0,
double dxgrad,
265 std::shared_ptr<OptimizationTargetInterface>
target,
279 QuasiNewton(
const std::shared_ptr<OptimizationTargetInterface>& tar,
289 void set_test(
const bool& test_level);
304 double value()
const;
Definition test_ar.cc:118
long dim(int i) const
Returns the size of dimension i.
Definition basetensor.h:147
Optimization via quasi-Newton (BFGS or SR1 update)
Definition solvers.h:246
const double gradient_precision
Definition solvers.h:253
void reset_hessian()
Resets Hessian to default guess.
Definition solvers.h:307
bool converged() const
After running the optimizer returns true if converged.
Definition solvers.cc:334
const double value_precision
Definition solvers.h:252
void set_update(const std::string &method)
Choose update method (currently only "BFGS" or "SR1")
Definition solvers.cc:269
virtual ~QuasiNewton()
Definition solvers.h:317
static double line_search(double a1, double f0, double dxgrad, const Tensor< double > &x, const Tensor< double > &dx, std::shared_ptr< OptimizationTargetInterface > target, double value_precision)
make this static for other QN classed to have access to it
Definition solvers.cc:113
static void hessian_update_bfgs(const Tensor< double > &dx, const Tensor< double > &dg, Tensor< double > &hessian)
make this static for other QN classed to have access to it
Definition solvers.cc:179
std::shared_ptr< OptimizationTargetInterface > target
Definition solvers.h:249
bool optimize(Tensor< double > &x)
Runs the optimizer.
Definition solvers.cc:278
std::string update
Definition solvers.h:248
bool printtest
Definition solvers.h:258
const double tol
Definition solvers.h:251
void set_test(const bool &test_level)
Choose update method (currently only "BFGS" or "SR1")
Definition solvers.cc:274
void set_hessian(const Tensor< double > &matrix)
Sets Hessian to given matrix.
Definition solvers.h:310
double gnorm
Definition solvers.h:255
double f
Definition solvers.h:254
const int maxiter
Definition solvers.h:250
int n
Definition solvers.h:257
Tensor< double > new_search_direction(const Tensor< double > &g) const
Definition solvers.cc:210
static void hessian_update_sr1(const Tensor< double > &s, const Tensor< double > &y, Tensor< double > &hessian)
make this static for other QN classed to have access to it
Definition solvers.cc:166
Tensor< double > h
Definition solvers.h:256
double value() const
Value of objective function.
Definition solvers.cc:336
double gradient_norm() const
Value of gradient norm.
Definition solvers.cc:338
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
Unconstrained minimization via steepest descent.
Definition solvers.h:218
double value() const
Definition solvers.cc:111
double f
Definition solvers.h:221
double gnorm
Definition solvers.h:222
bool converged() const
Definition solvers.cc:107
virtual ~SteepestDescent()
Definition solvers.h:238
const double tol
Definition solvers.h:220
std::shared_ptr< OptimizationTargetInterface > target
Definition solvers.h:219
double gradient_norm() const
Definition solvers.cc:109
bool optimize(Tensor< double > &x)
Definition solvers.cc:79
A tensor is a multidimension array.
Definition tensor.h:317
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
Tensor< T > KAIN(const Tensor< T > &Q, double rcond=1e-12)
Solves non-linear equation using KAIN (returns coefficients to compute next vector)
Definition solvers.h:98
void gelss(const Tensor< T > &a, const Tensor< T > &b, double rcond, Tensor< T > &x, Tensor< typename Tensor< T >::scalar_type > &s, long &rank, Tensor< typename Tensor< T >::scalar_type > &sumsq)
Solve Ax = b for general A using the LAPACK *gelss routines.
Definition lapack.cc:884
NDIM const Function< R, NDIM > & g
Definition mra.h:2416
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition mra.h:2002
static const double b
Definition nonlinschro.cc:119
Defines simple templates for printing to std::cout "a la Python".
double Q(double a)
Definition relops.cc:20
static const double c
Definition relops.cc:10
static const double m
Definition relops.cc:9
static const double L
Definition rk.cc:46
The interface to be provided by functions to be optimized.
Definition solvers.h:176
virtual void value_and_gradient(const Tensor< double > &x, double &value, Tensor< double > &gradient)
Reimplement if more efficient to evaluate both value and gradient in one call.
Definition solvers.h:189
virtual ~OptimizationTargetInterface()
Definition solvers.h:199
virtual Tensor< double > gradient(const Tensor< double > &x)
Should return the derivative of the function.
Definition solvers.h:184
virtual double value(const Tensor< double > &x)=0
Should return the value of the objective function.
double test_gradient(Tensor< double > &x, double value_precision, bool doprint=true)
Numerical test of the derivative ... optionally prints to stdout, returns max abs error.
Definition solvers.cc:38
virtual bool provides_gradient() const
Override this to return true if the derivative is implemented.
Definition solvers.h:181
The interface to be provided by optimizers.
Definition solvers.h:206
virtual bool optimize(Tensor< double > &x)=0
virtual double gradient_norm() const =0
virtual ~OptimizerInterface()
Definition solvers.h:211
virtual double value() const =0
virtual bool converged() const =0
The interface to be provided by targets for non-linear equation solver.
Definition solvers.h:148
virtual void residual_and_jacobian(const Tensor< double > &x, Tensor< double > &residual, Tensor< double > &jacobian)
Implement this if advantageous to compute residual and jacobian simultaneously.
Definition solvers.h:163
virtual ~SolverTargetInterface()
Definition solvers.h:169
virtual Tensor< double > jacobian(const Tensor< double > &x)
Some solvers require the jacobian or are faster if an analytic form is available.
Definition solvers.h:158
virtual Tensor< double > residual(const Tensor< double > &x)=0
Should return the resdiual (vector F(x))
virtual bool provides_jacobian() const
Override this to return true if the Jacobian is implemented.
Definition solvers.h:153
Defines and implements most of Tensor.
Prototypes for a partial interface from Tensor to LAPACK.
void e()
Definition test_sig.cc:75
const double a1
Definition vnucso.cc:85