0

I have a jagged float array chunks (float[][] chunks), and I want to interpolate each chunk of floats (with length n) with a sample rate of x. For example, if chunks[0] was {1f, 5f, 10f} so n = 3 and lets say x = 12, I want:

1.0000        
1.7273   
2.4545    
3.1818   
3.9091    
4.6364   
5.4545   
6.3636   
7.2727  
8.1818    
9.0909    
10.0000

I've found a way of doing this using the library MathNet.Numerics, but it is very ineffecient. My code is below.

double[] d = new double[n];
d[0] = 1d;
for (int i = 1; i < d.Length; i++)
    d[i] = d[i - 1] + (double)(x - 1)/(double)(n - 1);
for (int c = 0; c < chunks.Length; c++)
    for (int j = 0; j < x; j++)
            doubles.Add(Convert.ToSingle(Interpolate.Linear(d, chunks[c].Select(y => Convert.ToDouble(y))).Interpolate(j + 1)));

I then parse back the List<double> into a jagged array. This code basically mimics having a 2d plane for the interpolation, rather than just interpolating the numbers themselves (at least I think). MathNet.Numerics.Interpolate.Linear() takes two double arrays, and this was the only way I managed to get proper results. However, it takes forever. Is there a better way to do this?

Mini
  • 445
  • 5
  • 17
  • What does linear interpolation of 3 numbers into 12 samples mean? Oh, and is the entropy you are finding the minimum of, Thermodynamic entropy or Information Theory entropy? – Flydog57 Aug 04 '18 at 22:19
  • The three numbers are 1, 5, and 10. I want the interpolation line to be sampled x times. So when x is 12, the results are those 12 numbers in my post. – Mini Aug 04 '18 at 22:24
  • What was wrong with my solution at your previous posting : https://stackoverflow.com/questions/51645315/how-to-interpolate-through-3-points-numbers-with-a-defined-number-of-samples-i/51647817#51647817. I gave a full explanation and working code. Please ignore the comments from people who do not really understand the problems nor my great explanation and working solution. There is a half step offset between the 6th point and the center point and a half step offset between the center point and the 7th point that is missing in your code. See my integer solution for 1 12 34 – jdweng Aug 04 '18 at 23:52
  • A straight line is an arithmetic sequence.Both have a constant slope.Y = mx + b is an arithmetic sequence.Problem can be solved either by using arithmetic solution or by conventional interpolation methods.Using a ratio solution the number of points between the first point and the center is 5.5 steps and the number of points between the center and the last point is 5.5 steps.The ratio of the first half of the line is (5-1)/ 5.5 and the second half is (10-5)/5.5.Slope of the first half of the line is different from the second half.You need different ratio for first 6 points from last 6 points. – jdweng Aug 05 '18 at 01:00
  • @jdweng I like your solution. Thank you. There was another in that thread that seemed to work with odds and evens. What was wrong with that one? – Mini Aug 06 '18 at 00:21
  • This is not about odds and evens. You have two lines with different slopes. Each line has to be interpolated separately to get the expected answer. The 1st line is between the first two points and the 2nd line is between the last two points. There is no real correct answer to the problem because interpolation doesn't specify where the new points are located. Normally a new point is in the middle of the two existing points. I the expected results you are adding 5 points which are not centered between the two existing points. That is what I said in the other posting. – jdweng Aug 06 '18 at 07:10

0 Answers0