Commit c6ce8c93 by Thibault Lejemble

### AutoDiff for weighting functions test

parent 87112240
 ... ... @@ -12,9 +12,84 @@ #include "../common/testing.h" #include "../common/testUtils.h" #include using namespace std; using namespace Grenaille; template void testFunctionAutoDiff() { // Define related structure typedef typename WeightKernel::Scalar ScalarDiff; typedef typename ScalarDiff::Scalar Scalar; typedef typename DataPoint::VectorType VectorTypeDiff; typedef typename DataPoint::MatrixType MatrixTypeDiff; Scalar epsilon = testEpsilon(); ScalarDiff t = Eigen::internal::random(0.10, 10.0); ScalarDiff tDiff = ScalarDiff(t.value(), DataPoint::Dim+1, 0); DistWeightFunc wfunc(t); DistWeightFunc wfuncDiff(tDiff); // rejection sampling inside a sphere of radius t VectorTypeDiff x = t*VectorTypeDiff::Random(); while ( x.norm() < 0.001*t || 0.999*t < x.norm()) x = t*VectorTypeDiff::Random(); VectorTypeDiff xDiff; for(int i=0; i(); // 2nd order space derivative dw = wfunc.spacedw(xDiff, dummy); for(int i=0; i(); } // 1st order scale derivative w = wfuncDiff.w(x, dummy); dt_w_ = w.derivatives()[0]; // 2nd order scale derivative w = wfuncDiff.scaledw(x, dummy); d2t_w_ = w.derivatives()[0]; // cross derivative w = wfuncDiff.scaledw(xDiff, dummy); d2tx_w_ = w.derivatives().template tail(); VERIFY( (dx_w-dx_w_).array().abs().maxCoeff() < epsilon ); VERIFY( (d2x_w-d2x_w_).array().abs().maxCoeff() < epsilon ); VERIFY( (d2tx_w-d2tx_w_).array().abs().maxCoeff() < epsilon ); VERIFY( std::abs((dt_w-dt_w_).value()) < epsilon ); VERIFY( std::abs((d2t_w-d2t_w_).value()) < epsilon ); } template void testFunction() { ... ... @@ -122,10 +197,20 @@ void callSubTests() typedef SmoothWeightKernel SmoothKernel; typedef ConstantWeightKernel ConstantKernel; typedef Eigen::AutoDiffScalar> ScalarDiff; typedef PointPositionNormal DataPointDiff; typedef SmoothWeightKernel SmoothKernelDiff; typedef ConstantWeightKernel ConstantKernelDiff; for(int i = 0; i < g_repeat; ++i) { CALL_SUBTEST(( testFunction() )); CALL_SUBTEST(( testFunction() )); CALL_SUBTEST(( testFunctionAutoDiff() )); CALL_SUBTEST(( testFunctionAutoDiff() )); } cout << "ok" << endl; } ... ...
 ... ... @@ -12,9 +12,40 @@ #include "../common/testing.h" #include "../common/testUtils.h" #include using namespace std; using namespace Grenaille; template void testFunctionAutoDiff() { typedef typename Kernel::Scalar ScalarDiff; typedef typename ScalarDiff::Scalar Scalar; Scalar step = Scalar(0.05); int n = Scalar(1.)/step; Kernel k; Scalar epsilon = testEpsilon(); // compare to automatic differentiation for(int i=1; i<=n; ++i) { ScalarDiff a(i*step, 1, 0); ScalarDiff f = k.f(a); ScalarDiff df = k.df(a); ScalarDiff ddf = k.ddf(a); Scalar diff1 = std::abs( f.derivatives()[0] - df.value()); Scalar diff2 = std::abs(df.derivatives()[0] - ddf.value()); VERIFY(diff1 < epsilon); VERIFY(diff2 < epsilon); } } template void testFunction() { ... ... @@ -53,8 +84,14 @@ void testFunction() template void callSubTests() { typedef Eigen::AutoDiffScalar> ScalarDiff; typedef SmoothWeightKernel Kernel; typedef SmoothWeightKernel KernelAutoDiff; CALL_SUBTEST(( testFunction() )); CALL_SUBTEST(( testFunctionAutoDiff() )); cout << "ok" << endl; } ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!