From eb1333d0a8942168d6c0a1e99a873dfc55237f37 Mon Sep 17 00:00:00 2001 From: Alex Leontiev Date: Fri, 20 Sep 2013 15:12:48 +0800 Subject: [PATCH 1/5] Initial commit for Conjugate Gradient method Implementation is based on http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf So far we only have basic interface and empty test. But it compiles at least. --- modules/optim/doc/optim.rst | 1 + modules/optim/include/opencv2/optim.hpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/optim/doc/optim.rst b/modules/optim/doc/optim.rst index b3c7a740b..dfa4b65df 100644 --- a/modules/optim/doc/optim.rst +++ b/modules/optim/doc/optim.rst @@ -10,3 +10,4 @@ optim. Generic numerical optimization linear_programming downhill_simplex_method primal_dual_algorithm + conjugate_gradient diff --git a/modules/optim/include/opencv2/optim.hpp b/modules/optim/include/opencv2/optim.hpp index 715372b69..c1e7819b6 100644 --- a/modules/optim/include/opencv2/optim.hpp +++ b/modules/optim/include/opencv2/optim.hpp @@ -54,7 +54,6 @@ public: { public: virtual ~Function() {} - //! ndim - dimensionality virtual double calc(const double* x) const = 0; }; @@ -86,6 +85,23 @@ CV_EXPORTS_W Ptr createDownhillSolver(const Ptr(1,1,0.0), TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)); +//! conjugate gradient method +class CV_EXPORTS ConjGradSolver : public Solver +{ +public: + class CV_EXPORTS Function : public Solver::Function + { + public: + //! gradient is like the first derivative for multivar function + virtual void getGradient(const double* x,double* buf)const=0; + //! Jacobian is like the second derivative + virtual void getJacobian(const double* x)const=0; + }; +}; + +CV_EXPORTS_W Ptr createConjGradSolver(const Ptr& f=Ptr(), + TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)); + //!the return codes for solveLP() function enum { From 581d4545366b4f9392352af8737cba73b8a9dc5a Mon Sep 17 00:00:00 2001 From: Alex Leontiev Date: Sun, 22 Sep 2013 00:14:49 +0800 Subject: [PATCH 2/5] Refined interface for Conjugate Gradient Some interface was refined (most notably, the method for returning Hessian was removed and the method for getting gradient was added as optional to base Solver::Function class) and basic code for setters/getters was added. Now is the time for the real work on an algorithm. --- modules/optim/doc/conjugate_gradient.rst | 11 +++ modules/optim/include/opencv2/optim.hpp | 13 +--- modules/optim/src/conjugate_gradient.cpp | 77 +++++++++++++++++++ modules/optim/src/simplex.cpp | 7 +- .../optim/test/test_conjugate_gradient.cpp | 61 +++++++++++++++ 5 files changed, 157 insertions(+), 12 deletions(-) create mode 100644 modules/optim/doc/conjugate_gradient.rst create mode 100644 modules/optim/src/conjugate_gradient.cpp create mode 100644 modules/optim/test/test_conjugate_gradient.cpp diff --git a/modules/optim/doc/conjugate_gradient.rst b/modules/optim/doc/conjugate_gradient.rst new file mode 100644 index 000000000..cd9697465 --- /dev/null +++ b/modules/optim/doc/conjugate_gradient.rst @@ -0,0 +1,11 @@ +Conjugate Gradient +======================= + +.. highlight:: cpp + +optim::ConjGradSolver +--------------------------------- + +.. ocv:class:: optim::ConjGradSolver + +This class is used diff --git a/modules/optim/include/opencv2/optim.hpp b/modules/optim/include/opencv2/optim.hpp index c1e7819b6..0a460cce0 100644 --- a/modules/optim/include/opencv2/optim.hpp +++ b/modules/optim/include/opencv2/optim.hpp @@ -55,6 +55,7 @@ public: public: virtual ~Function() {} virtual double calc(const double* x) const = 0; + virtual void getGradient(const double* /*x*/,double* /*grad*/) {} }; virtual Ptr getFunction() const = 0; @@ -86,17 +87,7 @@ CV_EXPORTS_W Ptr createDownhillSolver(const Ptr createConjGradSolver(const Ptr& f=Ptr(), diff --git a/modules/optim/src/conjugate_gradient.cpp b/modules/optim/src/conjugate_gradient.cpp new file mode 100644 index 000000000..7e555c6cc --- /dev/null +++ b/modules/optim/src/conjugate_gradient.cpp @@ -0,0 +1,77 @@ +#include "precomp.hpp" +#include "debug.hpp" + +namespace cv{namespace optim{ + + class ConjGradSolverImpl : public ConjGradSolver + { + public: + Ptr getFunction() const; + void setFunction(const Ptr& f); + TermCriteria getTermCriteria() const; + ConjGradSolverImpl(); + void setTermCriteria(const TermCriteria& termcrit); + double minimize(InputOutputArray x); + protected: + Ptr _Function; + TermCriteria _termcrit; + Mat_ d,r,buf_x,r_old; + private: + }; + + double ConjGradSolverImpl::minimize(InputOutputArray x){ + CV_Assert(_Function.empty()==false); + dprintf(("termcrit:\n\ttype: %d\n\tmaxCount: %d\n\tEPS: %g\n",_termcrit.type,_termcrit.maxCount,_termcrit.epsilon)); + + Mat x_mat=x.getMat(); + CV_Assert(MIN(x_mat.rows,x_mat.cols)==1); + int ndim=MAX(x_mat.rows,x_mat.cols); + CV_Assert(x_mat.type()==CV_64FC1); + + d.create(1,ndim); + r.create(1,ndim); + r_old.create(1,ndim); + + Mat_ proxy_x; + if(x_mat.rows>1){ + buf_x.create(1,ndim); + Mat_ proxy(ndim,1,(double*)buf_x.data); + x_mat.copyTo(proxy); + proxy_x=buf_x; + }else{ + proxy_x=x_mat; + } + + //here everything goes. check that everything is setted properly + + if(x_mat.rows>1){ + Mat(ndim, 1, CV_64F, (double*)proxy_x.data).copyTo(x); + } + return 0.0; + } + ConjGradSolverImpl::ConjGradSolverImpl(){ + _Function=Ptr(); + } + Ptr ConjGradSolverImpl::getFunction()const{ + return _Function; + } + void ConjGradSolverImpl::setFunction(const Ptr& f){ + _Function=f; + } + TermCriteria ConjGradSolverImpl::getTermCriteria()const{ + return _termcrit; + } + void ConjGradSolverImpl::setTermCriteria(const TermCriteria& termcrit){ + CV_Assert((termcrit.type==(TermCriteria::MAX_ITER+TermCriteria::EPS) && termcrit.epsilon>0 && termcrit.maxCount>0) || + ((termcrit.type==TermCriteria::MAX_ITER) && termcrit.maxCount>0)); + _termcrit=termcrit; + } + // both minRange & minError are specified by termcrit.epsilon; In addition, user may specify the number of iterations that the algorithm does. + Ptr createConjGradSolver(const Ptr& f, TermCriteria termcrit){ + ConjGradSolver *CG=new ConjGradSolverImpl(); + CG->setFunction(f); + CG->setTermCriteria(termcrit); + return Ptr(CG); + } +}} + diff --git a/modules/optim/src/simplex.cpp b/modules/optim/src/simplex.cpp index f45d0ce0b..54de6ed8c 100644 --- a/modules/optim/src/simplex.cpp +++ b/modules/optim/src/simplex.cpp @@ -19,6 +19,8 @@ namespace cv{namespace optim{ Ptr _Function; TermCriteria _termcrit; Mat _step; + Mat_ buf_x; + private: inline void createInitialSimplex(Mat_& simplex,Mat& step); inline double innerDownhillSimplex(cv::Mat_& p,double MinRange,double MinError,int& nfunk, @@ -209,7 +211,10 @@ namespace cv{namespace optim{ Mat_ proxy_x; if(x_mat.rows>1){ - proxy_x=x_mat.t(); + buf_x.create(1,_step.cols); + Mat_ proxy(_step.cols,1,(double*)buf_x.data); + x_mat.copyTo(proxy); + proxy_x=buf_x; }else{ proxy_x=x_mat; } diff --git a/modules/optim/test/test_conjugate_gradient.cpp b/modules/optim/test/test_conjugate_gradient.cpp new file mode 100644 index 000000000..2456a5cab --- /dev/null +++ b/modules/optim/test/test_conjugate_gradient.cpp @@ -0,0 +1,61 @@ +#include "test_precomp.hpp" +#include + +static void mytest(cv::Ptr solver,cv::Ptr ptr_F,cv::Mat& x, + cv::Mat& etalon_x,double etalon_res){ + solver->setFunction(ptr_F); + //int ndim=MAX(step.cols,step.rows); + double res=solver->minimize(x); + std::cout<<"res:\n\t"<getTermCriteria().epsilon; + ASSERT_TRUE(std::abs(res-etalon_res)::iterator it1=x.begin(),it2=etalon_x.begin();it1!=x.end();it1++,it2++){ + ASSERT_TRUE(std::abs((*it1)-(*it2)) solver=cv::optim::createConjGradSolver(); +#if 1 + { + cv::Ptr ptr_F(new SphereF()); + cv::Mat x=(cv::Mat_(1,2)<<1.0,1.0), + etalon_x=(cv::Mat_(1,2)<<0.0,0.0); + double etalon_res=0.0; + return; + mytest(solver,ptr_F,x,etalon_x,etalon_res); + } +#endif +#if 0 + { + cv::Ptr ptr_F(new RosenbrockF()); + cv::Mat x=(cv::Mat_(2,1)<<0.0,0.0), + step=(cv::Mat_(2,1)<<0.5,+0.5), + etalon_x=(cv::Mat_(2,1)<<1.0,1.0); + double etalon_res=0.0; + mytest(solver,ptr_F,x,step,etalon_x,etalon_res); + } +#endif +} From 891bcd8491ba3f35c2a64459cf73272826a04255 Mon Sep 17 00:00:00 2001 From: Alex Leontiev Date: Tue, 24 Sep 2013 07:51:21 +0800 Subject: [PATCH 3/5] Finish implementing the Nonlinear Conjugate Gradient Now everything is prepared for the pull request. --- modules/optim/doc/conjugate_gradient.rst | 11 --- modules/optim/doc/downhill_simplex_method.rst | 13 ++-- modules/optim/doc/optim.rst | 2 +- modules/optim/src/conjugate_gradient.cpp | 78 +++++++++++++++++-- .../optim/test/test_conjugate_gradient.cpp | 23 +++--- 5 files changed, 93 insertions(+), 34 deletions(-) delete mode 100644 modules/optim/doc/conjugate_gradient.rst diff --git a/modules/optim/doc/conjugate_gradient.rst b/modules/optim/doc/conjugate_gradient.rst deleted file mode 100644 index cd9697465..000000000 --- a/modules/optim/doc/conjugate_gradient.rst +++ /dev/null @@ -1,11 +0,0 @@ -Conjugate Gradient -======================= - -.. highlight:: cpp - -optim::ConjGradSolver ---------------------------------- - -.. ocv:class:: optim::ConjGradSolver - -This class is used diff --git a/modules/optim/doc/downhill_simplex_method.rst b/modules/optim/doc/downhill_simplex_method.rst index 94d084c23..bd0e19439 100644 --- a/modules/optim/doc/downhill_simplex_method.rst +++ b/modules/optim/doc/downhill_simplex_method.rst @@ -8,14 +8,15 @@ optim::DownhillSolver .. ocv:class:: optim::DownhillSolver -This class is used to perform the non-linear non-constrained *minimization* of a function, given on an *n*-dimensional Euclidean space, +This class is used to perform the non-linear non-constrained *minimization* of a function, defined on an *n*-dimensional Euclidean space, using the **Nelder-Mead method**, also known as **downhill simplex method**. The basic idea about the method can be obtained from (`http://en.wikipedia.org/wiki/Nelder-Mead\_method `_). It should be noted, that this method, although deterministic, is rather a heuristic and therefore may converge to a local minima, not necessary a global one. It is iterative optimization technique, which at each step uses an information about the values of a function evaluated only at *n+1* points, arranged as a *simplex* in *n*-dimensional space (hence the second name of the method). At each step new point is chosen to evaluate function at, obtained value is compared with previous ones and based on this information simplex changes it's shape -, slowly moving to the local minimum. +, slowly moving to the local minimum. Thus this method is using *only* function values to make decision, on contrary to, say, Nonlinear +Conjugate Gradient method (which is also implemented in ``optim``). Algorithm stops when the number of function evaluations done exceeds ``termcrit.maxCount``, when the function values at the vertices of simplex are within ``termcrit.epsilon`` range or simplex becomes so small that it @@ -30,9 +31,9 @@ positive integer ``termcrit.maxCount`` and positive non-integer ``termcrit.epsil class CV_EXPORTS Function { public: - virtual ~Function() {} - //! ndim - dimensionality - virtual double calc(const double* x) const = 0; + virtual ~Function() {} + virtual double calc(const double* x) const = 0; + virtual void getGradient(const double* /*x*/,double* /*grad*/) {} }; virtual Ptr getFunction() const = 0; @@ -150,7 +151,7 @@ optim::createDownhillSolver This function returns the reference to the ready-to-use ``DownhillSolver`` object. All the parameters are optional, so this procedure can be called even without parameters at all. In this case, the default values will be used. As default value for terminal criteria are the only sensible ones, ``DownhillSolver::setFunction()`` and ``DownhillSolver::setInitStep()`` should be called upon the obtained object, if the respective parameters -were not given to ``createDownhillSolver()``. Otherwise, the two ways (give parameters to ``createDownhillSolver()`` or miss the out and call the +were not given to ``createDownhillSolver()``. Otherwise, the two ways (give parameters to ``createDownhillSolver()`` or miss them out and call the ``DownhillSolver::setFunction()`` and ``DownhillSolver::setInitStep()``) are absolutely equivalent (and will drop the same errors in the same way, should invalid input be detected). diff --git a/modules/optim/doc/optim.rst b/modules/optim/doc/optim.rst index dfa4b65df..113882eee 100644 --- a/modules/optim/doc/optim.rst +++ b/modules/optim/doc/optim.rst @@ -10,4 +10,4 @@ optim. Generic numerical optimization linear_programming downhill_simplex_method primal_dual_algorithm - conjugate_gradient + nonlinear_conjugate_gradient diff --git a/modules/optim/src/conjugate_gradient.cpp b/modules/optim/src/conjugate_gradient.cpp index 7e555c6cc..186d35a1f 100644 --- a/modules/optim/src/conjugate_gradient.cpp +++ b/modules/optim/src/conjugate_gradient.cpp @@ -1,8 +1,11 @@ #include "precomp.hpp" +#undef ALEX_DEBUG #include "debug.hpp" namespace cv{namespace optim{ +#define SEC_METHOD_ITERATIONS 4 +#define INITIAL_SEC_METHOD_SIGMA 0.1 class ConjGradSolverImpl : public ConjGradSolver { public: @@ -16,9 +19,45 @@ namespace cv{namespace optim{ Ptr _Function; TermCriteria _termcrit; Mat_ d,r,buf_x,r_old; + Mat_ minimizeOnTheLine_buf1,minimizeOnTheLine_buf2; private: + static void minimizeOnTheLine(Ptr _f,Mat_& x,const Mat_& d,Mat_& buf1,Mat_& buf2); }; + void ConjGradSolverImpl::minimizeOnTheLine(Ptr _f,Mat_& x,const Mat_& d,Mat_& buf1, + Mat_& buf2){ + double sigma=INITIAL_SEC_METHOD_SIGMA; + buf1=0.0; + buf2=0.0; + + dprintf(("before minimizeOnTheLine\n")); + dprintf(("x:\n")); + print_matrix(x); + dprintf(("d:\n")); + print_matrix(d); + + for(int i=0;igetGradient((double*)x.data,(double*)buf1.data); + dprintf(("buf1:\n")); + print_matrix(buf1); + x=x+sigma*d; + _f->getGradient((double*)x.data,(double*)buf2.data); + dprintf(("buf2:\n")); + print_matrix(buf2); + double d1=buf1.dot(d), d2=buf2.dot(d); + if((d1-d2)==0){ + break; + } + double alpha=-sigma*d1/(d2-d1); + dprintf(("(buf2.dot(d)-buf1.dot(d))=%f\nalpha=%f\n",(buf2.dot(d)-buf1.dot(d)),alpha)); + x=x+(alpha-sigma)*d; + sigma=-alpha; + } + + dprintf(("after minimizeOnTheLine\n")); + print_matrix(x); + } + double ConjGradSolverImpl::minimize(InputOutputArray x){ CV_Assert(_Function.empty()==false); dprintf(("termcrit:\n\ttype: %d\n\tmaxCount: %d\n\tEPS: %g\n",_termcrit.type,_termcrit.maxCount,_termcrit.epsilon)); @@ -28,9 +67,13 @@ namespace cv{namespace optim{ int ndim=MAX(x_mat.rows,x_mat.cols); CV_Assert(x_mat.type()==CV_64FC1); - d.create(1,ndim); - r.create(1,ndim); - r_old.create(1,ndim); + if(d.cols!=ndim){ + d.create(1,ndim); + r.create(1,ndim); + r_old.create(1,ndim); + minimizeOnTheLine_buf1.create(1,ndim); + minimizeOnTheLine_buf2.create(1,ndim); + } Mat_ proxy_x; if(x_mat.rows>1){ @@ -41,14 +84,40 @@ namespace cv{namespace optim{ }else{ proxy_x=x_mat; } + _Function->getGradient((double*)proxy_x.data,(double*)d.data); + if(true){ + d*=-1.0; + d.copyTo(r); + }else{((double*)d.data)[1]=42.0;} //here everything goes. check that everything is setted properly + dprintf(("proxy_x\n"));print_matrix(proxy_x); + dprintf(("d first time\n"));print_matrix(d); + dprintf(("r\n"));print_matrix(r); + + double beta=0; + for(int count=0;count<_termcrit.maxCount;count++){ + minimizeOnTheLine(_Function,proxy_x,d,minimizeOnTheLine_buf1,minimizeOnTheLine_buf2); + r.copyTo(r_old); + _Function->getGradient((double*)proxy_x.data,(double*)r.data); + r*=-1.0; + double r_norm_sq=norm(r); + if(_termcrit.type==(TermCriteria::MAX_ITER+TermCriteria::EPS) && r_norm_sq<_termcrit.epsilon){ + break; + } + r_norm_sq=r_norm_sq*r_norm_sq; + beta=MAX(0.0,(r_norm_sq-r.dot(r_old))/r_norm_sq); + d=r+beta*d; + } + + if(x_mat.rows>1){ Mat(ndim, 1, CV_64F, (double*)proxy_x.data).copyTo(x); } - return 0.0; + return _Function->calc((double*)proxy_x.data); } + ConjGradSolverImpl::ConjGradSolverImpl(){ _Function=Ptr(); } @@ -74,4 +143,3 @@ namespace cv{namespace optim{ return Ptr(CG); } }} - diff --git a/modules/optim/test/test_conjugate_gradient.cpp b/modules/optim/test/test_conjugate_gradient.cpp index 2456a5cab..890d891df 100644 --- a/modules/optim/test/test_conjugate_gradient.cpp +++ b/modules/optim/test/test_conjugate_gradient.cpp @@ -24,38 +24,39 @@ public: return x[0]*x[0]+x[1]*x[1]+x[2]*x[2]+x[3]*x[3]; } void getGradient(const double* x,double* grad){ - for(int i=0;i<4;i++,grad++,x++){ - grad[0]=2*x[0]; + for(int i=0;i<4;i++){ + grad[i]=2*x[i]; } } }; -//TODO: test transp/usual x -/*class RosenbrockF:public cv::optim::Solver::Function{ +class RosenbrockF:public cv::optim::Solver::Function{ double calc(const double* x)const{ return 100*(x[1]-x[0]*x[0])*(x[1]-x[0]*x[0])+(1-x[0])*(1-x[0]); } -};*/ + void getGradient(const double* x,double* grad){ + grad[0]=-2*(1-x[0])-400*(x[1]-x[0]*x[0])*x[0]; + grad[1]=200*(x[1]-x[0]*x[0]); + } +}; TEST(Optim_ConjGrad, regression_basic){ cv::Ptr solver=cv::optim::createConjGradSolver(); #if 1 { cv::Ptr ptr_F(new SphereF()); - cv::Mat x=(cv::Mat_(1,2)<<1.0,1.0), - etalon_x=(cv::Mat_(1,2)<<0.0,0.0); + cv::Mat x=(cv::Mat_(4,1)<<50.0,10.0,1.0,-10.0), + etalon_x=(cv::Mat_(1,4)<<0.0,0.0,0.0,0.0); double etalon_res=0.0; - return; mytest(solver,ptr_F,x,etalon_x,etalon_res); } #endif -#if 0 +#if 1 { cv::Ptr ptr_F(new RosenbrockF()); cv::Mat x=(cv::Mat_(2,1)<<0.0,0.0), - step=(cv::Mat_(2,1)<<0.5,+0.5), etalon_x=(cv::Mat_(2,1)<<1.0,1.0); double etalon_res=0.0; - mytest(solver,ptr_F,x,step,etalon_x,etalon_res); + mytest(solver,ptr_F,x,etalon_x,etalon_res); } #endif } From 3ac3ba041597df5e71fbde68d518e18956a7a624 Mon Sep 17 00:00:00 2001 From: Alex Leontiev Date: Sat, 28 Sep 2013 15:58:06 +0800 Subject: [PATCH 4/5] Minor fixes Fix failed builds that opencv's buildbot has got. --- .../doc/nonlinear_conjugate_gradient.rst | 136 ++++++++++++++++++ modules/optim/src/conjugate_gradient.cpp | 6 +- 2 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 modules/optim/doc/nonlinear_conjugate_gradient.rst diff --git a/modules/optim/doc/nonlinear_conjugate_gradient.rst b/modules/optim/doc/nonlinear_conjugate_gradient.rst new file mode 100644 index 000000000..d7c602938 --- /dev/null +++ b/modules/optim/doc/nonlinear_conjugate_gradient.rst @@ -0,0 +1,136 @@ +Nonlinear Conjugate Gradient +=============================== + +.. highlight:: cpp + +optim::ConjGradSolver +--------------------------------- + +.. ocv:class:: optim::ConjGradSolver + +This class is used to perform the non-linear non-constrained *minimization* of a function with *known gradient* +, defined on an *n*-dimensional Euclidean space, +using the **Nonlinear Conjugate Gradient method**. The implementation was done based on the beautifully clear explanatory article `An Introduction to the Conjugate Gradient Method Without the Agonizing Pain `_ +by Jonathan Richard Shewchuk. The method can be seen as an adaptation of a standard Conjugate Gradient method (see, for example +`http://en.wikipedia.org/wiki/Conjugate_gradient_method `_) for numerically solving the +systems of linear equations. + +It should be noted, that +this method, although deterministic, is rather a heuristic method and therefore may converge to a local minima, not necessary a global one. What +is even more disastrous, most of its behaviour is ruled by gradient, therefore it essentially cannot distinguish between local minima and maxima. +Therefore, if it starts sufficiently near to the local maximum, it may converge to it. Another obvious restriction is that it should be possible +to compute the gradient of a function at any point, thus it is preferable to have analytic expression for gradient and computational burden +should be born by the user. + +The latter responsibility is accompilished via the ``getGradient(const double* x,double* grad)`` method of a +``Solver::Function`` interface (which represents function that is being optimized). This method takes point a point in *n*-dimensional space +(first argument represents the array of coordinates of that point) and comput its gradient (it should be stored in the second argument as an array). + +:: + + class CV_EXPORTS Solver : public Algorithm + { + public: + class CV_EXPORTS Function + { + public: + virtual ~Function() {} + virtual double calc(const double* x) const = 0; + virtual void getGradient(const double* /*x*/,double* /*grad*/) {} + }; + + virtual Ptr getFunction() const = 0; + virtual void setFunction(const Ptr& f) = 0; + + virtual TermCriteria getTermCriteria() const = 0; + virtual void setTermCriteria(const TermCriteria& termcrit) = 0; + + // x contain the initial point before the call and the minima position (if algorithm converged) after. x is assumed to be (something that + // after getMat() will return) row-vector or column-vector. *It's size and should + // be consisted with previous dimensionality data given, if any (otherwise, it determines dimensionality)* + virtual double minimize(InputOutputArray x) = 0; + }; + + class CV_EXPORTS ConjGradSolver : public Solver{ + }; + +Note, that class ``ConjGradSolver`` thus does not add any new methods to the basic ``Solver`` interface. + +optim::ConjGradSolver::getFunction +-------------------------------------------- + +Getter for the optimized function. The optimized function is represented by ``Solver::Function`` interface, which requires +derivatives to implement the method ``calc(double*)`` to evaluate the function. It should be emphasized once more, that since Nonlinear +Conjugate Gradient method requires gradient to be computable in addition to the function values, +``getGradient(const double* x,double* grad)`` method of a ``Solver::Function`` interface should be also implemented meaningfully. + +.. ocv:function:: Ptr optim::ConjGradSolver::getFunction() + + :return: Smart-pointer to an object that implements ``Solver::Function`` interface - it represents the function that is being optimized. It can be empty, if no function was given so far. + +optim::ConjGradSolver::setFunction +----------------------------------------------- + +Setter for the optimized function. *It should be called at least once before the call to* ``ConjGradSolver::minimize()``, as +default value is not usable. + +.. ocv:function:: void optim::ConjGradSolver::setFunction(const Ptr& f) + + :param f: The new function to optimize. + +optim::ConjGradSolver::getTermCriteria +---------------------------------------------------- + +Getter for the previously set terminal criteria for this algorithm. + +.. ocv:function:: TermCriteria optim::ConjGradSolver::getTermCriteria() + + :return: Deep copy of the terminal criteria used at the moment. + +optim::ConjGradSolver::setTermCriteria +------------------------------------------ + +Set terminal criteria for downhill simplex method. Two things should be noted. First, this method *is not necessary* to be called +before the first call to ``ConjGradSolver::minimize()``, as the default value is sensible. Second, the method will raise an error +if ``termcrit.type!=(TermCriteria::MAX_ITER+TermCriteria::EPS)`` and ``termcrit.type!=TermCriteria::MAX_ITER``. This means that termination criteria +has to restrict maximum number of iterations to be done and may optionally allow algorithm to stop earlier if certain tolerance +is achieved (what we mean by "tolerance is achieved" will be clarified below). If ``termcrit`` restricts both tolerance and maximum iteration +number, both ``termcrit.epsilon`` and ``termcrit.maxCount`` should be positive. In case, if ``termcrit.type==TermCriteria::MAX_ITER``, +only member ``termcrit.maxCount`` is required to be positive and in this case algorithm will just work for required number of iterations. + +In current implementation, "tolerance is achieved" means that we have arrived at the point where the :math:`L_2`-norm of the gradient is less +than the tolerance value. + +.. ocv:function:: void optim::ConjGradSolver::setTermCriteria(const TermCriteria& termcrit) + + :param termcrit: Terminal criteria to be used, represented as ``TermCriteria`` structure (defined elsewhere in openCV). Mind you, that it should meet ``termcrit.type==(TermCriteria::MAX_ITER+TermCriteria::EPS) && termcrit.epsilon>0 && termcrit.maxCount>0`` or ``termcrit.type==TermCriteria::MAX_ITER) && termcrit.maxCount>0``, otherwise the error will be raised. + +optim::ConjGradSolver::minimize +----------------------------------- + +The main method of the ``ConjGradSolver``. It actually runs the algorithm and performs the minimization. The sole input parameter determines the +centroid of the starting simplex (roughly, it tells where to start), all the others (terminal criteria and function to be minimized) +are supposed to be set via the setters before the call to this method or the default values (not always sensible) will be used. Sometimes it may +throw an error, if these default values cannot be used (say, you forgot to set the function to minimize and default value, that is, empty function, +cannot be used). + +.. ocv:function:: double optim::ConjGradSolver::minimize(InputOutputArray x) + + :param x: The initial point. It is hard to overemphasize how important the choise of initial point is when you are using the heuristic algorithm like this one. Badly chosen initial point can make algorithm converge to (local) maximum instead of minimum, do not converge at all, converge to local minimum instead of global one. + + :return: The value of a function at the point found. + +optim::createConjGradSolver +------------------------------------ + +This function returns the reference to the ready-to-use ``ConjGradSolver`` object. All the parameters are optional, so this procedure can be called +even without parameters at all. In this case, the default values will be used. As default value for terminal criteria are the only sensible ones, +``ConjGradSolver::setFunction()`` should be called upon the obtained object, if the function +was not given to ``createConjGradSolver()``. Otherwise, the two ways (submit it to ``createConjGradSolver()`` or miss it out and call the +``ConjGradSolver::setFunction()``) are absolutely equivalent (and will drop the same errors in the same way, +should invalid input be detected). + +.. ocv:function:: Ptr optim::createConjGradSolver(const Ptr& f, TermCriteria termcrit) + + :param f: Pointer to the function that will be minimized, similarly to the one you submit via ``ConjGradSolver::setFunction``. + :param termcrit: Terminal criteria to the algorithm, similarly to the one you submit via ``ConjGradSolver::setTermCriteria``. diff --git a/modules/optim/src/conjugate_gradient.cpp b/modules/optim/src/conjugate_gradient.cpp index 186d35a1f..9b48f1f68 100644 --- a/modules/optim/src/conjugate_gradient.cpp +++ b/modules/optim/src/conjugate_gradient.cpp @@ -37,11 +37,11 @@ namespace cv{namespace optim{ print_matrix(d); for(int i=0;igetGradient((double*)x.data,(double*)buf1.data); + _f->getGradient((double*)x.data,(double*)buf1.data); dprintf(("buf1:\n")); print_matrix(buf1); x=x+sigma*d; - _f->getGradient((double*)x.data,(double*)buf2.data); + _f->getGradient((double*)x.data,(double*)buf2.data); dprintf(("buf2:\n")); print_matrix(buf2); double d1=buf1.dot(d), d2=buf2.dot(d); @@ -85,10 +85,8 @@ namespace cv{namespace optim{ proxy_x=x_mat; } _Function->getGradient((double*)proxy_x.data,(double*)d.data); - if(true){ d*=-1.0; d.copyTo(r); - }else{((double*)d.data)[1]=42.0;} //here everything goes. check that everything is setted properly dprintf(("proxy_x\n"));print_matrix(proxy_x); From 0324932fb3957e353a8111f101bce7f3c7cb68da Mon Sep 17 00:00:00 2001 From: Alex Leontiev Date: Mon, 30 Sep 2013 08:27:43 +0800 Subject: [PATCH 5/5] Added the copyright statements Added the copyrights missing in all files that required so. --- modules/optim/include/opencv2/optim.hpp | 5 +-- modules/optim/include/opencv2/optim/optim.hpp | 6 +-- modules/optim/src/conjugate_gradient.cpp | 41 +++++++++++++++++++ modules/optim/src/debug.hpp | 40 ++++++++++++++++++ modules/optim/src/denoise_tvl1.cpp | 40 ++++++++++++++++++ modules/optim/src/lpsolver.cpp | 40 ++++++++++++++++++ modules/optim/src/precomp.hpp | 7 ++-- modules/optim/src/simplex.cpp | 40 ++++++++++++++++++ .../optim/test/test_conjugate_gradient.cpp | 40 ++++++++++++++++++ modules/optim/test/test_denoise_tvl1.cpp | 40 ++++++++++++++++++ modules/optim/test/test_downhill_simplex.cpp | 40 ++++++++++++++++++ modules/optim/test/test_lpsolver.cpp | 40 ++++++++++++++++++ 12 files changed, 368 insertions(+), 11 deletions(-) diff --git a/modules/optim/include/opencv2/optim.hpp b/modules/optim/include/opencv2/optim.hpp index 0a460cce0..060855d07 100644 --- a/modules/optim/include/opencv2/optim.hpp +++ b/modules/optim/include/opencv2/optim.hpp @@ -10,8 +10,7 @@ // License Agreement // For Open Source Computer Vision Library // -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -30,7 +29,7 @@ // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, +// In no event shall the OpenCV Foundation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused diff --git a/modules/optim/include/opencv2/optim/optim.hpp b/modules/optim/include/opencv2/optim/optim.hpp index b5a9ebf79..25a131517 100644 --- a/modules/optim/include/opencv2/optim/optim.hpp +++ b/modules/optim/include/opencv2/optim/optim.hpp @@ -7,11 +7,9 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. // Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // @@ -31,7 +29,7 @@ // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, +// In no event shall the OpenCV Foundation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused diff --git a/modules/optim/src/conjugate_gradient.cpp b/modules/optim/src/conjugate_gradient.cpp index 9b48f1f68..027e9f18a 100644 --- a/modules/optim/src/conjugate_gradient.cpp +++ b/modules/optim/src/conjugate_gradient.cpp @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + #include "precomp.hpp" #undef ALEX_DEBUG #include "debug.hpp" diff --git a/modules/optim/src/debug.hpp b/modules/optim/src/debug.hpp index fe5d00e87..757703694 100644 --- a/modules/optim/src/debug.hpp +++ b/modules/optim/src/debug.hpp @@ -1,3 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ namespace cv{namespace optim{ #ifdef ALEX_DEBUG #define dprintf(x) printf x diff --git a/modules/optim/src/denoise_tvl1.cpp b/modules/optim/src/denoise_tvl1.cpp index a2068baba..6b4f3c2a8 100644 --- a/modules/optim/src/denoise_tvl1.cpp +++ b/modules/optim/src/denoise_tvl1.cpp @@ -1,3 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ #include "precomp.hpp" #undef ALEX_DEBUG #include "debug.hpp" diff --git a/modules/optim/src/lpsolver.cpp b/modules/optim/src/lpsolver.cpp index a046ddae1..de66ef7f0 100644 --- a/modules/optim/src/lpsolver.cpp +++ b/modules/optim/src/lpsolver.cpp @@ -1,3 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ #include "precomp.hpp" #include #include diff --git a/modules/optim/src/precomp.hpp b/modules/optim/src/precomp.hpp index 7aab572f8..2838e54f3 100644 --- a/modules/optim/src/precomp.hpp +++ b/modules/optim/src/precomp.hpp @@ -7,11 +7,10 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -30,7 +29,7 @@ // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, +// In no event shall the OpenCV Foundation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused diff --git a/modules/optim/src/simplex.cpp b/modules/optim/src/simplex.cpp index 54de6ed8c..f3818cdc5 100644 --- a/modules/optim/src/simplex.cpp +++ b/modules/optim/src/simplex.cpp @@ -1,3 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ #include "precomp.hpp" #include "debug.hpp" #include "opencv2/core/core_c.h" diff --git a/modules/optim/test/test_conjugate_gradient.cpp b/modules/optim/test/test_conjugate_gradient.cpp index 890d891df..aaddfe695 100644 --- a/modules/optim/test/test_conjugate_gradient.cpp +++ b/modules/optim/test/test_conjugate_gradient.cpp @@ -1,3 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ #include "test_precomp.hpp" #include diff --git a/modules/optim/test/test_denoise_tvl1.cpp b/modules/optim/test/test_denoise_tvl1.cpp index 2721a7666..9334dc5c5 100644 --- a/modules/optim/test/test_denoise_tvl1.cpp +++ b/modules/optim/test/test_denoise_tvl1.cpp @@ -1,3 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ #include "test_precomp.hpp" #include "opencv2/highgui.hpp" diff --git a/modules/optim/test/test_downhill_simplex.cpp b/modules/optim/test/test_downhill_simplex.cpp index 95b2c6e9e..c55236505 100644 --- a/modules/optim/test/test_downhill_simplex.cpp +++ b/modules/optim/test/test_downhill_simplex.cpp @@ -1,3 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ #include "test_precomp.hpp" #include #include diff --git a/modules/optim/test/test_lpsolver.cpp b/modules/optim/test/test_lpsolver.cpp index f39c7eb37..f1bfc5b58 100644 --- a/modules/optim/test/test_lpsolver.cpp +++ b/modules/optim/test/test_lpsolver.cpp @@ -1,3 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ #include "test_precomp.hpp" #include