Incorrect linear interpolation with large x values ​​using Math.Net Numerics

I am trying to use Math.NET Numerics to interpolate a DateTime - Value series. I started with linear interpolation, but I get very good results.

Running this test:

public class script{

public void check_numerics()
  {
    var ticks = DateTime.Now.Ticks;
    Console.WriteLine("Ticks: " + ticks);
    var xValues = new double[] { ticks, ticks + 1000, ticks + 2000, ticks + 3000, ticks + 4000, ticks + 5000 };
    var yValues = new double[] {0, 1, 2, 3, 4, 5};
    var spline = Interpolate.LinearBetweenPoints(xValues, yValues);
    var ticks2 = ticks;
    for (int i = 0; i < 10; i++)
    {
      ticks2 += 500;
      Console.WriteLine(spline.Interpolate(ticks2));
    }
  }
}

This gives:

Ticks: 635385235576843379
0.5
1
1.5
2
2.42857142857143 // this should be 2.5
3
3.5
4
4.5
5

Please note that 2.4285 is pretty wrong. At another time (another tick value), the other value will be "wrong". Is there an “error” with large x values ​​in Math.NET or am I expecting too much?

+4
source share
1 answer

Just confirming the comments above as the keeper of Math.NET Numerics:

() , , 128:

Precision.EpsilonOf(ticks); // 128

, 128/2-1 = 63 , :

long ticks = DateTime.Now.Ticks // 635385606515570758
((long)(double)ticks)           // 635385606515570816
((long)(63+(double)ticks))      // 635385606515570816
((long)(-63+(double)ticks))     // 635385606515570816
((long)(65+(double)ticks))      // 635385606515570944
((long)(-65+(double)ticks))     // 635385606515570688

500 128 128 (, 512), , , .

, 10000, , 0,0078125 1 500.

Precision.EpsilonOf(ticks/10000); // 0.0078125
+5

Source: https://habr.com/ru/post/1544752/


All Articles