prove continuity of cubic regression spline - spline

How can I prove that the cubic regression spline y_i = α +
K+4∑k=2 β_kh_k(x_i) + e_i is continuous in the first and second derivative at the knots? I understand how to prove the property by expanding the equation for f(x)=β0+β1x+β2x2+β3x3+β4(x−ξ)3+ which is explained here:https://rstudio-pubs-static.s3.amazonaws.com/65563_d6411480e07b4aaaad9b484b66210497.html, but how can I extend the proof to K knots?

Related

Using least square to fit a parametric curve

I have a curve represented as a parametric function, z(t)=(x(t), y(t)), x=f(t), y=g(t). If I wanna find a approximate curve using least square(using polynomial funtions), am I supposed to get one for x and one for y or just one for z?
So the problem is like this: given a parametric curve r(t) = (x(t), y(t)), find a approximate cubic polynomial curve. I collect multiple points in x(t) and y(t) and then use least square to find a corresponding curve for x(t), y(t). The final approximate curve is like r'(t) = (x'(t), y'(t))

What is a Hessian matrix?

I know that the Hessian matrix is a kind of second derivative test of functions involving more than one independent variable. How does one find the maximum or minimum of a function involving more than one variable? Is it found using the eigenvalues of the Hessian matrix or its principal minors?
You should have a look here:
https://en.wikipedia.org/wiki/Second_partial_derivative_test
For an n-dimensional function f, find an x where the gradient grad f = 0. This is a critical point.
Then, the 2nd derivatives tell, whether x marks a local minimum, a maximum or a saddle point.
The Hessian H is the matrix of all combinations of 2nd derivatives of f.
For the 2D-case the determinant and the minors of the Hessian are relevant.
For the nD-case it might involve a computation of eigen values of the Hessian H (if H is invertible) as part of checking H for being positive (or negative) definite.
In fact, the shortcut in 1) is generalized by 2)
For numeric calculations, some kind of optimization strategy can be used for finding x where grad f = 0.

piecewise non linear cost function in cplex

Is it possible to model a non-linear piece-wise cost function in Cplex?
For example something like the figures I put here:
non linear piece wise Cost function (black line)
I know one way is to linearising the quadratic part to linear one, but, I want to use the quadratic part as it is.
You can see that the condition is on the decision variable itself, the cost function can be formulated as follows:
if x &#8818 x0 Then cost is quadratic part;
else cost is linear part.
Thanks in advance :)
One way is to pick the cheapest curve at x:
min cost
cost ≥ f(x) − Mδ
cost ≥ g(x) − M(1−δ)
δ ϵ {0,1}
M is a constant: the largest difference between the two curves (i.e. M=|f(xmax)−g(xmax)|). δ is a binary variable. I assumed we are minimizing cost and that the quadratic function is convex.
This construct implements
min cost
cost ≥ f(x) or cost ≥ g(x)
The solver will always drop the most expensive function, and keep the cheapest. In your picture this is exactly what we want: on the left of x0 the quadratic function is the cheapest, and on the right of x0, the linear function is cheaper. This formulation will automatically pick the cheaper option.

Subdivide multi segmented Cubic Bezier spline

