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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user