33 #ifndef MADNESS_LINALG_SOLVERS_H__INCLUDED
34 #define MADNESS_LINALG_SOLVERS_H__INCLUDED
98 Tensor<T>
KAIN(
const Tensor<T>& Q,
double rcond=1e-12) {
99 const int nvec = Q.dim(0);
100 const int m = nvec-1;
110 for (
long i=0; i<
m; ++i) {
111 b(i) = Q(m,m) - Q(i,m);
112 for (
long j=0; j<
m; ++j) {
113 A(i,j) = Q(i,j) - Q(m,j) - Q(i,m) + Q(m,m);
125 Tensor<double> s, sumsq;
127 gelss(A, b, rcond, x, s, rank, sumsq);
134 for (
long i=0; i<
m; ++i) sumC += x(i);
150 virtual Tensor<double>
residual(
const Tensor<double>& x) = 0;
158 virtual Tensor<double>
jacobian(
const Tensor<double>& x) {
159 throw "not implemented";
178 virtual double value(
const Tensor<double>& x) = 0;
184 virtual Tensor<double>
gradient(
const Tensor<double>& x) {
185 throw "not implemented";
192 value = this->
value(x);
197 double test_gradient(Tensor<double>& x,
double value_precision,
bool doprint=
true);
207 virtual bool solve(Tensor<double>& x) = 0;
217 virtual bool optimize(Tensor<double>& x) = 0;
219 virtual double value()
const = 0;
231 const double value_precision;
232 const double gradient_precision;
239 double value_precision = 1e-12,
240 double gradient_precision = 1e-12);
248 double value()
const;
264 const double value_precision;
265 const double gradient_precision;
272 double line_search(
double a1,
double f0,
double dxgrad,
const Tensor<double>& x,
const Tensor<double>& dx);
274 void hessian_update_sr1(
const Tensor<double>& s,
const Tensor<double>& y);
276 void hessian_update_bfgs(
const Tensor<double>& dx,
277 const Tensor<double>& dg);
279 Tensor<double> new_search_direction(
const Tensor<double>&
g);
285 double value_precision = 1e-12,
286 double gradient_precision = 1e-12);
292 void set_test(
const bool& test_level);
307 double value()
const;
324 #endif // MADNESS_LINALG_SOLVERS_H__INCLUDED
virtual Tensor< double > residual(const Tensor< double > &x)=0
Should return the resdiual (vector F(x))
NDIM const Function< R, NDIM > & g
Definition: mra.h:2179
virtual ~SteepestDescent()
Definition: solvers.h:250
void set_hessian(const Tensor< double > &matrix)
Sets Hessian to given matrix.
Definition: solvers.h:313
virtual bool converged() const =0
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:393
const double L
Definition: 3dharmonic.cc:123
::std::string string
Definition: gtest-port.h:872
virtual double value() const =0
virtual bool converged() const =0
double gradient_norm() const
Definition: solvers.cc:110
The interface to be provided by optimizers.
Definition: solvers.h:216
QuasiNewton(const std::shared_ptr< OptimizationTargetInterface > &tar, int maxiter=20, double tol=1e-6, double value_precision=1e-12, double gradient_precision=1e-12)
Definition: solvers.cc:247
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
double value() const
Definition: solvers.cc:112
Unconstrained minimization via steepest descent.
Definition: solvers.h:228
bool optimize(Tensor< double > &x)
Runs the optimizer.
Definition: solvers.cc:274
void reset_hessian()
Resets Hessian to default guess.
Definition: solvers.h:310
virtual ~SolverInterface()
Definition: solvers.h:210
Defines and implements most of Tensor.
virtual double residual_norm() const =0
virtual ~OptimizerInterface()
Definition: solvers.h:221
Optimization via quasi-Newton (BFGS or SR1 update)
Definition: solvers.h:258
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
The interface to be provided by functions to be optimized.
Definition: solvers.h:176
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:1835
Prototypes for a partial interface from Tensor to LAPACK.
double gradient_norm() const
Value of gradient norm.
Definition: solvers.cc:329
virtual ~SolverTargetInterface()
Definition: solvers.h:169
virtual ~QuasiNewton()
Definition: solvers.h:320
virtual bool provides_gradient() const
Override this to return true if the derivative is implemented.
Definition: solvers.h:181
bool converged() const
Definition: solvers.cc:108
virtual Tensor< double > gradient(const Tensor< double > &x)
Should return the derivative of the function.
Definition: solvers.h:184
void set_test(const bool &test_level)
Choose update method (currently only "BFGS" or "SR1")
Definition: solvers.cc:269
bool optimize(Tensor< double > &x)
Definition: solvers.cc:80
The interface to be provided by targets for non-linear equation solver.
Definition: solvers.h:148
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
void set_update(const std::string &method)
Choose update method (currently only "BFGS" or "SR1")
Definition: solvers.cc:265
const double m
Definition: gfit.cc:199
virtual bool provides_jacobian() const
Override this to return true if the Jacobian is implemented.
Definition: solvers.h:153
Defines simple templates for printing to std::cout "a la Python".
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
const double a1
Definition: vnucso.cc:90
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 ~OptimizationTargetInterface()
Definition: solvers.h:199
virtual bool solve(Tensor< double > &x)=0
virtual double gradient_norm() const =0
double value() const
Value of objective function.
Definition: solvers.cc:327
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
SteepestDescent(const std::shared_ptr< OptimizationTargetInterface > &tar, double tol=1e-6, double value_precision=1e-12, double gradient_precision=1e-12)
Definition: solvers.cc:67
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const double c
Definition: gfit.cc:200
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
The interface to be provided by solvers ... NOT USED ANYWHERE?
Definition: solvers.h:206
virtual double value(const Tensor< double > &x)=0
Should return the value of the objective function.
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
virtual bool optimize(Tensor< double > &x)=0
bool converged() const
After running the optimizer returns true if converged.
Definition: solvers.cc:325