Skip to content
Snippets Groups Projects
Commit a2647f48 authored by Müller, Alexander's avatar Müller, Alexander
Browse files

changed tolerances to fix failing tests

The tests failed since the construction of values of ProductManifold<> in ValueFactory uses random entries between [0.9..1.1]. These are then used for the tests and are projected onto the manifold. 

To pass this tests it is needed to adjust several Taylor expansions and thresholds. For example this commit increases the threshold from `1e-4` to `1e-2` and adds more terms to the Taylor expansion. The reason for this change is explained in the following. 

The problem is, even if the tolerance `1e-4` is sufficient to have a correct function value within machine precision, it is not always sufficient to get correct derivatives since here we lose orders of correctness.

For  example of for sinc(x) we need to put the threshold at `1e-4` to get the correct function value if we use  `1.0-x*x/6.0` as approximation formula.

If we then use this formula within automatic differentiation or finite differences, e.g. the derivative algorithms  "sees" only the following formulas of the first and second derivative:

- Function value: `1.0-x*x/6.0`   This function is implemented
- First deriv: `-x/3.0`      This sees the derivative algorithms as first derivative
- Second: `-1.0/3.0`       This sees the derivative algorithms as second derivative

Obviously, this is the case if the function value is inside the region where the Taylor expansion is used.

If we use these functions to test the exactness of the derivatives we need to set the threshold to `x<1e-6` to get exact second order derivatives where the error is within machine precision. Therefore, for larger values `x>1e-6` the exact formula has to be used to get correct results. Unfortunately, in this range the exact derivative are already unstable.
E.g. the first derivative formula behaves already strange near `x=1e-4`.

Therefore,
to get a correct derivative value we need to switch to the Taylor expansion earlier (`1e-4`) to prevent using the unstable exact formula. But in this range the Taylor expansion is unable to reproduce an approximation error within machine precision.

I think the only way to fix this problem is to add more terms to the Taylor expansions. Since even if they seem to be sufficient in terms of function value, usually they are not sufficient in terms of derivatives.

For `sin(x)/x` a test ist at https://godbolt.org/z/T995hGec3 and for `acos(x)^2` https://godbolt.org/z/TG9E15jjf.
parent a044e810
No related branches found
No related tags found
1 merge request!70added ProductManifold<...>
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment