spline

Non-monotonic interpolation methods

空扰寡人 提交于 2019-12-11 05:30:23
问题 I'm currently trying to interpolate curves through multiple dimensions (which just involves using interpolation methods on each dimension individually), and I'm a bit confused about the PCHIP (piecewise cubic hermite interpolation polynomial). Does the PCHIP only apply to monotonic data? The data I am interested in is necessarily non-monotonic, so I used a Catmull-Rom spline, but the PCHIP seems to fit my data better, but the off the shelf implementation of the PCHIP im using only works for

Rough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcv

泪湿孤枕 提交于 2019-12-11 04:37:27
问题 Background I am trying to replicate figure 2.6 in the book An Introduction to Statistical Learning: A rough thin-plate spline fit to the Income data from Figure 2.3. This fit makes zero errors on the training data. What have I tried so far? I tried to replicate the previous figure 2.5, a smooth thin-plate spline fit, not sure if succesfully. income_2 <- read.csv("http://www-bcf.usc.edu/~gareth/ISL/Income2.csv") library(mgcv) model1 <- gam(Income ~ te(Education, Seniority, bs=c("tp", "tp")),

How to implement a piecewise function and then plot it on certain intervals in MATLAB

≯℡__Kan透↙ 提交于 2019-12-11 04:08:21
问题 I am actually attempting to write code for the cubic spline interpolation. Cubic spline boils down to a series of n-1 segments where n is the number of original coordinates given initially and the segments are each represented by some cubic function. I have figured out how to get all the coefficients and values for each segment, stored in vectors a,b,c,d , but I don't know how to plot the function as a piecewise function on different intervals. Here is my code so far. The very last for loop

Smoothing Continuous 2D Points

纵饮孤独 提交于 2019-12-11 02:14:45
问题 UPDATE Thanks to @user20650 and @李哲源 Zheyuan Li, here is the solution I came up with: # Example data set: df # 3600 observations/points # Create a vector of the cumulative distances between all of the points require(Momocs) cumdist <- coo_perimcum(df) # Apply splines parametrically - define a spline interpolated mapping R --> R^2 of some curve c # c(t) = (x(t), y(t)) # 't' is the set of cumulative distances (as defined above) # Set the number of points to some fraction of the number of

Prediction using a natural spline fit

喜欢而已 提交于 2019-12-10 18:54:45
问题 I have a fitted a simple natural spline (df = 3) model and I'm trying to predict for some out of sample observations. Using the function predict() , I'm able to get fitted values for in-sample observations but I've not been able to get the predicted value for new observations. Here is my code: library(splines) set.seed(12345) x <- seq(0, 2, by = 0.01) y <- rnorm(length(x)) + 2*sin(2*pi*(x-1/4)) # My n.s fit: fit.temp <- lm(y ~ ns(x, knots = seq(0.01, 2, by = 0.1))) # Getting fitted values:

How to get the spline basis used by scipy.interpolate.splev

混江龙づ霸主 提交于 2019-12-09 19:00:55
问题 I need to evaluate b-splines in python. To do so i wrote the code below which works very well. import numpy as np import scipy.interpolate as si def scipy_bspline(cv,n,degree): """ bspline basis function c = list of control points. n = number of points on the curve. degree = curve degree """ # Create a range of u values c = cv.shape[0] kv = np.clip(np.arange(c+degree+1)-degree,0,c-degree) u = np.linspace(0,c-degree,n) # Calculate result return np.array(si.splev(u, (kv,cv.T,degree))).T Giving

finding inflection points in spline fitted 1d data

我怕爱的太早我们不能终老 提交于 2019-12-09 18:29:49
问题 I have some one dimensional data and fit it with a spline. Then I want to find the inflection points (ignoring saddle points) in it. Now I am searching the extrema of its first derivation by using scipy.signal.argrelmin (and argrelmax) on a lot of values generated by splev. import scipy.interpolate import scipy.optimize import scipy.signal import numpy as np import matplotlib.pyplot as plt import operator y = [-1, 5, 6, 4, 2, 5, 8, 5, 1] x = np.arange(0, len(y)) tck = scipy.interpolate.splrep

scipy: Interpolating trajectory

有些话、适合烂在心里 提交于 2019-12-09 05:50:59
问题 I have a trajectory formed by a sequence of (x,y) pairs. I would like to interpolate points on this trajectory using splines. How do I do this? Using scipy.interpolate.UnivariateSpline doesn't work because neither x nor y are monotonic. I could introduce a parametrization (e.g. length d along the trajectory), but then I have two dependent variables x(d) and y(d) . Example: import numpy as np import matplotlib.pyplot as plt import math error = 0.1 x0 = 1 y0 = 1 r0 = 0.5 alpha = np.linspace(0,

Plot a thin plate spline using scatterplot3d

本小妞迷上赌 提交于 2019-12-08 12:54:03
问题 Splines are still fairly new to me. I am trying to figure out how to create a three dimensional plot of a thin plate spline, similar to the visualizations which appear on pages 24-25 of Introduction to Statistical Learning (http://www-bcf.usc.edu/~gareth/ISL/ISLR%20Sixth%20Printing.pdf). I'm working in scatterplot3d, and for the sake of easily reproducible data, lets use the 'trees' dataset in lieu of my actual data. Setting the initial plot is trivial: data(trees) attach(trees) s3d <-

Parallelization of Piecewise Polynomial Evaluation

筅森魡賤 提交于 2019-12-07 22:33:54
问题 I am trying to evaluate points in a large piecewise polynomial, which is obtained from a cubic-spline. This takes a long time to do and I would like to speed it up. As such, I would like to evaluate a points on a piecewise polynomial with parallel processes, rather than sequentially. Code: z = zeros(1e6, 1) ; % preallocate some memory for speed Y = rand(11220,161) ; %some data, rand for generating a working example X = 0 : 0.0125 : 2 ; % vector of data sites pp = spline(X, Y) ; % get the