1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

extended MinProblemSolver::Function to 1) report the space dimensionality, 2) compute gradient if needed

This commit is contained in:
Vadim Pisarevsky
2015-05-05 15:56:06 +03:00
parent 5b9182ba43
commit 63a63e3eaa
5 changed files with 32 additions and 5 deletions
+19
View File
@@ -46,6 +46,25 @@
namespace cv
{
double MinProblemSolver::Function::getGradientEps() const { return 1e-3; }
void MinProblemSolver::Function::getGradient(const double* x, double* grad)
{
double eps = getGradientEps();
int i, n = getDims();
AutoBuffer<double> x_buf(n);
double* x_ = x_buf;
for( i = 0; i < n; i++ )
x_[i] = x[i];
for( i = 0; i < n; i++ )
{
x_[i] = x[i] + eps;
double y1 = calc(x_);
x_[i] = x[i] - eps;
double y0 = calc(x_);
grad[i] = (y1 - y0)/(2*eps);
x_[i] = x[i];
}
}
#define SEC_METHOD_ITERATIONS 4
#define INITIAL_SEC_METHOD_SIGMA 0.1