This repository was archived by the owner on Nov 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
Possible error in Special.BSpline function #129
Copy link
Copy link
Closed
Description
It seems that there is an error in the BSpline function in the Special.cs file.
There may be a mismatch between the definition stated here : http://crsouza.com/2010/03/kernel-functions-for-machine-learning-applications/#bspline and the implementation on the Special class.
Original code :
/// <summary>
/// Computes the Basic Spline of order <c>n</c>
/// </summary>
public static double BSpline(int n, double x)
{
// ftp://ftp.esat.kuleuven.ac.be/pub/SISTA/hamers/PhD_bhamers.pdf
// http://sepwww.stanford.edu/public/docs/sep105/sergey2/paper_html/node5.html
if (n == Int32.MaxValue)
throw new ArgumentOutOfRangeException("n");
double a = 1.0 / Special.Factorial(n); // <= preloading the 1/n!... ok
double c;
bool positive = true;
for (int k = 0; k <= n + 1; k++)
{
c = Binomial(n + 1, k) * Tools.TruncatedPower(x + (n + 1.0) / 2.0 - k, n);
a += positive ? c : -c; // <= Then here you sum the n+1 parts of the formula which shouldn't be added to the 1/n! preload
positive = !positive;
}
return a; // <= returned "a" which does not correspond to the stated formula
}
Code should look like this :
/// <summary>
/// Computes the Basic Spline of order <c>n</c>
/// </summary>
public static double BSpline(int n, double x)
{
// ftp://ftp.esat.kuleuven.ac.be/pub/SISTA/hamers/PhD_bhamers.pdf
// http://sepwww.stanford.edu/public/docs/sep105/sergey2/paper_html/node5.html
if (n == Int32.MaxValue)
throw new ArgumentOutOfRangeException("n");
double a = 0.0; // Preload a with 0
double c;
bool positive = true;
for (int k = 0; k <= n + 1; k++)
{
c = Binomial(n + 1, k) * Tools.TruncatedPower(x + (n + 1.0) / 2.0 - k, n);
a += positive ? c : -c; // Sum terms over k
positive = !positive;
}
return 1.0 / Special.Factorial(n) * a; // Finally apply the 1/n! factor
}
What do you think ? I hope I'm not misunderstanding anything...
Metadata
Metadata
Assignees
Labels
No labels