OpenMS/OpenMS — pull request #817 by hroest (2014-05-12 17:42:05+00:00)
Title: [FIX] fix spline derivative for cubic spline

I have a question regarding the recently merged cubic spline, specifically how the derivatives are calculated here https://github.com/OpenMS/OpenMS/blob/develop/src/openms/source/MATH/MISC/CubicSpline2d.cpp#L105

The cubic spline with its parameters is evaluated as
```
d * x^3 + c * x^2 + b * x + a
```
so it seems only natural that the first derivative of this should be
```
3 * d * x^2 + 2 * c * x + b
```
and not
```
d * x^2 + c * x + b
```
which is what is in the code. Maybe I missed something here but I think this is a mistake and should be changed. Also, the current code in `CubicSpline2d.cpp` produces wrong results on my test data and does not properly interpolate a gaussian function which I re-sample in my tests here: https://github.com/hroest/OpenMS/blob/feature/PeakPickerSNPerformance_CubicSplines/src/tests/class_tests/openms/source/PeakPickerMaxima_test.cpp#L200

I create a gaussian function with mu = 10 and sigma = 5 (maximum at point 10 https://github.com/hroest/OpenMS/blob/feature/PeakPickerSNPerformance_CubicSplines/src/tests/class_tests/openms/source/PeakPickerMaxima_test.cpp#L68) in my tests but when I let the peak picker algorithm run on the spline interpolation I see this result
```457: eval at 9 to 0.00583180911
457: eval at 10 to 0.00152327345
457: eval at 10.5 to 0.000732898981
457: eval at 10.75 to 0.000340515054
457: eval at 10.875 to 0.000145023918
457: eval at 10.9375 to 4.74535567e-05
457: eval at 10.96875 to -1.2878222e-06
457: eval at 10.953125 to 2.30792171e-05
457: eval at 10.9609375 to 1.08947849e-05
457: eval at 10.9648438 to 4.80325323e-06
457: eval at 10.9667969 to 1.75765848e-06
457: eval at 10.9677734 to 2.34903882e-07
457: eval at 10.9682617 to -5.26462723e-07
457: eval at 10.9680176 to -1.45780312e-07
457: eval at 10.9678955 to 4.45615625e-08
457: eval at 10.9679565 to -5.06094303e-08
457: eval at 10.967926 to -3.02394785e-09
457: eval at 10.9679108 to 2.07688038e-08
457: eval at 10.9679184 to 8.87242713e-09
457: eval at 10.9679222 to 2.92423942e-09
457: eval at 10.9679241 to -4.98542657e-11
457: eval at 10.9679232 to 1.43719257e-09
457: ===> eval at 10.9679236 to 10.9679236
```

what it should be producing is
```
457: eval at 9 to 0.00312644886
457: eval at 10 to -6.49509804e-05
457: eval at 9.5 to 0.00151953571
457: eval at 9.75 to 0.000724489054
457: eval at 9.875 to 0.00032906821
457: eval at 9.9375 to 0.000131883408
457: eval at 9.96875 to 3.3422412e-05
457: eval at 9.984375 to -1.57752346e-05
457: eval at 9.9765625 to 8.82085112e-06
457: eval at 9.98046875 to -3.47787614e-06
457: eval at 9.97851562 to 2.67131639e-06
457: eval at 9.97949219 to -4.0332265e-07
457: eval at 9.97900391 to 1.13398618e-06
457: eval at 9.97924805 to 3.65329089e-07
457: eval at 9.97937012 to -1.89974488e-08
457: eval at 9.97930908 to 1.73165653e-07
457: eval at 9.9793396 to 7.70840604e-08
457: eval at 9.97935486 to 2.90432954e-08
457: eval at 9.97936249 to 5.02292068e-09
457: eval at 9.9793663 to -6.98726471e-09
457: eval at 9.9793644 to -9.8217218e-10
457: eval at 9.97936344 to 2.02037421e-09
```
e.g. it should approximate 10.0 closer and closer and not 11.0.

PS: Since I did not adjust the tests, travis will fail. However if you agree with me that this should be changed, I will also adjust the tests accordingly.