Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7121 Discussions

Data fitting cubic spline - failing with <=4 breakpoints

Towie__Ewan
New Contributor I
2,072 Views

Hi,

I'm aware that this question is close to that being asked in: https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/815604

I'm using an older version of MKL, version 11.0.5, and I am having problems with the use of the Akima cubic spline that I can't find any concrete answer for in the documentation.

I'm using a combination of boundary conditions on the spline, depending on the case, of either a fixed value to the 1st or 2nd derivative at the left and right edge (both left and right BC are always defined). I don't define any internal conditions, and I use a non-uniform partition for the x breakpoints.

The problem I am encountering is that if there is <= 4 breakpoints, the dfdConstruct1D method will fail with the error 'Error: the number of breakpoints is invalid (code -1004).'  At the moment, the code will enforce a linear interpolation of there are <= 2 breakpoints which I understood to be the minimum.

However, I can't seem to find anywhere in the documentation that the minimum number of breakpoints required for each cubic spline method is defined.

Can someone clarify what the minimum number of breakpoints required is for each of the methods, and how the BC's and/or IC's change this behaviour?

Thanks,

Ewan

0 Kudos
8 Replies
Alina_E_Intel
Employee
2,072 Views

Hi Ewan,

Construction of Akima spline requires at least 5 breakpoints as defined in “A New Method of Interpolation and Smooth Curve Fitting Based on Local Procedures” by Hiroshi Akima (Journal of the Association for Computing Machinery, Vol.17, No.4, October 1970 pp. 589-602), paragraph 2: The slope of the curve at each given point is determined locally by the coordinates of five points. For this reason, the library reports unsuccessful status code when number of breakpoints <= 4.

We will update Intel MKL Data Fitting documentation in one of future releases to make this information clear for all types of splines.

 

Thanks,

Alina

0 Kudos
Towie__Ewan
New Contributor I
2,072 Views

Hi Alina,

Is there any chance you could post the minimum number of breakpoints required for each type of spline here?

I am struggling to figure out which types can be used in different scenarios. For example, the natural cubic spline I have used in the past works with only 2 breakpoints, but in the MKL version the natural spline seems to require 3?

Thanks,

Ewan

0 Kudos
Alina_E_Intel
Employee
2,072 Views

Hi Ewan,

Here you can find minimal numbers of breakpoints for the different types of cubic splines:

Cubic Default    3 breakpoints
Cubic Natural    2 breakpoints (in case of not-a-knot boundary conditions: 3 breakpoints)
Cubic Hermite   3 breakpoints
Cubic Bessel     4 breakpoints
Cubic Akima      5 breakpoints
Cubic Hyman     4 breakpoints

As I mentioned before we will update Intel MKL Data Fitting documentation in the future releases.

Thank you for bringing this question, feel free to ask more.

Best regards,
Alina

0 Kudos
Towie__Ewan
New Contributor I
2,072 Views

Hi Alina,

If you are updating the documentation, it might be a good idea to change the include line from 'mkl.h' to 'mkl_df.h' within the Data FItting manual section. There only seems to be one place in the manual where it mentions that this is the minimum required include to get access to the DF functionality, at the start of chapter 15. For each and every description of the DF routines the required include section only mentions 'mkl.h' which is a bit misleading.

In many cases, incuding 'mkl.h' can result in a lot of linking conflicts if you are using an alternative library for some other numerical calculations (e.g LAPACK, BLAS, etc.).

Thanks,

Ewan

0 Kudos
Gennady_F_Intel
Moderator
2,072 Views

>> In many cases, including 'mkl.h' can result in a lot of linking conflicts if you are using an alternative library for some other numerical calculations (e.g LAPACK, BLAS, etc.).

Actually mkl.h includes all mkl's header files including mkl_df.h also. What kind of linking conflict do you see? Could you show more details and examples?

0 Kudos
Towie__Ewan
New Contributor I
2,072 Views

Hi Gennady,

I think you've misunderstood my point.

To get access to the Data Fitting routines the minimum include is mkl_df.h. There is no need to include the entirety of the MKL library by including mkl.h.

In my particular case, if I include mkl.h it causes a lot of linking conflicts as I include other numerical libraries elsewhere in my code that are redefined in MKL.

It's a little misleading to suggest in the manual that you need to include mkl.h when actually mkl_df.h is more than sufficient to access the DF routines.

Ewan

0 Kudos
Khoury__Pascal
Beginner
2,072 Views

Elizarova, Alina (Intel) wrote:

Hi Ewan,

Here you can find minimal numbers of breakpoints for the different types of cubic splines:

Cubic Default    3 breakpoints
Cubic Natural    2 breakpoints (in case of not-a-knot boundary conditions: 3 breakpoints)
Cubic Hermite   3 breakpoints
Cubic Bessel     4 breakpoints
Cubic Akima      5 breakpoints
Cubic Hyman     4 breakpoints

As I mentioned before we will update Intel MKL Data Fitting documentation in the future releases.

Thank you for bringing this question, feel free to ask more.

Best regards,
Alina

 

Hey,

I tried the provided example with MKL 'dfdhermitecubicspline.c' and I only changed the number of breakpoints from 7 to 3 but I get 'DF_ERROR_MEM_FAILURE' when calling dfdConstruct1D. It works with more than 3 breakpoints. Does the hermite interpolation only work with > 3 breakpoints?

 

Thanks

0 Kudos
Gennady_F_Intel
Moderator
2,072 Views

checked the problem with MKL 2020 and when the #breakppoins == 3

dfdhermitecubicspline.exe
Number of break points : 3

 i  x(i)        y(i)        y'(i)
 0 +0.000000   +0.000000   +1.884956
 1 +1.500000   +0.309017   -1.792699
 2 +3.000000   -0.587785   +1.524961

Coefficients are calculated for a polynomial of the form:

Pi(x) = Ai + Bi*(x - x(i)) + Ci*(x - x(i))^2 + Di*(x - x(i))^3
    where x(i) <= x < x(i+1)

Spline coefficients for Y:
 i    Ai            Bi            Ci            Di            P(x(i))       P(x(i+1))     P'(x(i))      P'(x(i+1))
 0   +0.000000     +1.884956     -0.906119     -0.142118     +0.000000     +0.309017     +1.884956     -1.792699
 1   +0.309017     -1.792699     +0.177889     +0.412444     +0.309017     -0.587785     -1.792699     +1.524961

  i    Sites       Spline value
                   Computed    Expected
  0   +1.391320   +0.485773   +0.485773
  1   +2.915025   -0.702936   -0.702936
  2   +1.377971   +0.505020   +0.505020
  3   +1.235440   +0.677742   +0.677742
  4   +0.228633   +0.381899   +0.381899
  5   +0.571236   +0.754588   +0.754588
  6   +2.980018   -0.617449   -0.617449
  7   +2.721153   -0.863813   -0.863813
  8   +0.987973   +0.840779   +0.840779
  9   +1.046622   +0.817321   +0.817321
 10   +0.535681   +0.727875   +0.727875
 11   +2.266246   -0.774634   -0.774634
 12   +0.839760   +0.859756   +0.859756
 13   +1.134457   +0.764735   +0.764735
 14   +1.326985   +0.573649   +0.573649


Computed Hermite cubic spline coefficients,  spline values are correct

0 Kudos
Reply