http://www.itl.nist.gov/div898/strd/nls/data/hahn1.shtml
| 839 | |
| 840 | // http://www.itl.nist.gov/div898/strd/nls/data/hahn1.shtml |
| 841 | void testNistHahn1(void) |
| 842 | { |
| 843 | const int n=7; |
| 844 | int info; |
| 845 | |
| 846 | VectorXd x(n); |
| 847 | |
| 848 | /* |
| 849 | * First try |
| 850 | */ |
| 851 | x<< 10., -1., .05, -.00001, -.05, .001, -.000001; |
| 852 | // do the computation |
| 853 | hahn1_functor functor; |
| 854 | LevenbergMarquardt<hahn1_functor> lm(functor); |
| 855 | info = lm.minimize(x); |
| 856 | |
| 857 | // check return value |
| 858 | VERIFY_IS_EQUAL(info, 1); |
| 859 | VERIFY_IS_EQUAL(lm.nfev, 11); |
| 860 | VERIFY_IS_EQUAL(lm.njev, 10); |
| 861 | // check norm^2 |
| 862 | VERIFY_IS_APPROX(lm.fvec.squaredNorm(), 1.5324382854E+00); |
| 863 | // check x |
| 864 | VERIFY_IS_APPROX(x[0], 1.0776351733E+00); |
| 865 | VERIFY_IS_APPROX(x[1],-1.2269296921E-01); |
| 866 | VERIFY_IS_APPROX(x[2], 4.0863750610E-03); |
| 867 | VERIFY_IS_APPROX(x[3],-1.426264e-06); // shoulde be : -1.4262662514E-06 |
| 868 | VERIFY_IS_APPROX(x[4],-5.7609940901E-03); |
| 869 | VERIFY_IS_APPROX(x[5], 2.4053735503E-04); |
| 870 | VERIFY_IS_APPROX(x[6],-1.2314450199E-07); |
| 871 | |
| 872 | /* |
| 873 | * Second try |
| 874 | */ |
| 875 | x<< .1, -.1, .005, -.000001, -.005, .0001, -.0000001; |
| 876 | // do the computation |
| 877 | info = lm.minimize(x); |
| 878 | |
| 879 | // check return value |
| 880 | VERIFY_IS_EQUAL(info, 1); |
| 881 | VERIFY_IS_EQUAL(lm.nfev, 11); |
| 882 | VERIFY_IS_EQUAL(lm.njev, 10); |
| 883 | // check norm^2 |
| 884 | VERIFY_IS_APPROX(lm.fvec.squaredNorm(), 1.5324382854E+00); |
| 885 | // check x |
| 886 | VERIFY_IS_APPROX(x[0], 1.077640); // should be : 1.0776351733E+00 |
| 887 | VERIFY_IS_APPROX(x[1], -0.1226933); // should be : -1.2269296921E-01 |
| 888 | VERIFY_IS_APPROX(x[2], 0.004086383); // should be : 4.0863750610E-03 |
| 889 | VERIFY_IS_APPROX(x[3], -1.426277e-06); // shoulde be : -1.4262662514E-06 |
| 890 | VERIFY_IS_APPROX(x[4],-5.7609940901E-03); |
| 891 | VERIFY_IS_APPROX(x[5], 0.00024053772); // should be : 2.4053735503E-04 |
| 892 | VERIFY_IS_APPROX(x[6], -1.231450e-07); // should be : -1.2314450199E-07 |
| 893 | |
| 894 | } |
| 895 | |
| 896 | struct misra1d_functor : Functor<double> |
| 897 | { |
no test coverage detected