-3

I am experimenting with a open source code, which is based on learned index for DBMS indexing. Each index is considered as a model which predicts the position of the key in the dataset. I am trying to fit a quadratic regression model in place of linear regression. For the linear regression function of form y=ax+b, the spline connects points (xmax,ymax) and (xmin,ymin). x is the key value and y is the predicted position.CDF of position of keys is in the range of [0,1].

//Fitting linear spline

`if (mdl_->a_ <= 0) {` 
   `mdl_->a_ = (y_max_ - y_min_) / (x_max_ - x_min_);`
   `mdl_->b_ = -static_cast<double>(x_min_) * mdl_->a_; + y_min_`
 `}`

//Temporary model by in the range of CDF[0,1]

 `T min_key = values[0].first;`
 `T max_key = values[num_keys - 1].first;`
 `root_->mdl_.a_ = 1.0 / (max_key - min_key);`
 `root_->mdl_.b_ = -1.0 * min_key * root_node_->mdl_.a_;`

I suppose that in the temporary model, they have fitted ymin for 0 and ymax for 1. And I would like to find the coefficients of a quadratic function, by fitting a spline. Could someone please tell me whether how I could fit a quadratic spline using 2 points (min and max points)?

I tried using the interpolation formula. Quadratic spline interpolation

The predicted positions fit the parabola if the key values (x) are given sequentially. If the key values are given in random manner, the coefficient (c in ax2+bx+c) comes as very larger value which results in segmentation fault. And also the predicted positions don't fit the quadratic curve.

Nina
  • 1
  • 2
  • 3
    This is not really a SO question. You are asking a library suggestion and mathematical question in one. On SO please provide example code of what you have tried. – Bart Aug 16 '21 at 09:39
  • To be fair, the question may not be C/C++ related, nor even code related, but it is on a subject that shares a lot of maths with Computer Graphics, which is mostly written in C. – Tiger4Hire Aug 16 '21 at 10:32
  • Sorry. I forgot to attach the code. I shall add it – Nina Aug 16 '21 at 13:18
  • I am sorry for not framing the question properly. I am new to stack overflow. – Nina Aug 16 '21 at 13:36

1 Answers1

-2

Could someone please tell me whether how I could fit a quadratic spline using 2 points?

It is inherent to the maths of quadratic splines that you need four points, or two points and two vectors, to define a quadratic spline. The definitive text for this is Computer Graphics : Principles and practice

The most common interpretation for this problem is known as a Bezier Curve. It works by injecting two new points (known as control points) per pair of existing points. Each control point is calculated using the vector from each point, to the previous/next point. If there is no previous/next point, the control points are the just the points themselves. So with just two points, the Bezier-curve, is just a line. You will be using a complex way of getting what you already have.

Tiger4Hire
  • 1,065
  • 5
  • 11