Cubic spline - return values for every row in source data?
masheroz
I have an algorithm which I want to use to minimise, and I want to fit a spline function. The nodes will be specified by me in another wave, but can be taken to be evenly spaced in the first instance (~20 nodes).
I've tried fitting a cubic spline, and I can only make it return values at the nodes.
I've tried fitting a smoothing spline. It returns values at every value, but I don't want to smooth the data, and the fit is too far off.
How can I fit a spline through the nodes and return the value of that spline for every point in the original source data?
I can then do a sum[(source-bkg)^2], and start minimising with my algorithm to refine the node positions.
Execute this:
The cubic spline algorithm returns a curve that goes through all of the input points. The smoothing spline is not constrained to go through all of the input points.
The cubic spline has no analytical value - it is useful only to produce a reasonably smooth curve through specific points. The smoothing spline also has no analytic value but it is better at producing a smoothed representation of the input data.
September 16, 2015 at 09:01 am - Permalink
No.
"In this mode the number of output points is determined by the destination wave and the /N flag is ignored."
Now I've just made a cubic spline go through every point of my data, not creating a smooth curve through a small number of nodes, for which I can then get the values of that smooth curve at every original x value in my original data.
I want to input my source and node waves and get back a spline wave with the same dimension as my source, where the spline was calculated through my nodes.
I can't see how to do that.
September 16, 2015 at 05:52 pm - Permalink
September 16, 2015 at 06:02 pm - Permalink
The workflow that I've come up with (and only briefly tested) is:
source_x & source_y - 1D waves containing x and y information. I want to fit the y data. ~2000 rows
node_x - 1D wave containing x positions at which I want to place my nodes. ~20 rows
node_y - Loop through node_x to lookup source_x to get the row to find the value of source_y **code below
interpolate2 /I=3 /X=source_x /Y=spline_y node_x, node_y
wave sx, sy, nx
make/O/N=(numpnts(nx)) node_y
variable i
for(i=0; i < numpnts(nx); i+=1)
node_y[i] = sy[sx[nx[i]]]
endfor
end
September 17, 2015 at 07:58 pm - Permalink
optimize x=W_nodesY chisquarefunction, w_data
In my experience this works, but for my application a smoothing spline achieves the same thing - see the spline option in my “Baseline Fitting” project for an example of how I implement it.
September 22, 2015 at 08:08 am - Permalink