...
 
Commits (1)
......@@ -61,36 +61,40 @@ public:
};
template<class ProblemInterface>
bool check_all(ProblemInterface* _np, double _dx, double _eps)
bool check_all(ProblemInterface* _np, const double* _x, double _dx, double _eps)
{
conf_.dx = _dx;
conf_.eps = _eps;
return check_all(_np);
return check_all(_np, _x);
}
template<class ProblemInterface>
bool check_all(ProblemInterface* _np)
bool check_all(ProblemInterface* _np, const double* _x)
{
bool d1_ok = check_d1(_np);
bool d2_ok = check_d2(_np);
bool d1_ok = check_d1(_np, _x);
bool d2_ok = check_d2(_np, _x);
return ( d1_ok && d2_ok);
}
template<class ProblemInterface>
bool check_d1(ProblemInterface* _np)
bool check_d1(ProblemInterface* _np, const double* _x)
{
int n_ok = 0;
int n_errors = 0;
int n = _np->n_unknowns();
std::vector<double> x(n), g(n);
std::vector<double> x(n); // Copy x because we don't want to change the input
for (int i = 0; i < n; ++i)
x[i] = _x[i];
for(int i=0; i<conf_.n_iters; ++i)
{
std::vector<double> g(n);
// for(int i=0; i<conf_.n_iters; ++i)
// {
// get random x
get_random_x(x, conf_.x_min, conf_.x_max);
// get_random_x(x, conf_.x_min, conf_.x_max);
// gradient
_np->eval_gradient(P(x), P(g));
......@@ -111,7 +115,7 @@ public:
<< " should be " << fd << " (" << std::abs(fd-g[j]) << ")" << std::endl;
}
else ++ n_ok;
}
// }
}
std::cerr << "############## Gradient Checker Summary #############\n";
......@@ -125,19 +129,22 @@ public:
inline double getCoeff(const MatrixType &m, int r, int c);
template<class ProblemInterface>
bool check_d2(ProblemInterface* _np)
bool check_d2(ProblemInterface* _np, const double* _x)
{
int n_ok = 0;
int n_errors = 0;
int n = _np->n_unknowns();
std::vector<double> x(n);
std::vector<double> x(n); // Copy x because we don't want to change the input
for (int i = 0; i < n; ++i)
x[i] = _x[i];
typename ProblemInterface::SMatrixNP H(n,n);
for(int i=0; i<conf_.n_iters; ++i)
{
// for(int i=0; i<conf_.n_iters; ++i)
// {
// get random x
get_random_x(x, conf_.x_min, conf_.x_max);
// get_random_x(x, conf_.x_min, conf_.x_max);
// gradient
_np->eval_hessian(P(x), H);
......@@ -167,7 +174,7 @@ public:
<< ", relative delta:" << (std::abs(fd-getCoeff(H, j,k))/std::max(std::abs(getCoeff(H, j,k)), 1.0)) << ")" << std::endl;
}
else ++ n_ok;
}
// }
}
std::cerr << "############## Hessian Checker Summary #############\n";
......