0

So - edited because some of us thought that this question is off-topic.

I need to build spline (approximation) on 100 points in one of environments listed in tags. But I need it with exact number of intervals (maximum of 6 intervals - separate equations - in whole domain). Packages / libraries in R and Maxima which I know let me for building spline on this points but with 25-30 intervals (separate equations). Does anyone know how to build spline with set number of intervals without coding whole algorithm all over again?

bpop
  • 17
  • 2
  • 2
    a spline with exact number of segment? I do not understand this unclear sentence, can you reformulate? By the way typing something like 'R spline' in any web search engine will lead you to this kind of page https://stat.ethz.ch/R-manual/R-devel/library/stats/html/smooth.spline.html.... – Colonel Beauvel Apr 22 '15 at 09:05
  • Same as @colonel-beauvel I do not understand your exact problem, but the basics of spline interpolation in Scilab are given [here](http://wiki.scilab.org/Overview%20of%20interpolation%20in%20Scilab) – spoorcc Apr 22 '15 at 10:54
  • Perhaps if you added a simple example [How to Make a Reproducible Example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) to you post, it would help clarify things. – WaltS Apr 22 '15 at 12:43
  • Thanks for your interest. Maybe I used wrong word for it. I mean that I can use spline which consists only e.g. ten polynomials. I have 100 points and I want to build spline on it, but it has to consist at a maximum ten polynomials in that domain. – bpop Apr 22 '15 at 12:51
  • Default method in maxima gave me a spline with about 25 sections. – bpop Apr 22 '15 at 13:39
  • By the way, what function did you use in Maxima? – Robert Dodier Apr 22 '15 at 21:34
  • For building a spline: cspline. – bpop Apr 23 '15 at 08:46

1 Answers1

1

What you're looking for might be described as "local regression" or "localized regression"; searching for those terms might turn up some hits.

I don't know if you can find exactly what you've described. But implementing it doesn't seem too complicated: (1) Split the domain into N intervals (say N=10). For each interval, (2) make a list of the data in the interval, (3) fit a low-order polynomial (e.g. cubic) to the data in the interval using least squares.

If that sounds interesting to you, I can go into details, or maybe you can work it out yourself.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • Thanks for your response. I considered this approach but it would probably result in discontinuities on bounds of intervals. – bpop Apr 22 '15 at 18:02
  • Yes, you're right. You will have to put in constraints to make the ends match up. I can think of 2 ways to do that. (1) Add a term for each pair of matched ends which penalizes the difference between p[i - 1](m[i]) and p[i](m[i]) where p[i - 1] and p[i] are the polynomials on the left and right sides of the match point m[i]. This is a so-called soft constraint. It is less exact but easier to handle. (2) Constrained minimization of sum of squares via augmented Lagrangian method or some other method for constrained optimization. I believe this isn't too hard. I will describe it if you want. – Robert Dodier Apr 22 '15 at 19:26
  • But then I'll have to code everything by myself, right? I'll not be able to add these constraints to some method implemented in one of environments listed in tags. – bpop Apr 22 '15 at 20:22
  • Maxima has an implementation of the augmented Lagrangian method. It is actually not very complicated -- it amounts to adding a variable penalty term to the function to be minimized and then repeatedly minimizing function + penalty, such that it converges to a minimum of function satisfying the constraints. – Robert Dodier Apr 22 '15 at 20:30
  • So, what I think that you're trying to suggest me to do: 1. Split the domain (a set of points) into smaller sets. 2. Use kind of procedure: augmented_lagrangian_method(lsquares_estimates (matrix, [x,y], y = a*x*x*x + b*x*x + c*x + d, [a, b, c, d]), [a, b, c, d], CONSTRAINT, [a0, b0, c0, d0]), where CONSTRAINT : y(endOfTheSegment) = yCoordinateOfTheBandPoint Am I right? ;) – bpop Apr 23 '15 at 08:54
  • @bpop Yes, but I think some details would have to be changed -- maybe you mean lsquares_mse instead of lsquares_estimates, and for the constraints, I think you want cubic[i](foo) = cubic[i + 1](foo) where cubic[i] is the i'th function and foo = midpoint between max(i'th x data) and min((i + 1)'th x data). To be honest, I am trying that right now, and I am having trouble getting it to work. So I can't really recommend this approach. Perhaps you'll be able to find an existing library, or take a different approach. Good luck and let us know here how it turns out. – Robert Dodier Apr 23 '15 at 17:27
  • So I've found an already programmed solution for my problem. ...Invented in 1991. :) It is called MARS - Multivariate adaptive regression splines R package called earth: http://cran.r-project.org/web/packages/earth/index.html Matlab toolbox called ARESLab: http://www.cs.rtu.lv/jekabsons/regression.html Thanks Robert for your interest in the problem. – bpop May 01 '15 at 22:33
  • Terrific, thanks for the update. I heard of MARS long ago and I didn't connect it to your problem. – Robert Dodier May 01 '15 at 22:43