First of let me apologies for a bad English and probably not very straight forward question, as I am not really sure how to call it.
I have a multi segmented Cubic Bezier curve In After Effects, it is is defined by 5 vertices with IN & OUT tangents. My task is to subdivide it into N small linear chunks in Java Script.
EDIT submited more info.
Given a multi segmented Cubic Bezier spline defined by 5 points with In & Out tangents, I need to get a linear representation of it. Where N is number of linear segments, defined by user.
Cubic Bezier Spline:
Segment1: P0, P0out, P1in, P1;
Segment2: P1, P1out, P2in, P2;
Segment3: P2, P2out, P3in, P3;
Segment4: P3, P3out, P4in, P4;
Expected output:
N = 1: linear spline with 2 anchors representing entire shape;
N = 2: linear spline with 3 anchors representing entire shape;
N = 3: linear spline with 4 anchors representing entire shape;
N = 4: linear spline with 5 anchors representing entire shape;
...
N = 8: linear spline with 9 anchors representing entire shape;
distance(L0,L1) = distance(L1,L2) = distance(L2,L3) = ... = distance(L-n, Ln)
In example image I use 4-segmented spline, where segment length is equal to one another - this is just easier to draw to explain my task. But in real project those segments will not be equal, and there will be more then 4 segments total.
I have looked at de Casteljau method, but as I can understand, it works with one segment spline. My math skills are dusty, so I am not really sure if I can use de Casteljau in my example.
This is conceptually straight forward, although it might involve quite a bit of code for reasons explained a little later on. What you're trying to do is flatten a (cubic) poly-Bezier, so let's start with that:
Individual cubic Bezier curves are generated by four points: a start point, a control point that determines the tangent at the start point, an end point, and a control point that determines the tangent at the end point. The curve, then, is a plot of the cubic Bezier function:
Bx(t) = p1.x × (1-t)³ + 2 × p2.x × (1-t)² × t + 2 × p3.x × (1-t) × t² + p4.x × t³
By(t) = p1.y × (1-t)³ + 2 × p2.y × (1-t)² × t + 2 × p3.y × (1-t) × t² + p4.y × t³
A single Bezier curve is plotted over the interval t=[0,1], so a poly-Bezier of N segments is plotted over a total interval N × [0,1].
First, the simple case: simple flattening. Bezier curves are non-linear curves and so let's first not bother to enforce "same length for each of the line segments". Given an N-segment poly-Bezier:
S = number of segments we want
points = empty list
for (s = 0):(s = S):(step = S/N):
v = s * step
segmentid = floor(v)
segment = polycurve.segments[segmentid]
t = v % 1
points.push(
segment.pointAt(t)
)
We now have all the points we need, and we just connect them with lines. Done.
However, Bezier curves are non-linear curves, so flattening in this way does not yield equidistant segments in the slightest. If we want to do that, we need to work with distance along the curve rather than t values.
S = number of segments we want
points = empty list
for (s = 0):(s = S):(step = S/N):
v = s * step
segmentid = floor(v)
segment = polycurve.segments[segmentid]
distanceRatio = v % 1
t = segment.getTforDistanceRatio(distanceRatio)
points.push(
segment.pointAt(t)
)
This will work exactly as you want, but getTforDistanceRatio is the hard part, because what we're doing here is reparameterizing the curve for distance, rather than time, and that is a very hard mathematical problem (for which no general symbolic solution exists). The cheapest way to do this is using a Lookup Table (LUT), which is explained in the link above, for "distance along the curve".
The de Casteljau method is used to compute a point on the Bezier curve and also obtain the control points for the two subdivided curves in the process. So, yes you should be able to use de Cateljau method to evaluate as many points as you want on a Bezier curve if you know the control points.
From the picture you show and the fact that your "cubic Bezier spline" takes in/out tangents as input, I think your spline is actually "cubic Hermite spline", in which each segment is indeed a cubic Bezier curve. You can convert each segment of your spline to a cubic Bezier curve, then use de Cateljau method to evaluate as many points as you want, then connect these points by straight lines.

How do Catmull-Rom and Hermite splines relate?

I'm a little confused as to how they relate. From my class, my professor asked how to fit C1 continuous piecewise Hermite curves to x amount of points with automatically computed tangents. Can someone explain how this works?
Hermite spline is a method of representation of cubic curve with two endpoints and two tangent vectors at these endpoints.
Note that there are many approaches to represent the same curve- power basis (at^3+bt^2+ct+d), Bernstein polynomials (for Bezier curves) and so on.
Catmull-Rom spline is a method of construction of a cubic curve (C1 continuous, if some pieces used). Every Catmull-Rom segment is a Hermite spline. If we want to represent a Catmull-Rom spline for the P1-P2 segment of the (P0,P1,P2,P3) point sequence as a Hermite one, we just use P1 and P2 as endpoints, and V1 and V2 as tangent vectors, where
V1 = tau * (P2-P0)
V2 = tau * (P3-P1)
(good article here)
and tau is parameter of tension (rigidness)