spline

How to save and load spline interpolation functions in R?

坚强是说给别人听的谎言 提交于 2019-12-02 05:08:05
I need to create thousands and thousands of interpolation splines, each based on 5 pairs of (x, y) values. I would like to save them in a database (or csv file). How can I export / import them, say in a text format or as an array of real parameters to rebuild each function when I need them? If you are using the splinefun function from R base package stats , it is very easy to export its construction information. set.seed(0) xk <- c(0, 1, 2) yk <- round(runif(3), 2) f <- splinefun(xk, yk, "natural") ## natural cubic spline construction_info <- environment(f)$z str(construction_info) # $ method:

catmull-rom splines for Android

给你一囗甜甜゛ 提交于 2019-12-02 03:32:33
问题 I'm trying to find a way to implement catmull-rom splines on the android platform for the purpose of smoothly drawing a line through n points. Ideally I would be able to adapt cubic beziers via the Path and its cubicTo method as alluded to in this thread: How do I draw a curve through tree points in Android? Unfortunately, I wasnt able to follow the implementation there so I'm hoping somebody out there has already done this and can share a few lines of sample code. Thanks! 回答1: This game

LibGDX Path (CatmullRomSpline) Constant Speed

只谈情不闲聊 提交于 2019-12-01 20:40:15
问题 I’m trying to achieve constant speed on a path using the LibGDX CatmullRomSpline and I’m having problems getting it to work. I’ve tried researching on this topic a lot including reading the LibGDX wiki, but their explanation for achieving constant speed doesn’t really make sense and I wasn’t able to get their method to work. https://github.com/libgdx/libgdx/wiki/Path-interface-&-Splines In my case, the derivative values are very large (in the hundreds) so when dividing a number between 0-1 by

smooth.spline(): fitted model does not match user-specified degree of freedom

折月煮酒 提交于 2019-12-01 18:36:34
问题 Here is the code I ran fun <- function(x) {1 + 3*sin(4*pi*x-pi)} set.seed(1) num.samples <- 1000 x <- runif(num.samples) y <- fun(x) + rnorm(num.samples) * 1.5 fit <- smooth.spline(x, y, all.knots=TRUE, df=3) Despite df=3 , when I checked the fitted model, the output was Call: smooth.spline(x = x, y = y, df = 3, all.knots = TRUE) Smoothing Parameter spar= 1.499954 lambda= 0.002508571 (26 iterations) Equivalent Degrees of Freedom (Df): 9.86422 Could someone please help? Thanks! 回答1: Note that

smooth.spline(): fitted model does not match user-specified degree of freedom

非 Y 不嫁゛ 提交于 2019-12-01 18:17:10
Here is the code I ran fun <- function(x) {1 + 3*sin(4*pi*x-pi)} set.seed(1) num.samples <- 1000 x <- runif(num.samples) y <- fun(x) + rnorm(num.samples) * 1.5 fit <- smooth.spline(x, y, all.knots=TRUE, df=3) Despite df=3 , when I checked the fitted model, the output was Call: smooth.spline(x = x, y = y, df = 3, all.knots = TRUE) Smoothing Parameter spar= 1.499954 lambda= 0.002508571 (26 iterations) Equivalent Degrees of Freedom (Df): 9.86422 Could someone please help? Thanks! Note that from R-3.4.0 (2017-04-21), smooth.spline can accept direct specification of λ by a newly added argument

define numerical evaluation of a derivative of a sympy function

一笑奈何 提交于 2019-12-01 00:46:23
How can I define the numerical evaluation of a derivative of a function in sympy? I have some functions I can describe with splines for the function and it's derivative using scipy.interpolate. I want to manipulate some expressions with this function and then evaluate the expressions with the splines. I can use lambdify to make a sympy function evaluate numerically as a spline. But how can I define the derivative of a sympy function to evaluate numerically as a spline? E.g. import sympy as sp import numpy as np from scipy.interpolate import InterpolatedUnivariateSpline from sympy.ultilitis

Replacing all NAs with smoothing spline

元气小坏坏 提交于 2019-11-30 21:32:00
Below is the sample data (out of approximately 8000 rows of data). How can I replace all NAs with values from a smoothing spline fit to the rest of the data? Date Max Min Rain RHM RHE 4/24/1981 35.9 24.7 0.0 71 37 4/25/1981 36.8 22.8 0.0 62 40 4/26/1981 36.0 22.6 0.0 47 37 4/27/1981 35.1 24.2 0.0 51 39 4/28/1981 35.4 23.8 0.0 61 47 4/29/1981 35.4 25.1 0.0 67 43 4/30/1981 37.4 24.8 0.0 72 34 5/1/1981 NA NA NA NA NA 5/2/1981 39.0 25.3 NA NA 55 5/3/1981 35.9 23.0 0.0 68 66 5/4/1981 28.4 22.4 0.7 70 30 5/5/1981 35.5 24.6 0.0 47 31 5/6/1981 37.4 25.5 0.0 51 31 I'm using some simplified data for the

define numerical evaluation of a derivative of a sympy function

旧时模样 提交于 2019-11-30 19:38:32
问题 How can I define the numerical evaluation of a derivative of a function in sympy? I have some functions I can describe with splines for the function and it's derivative using scipy.interpolate. I want to manipulate some expressions with this function and then evaluate the expressions with the splines. I can use lambdify to make a sympy function evaluate numerically as a spline. But how can I define the derivative of a sympy function to evaluate numerically as a spline? E.g. import sympy as sp

Replacing all NAs with smoothing spline

拟墨画扇 提交于 2019-11-30 17:10:12
问题 Below is the sample data (out of approximately 8000 rows of data). How can I replace all NAs with values from a smoothing spline fit to the rest of the data? Date Max Min Rain RHM RHE 4/24/1981 35.9 24.7 0.0 71 37 4/25/1981 36.8 22.8 0.0 62 40 4/26/1981 36.0 22.6 0.0 47 37 4/27/1981 35.1 24.2 0.0 51 39 4/28/1981 35.4 23.8 0.0 61 47 4/29/1981 35.4 25.1 0.0 67 43 4/30/1981 37.4 24.8 0.0 72 34 5/1/1981 NA NA NA NA NA 5/2/1981 39.0 25.3 NA NA 55 5/3/1981 35.9 23.0 0.0 68 66 5/4/1981 28.4 22.4 0.7

R smooth.spline(): smoothing spline is not smooth but overfitting my data

我们两清 提交于 2019-11-30 14:08:47
I have several data points which seem suitable for fitting a spline through them. When I do this, I get a rather bumpy fit, like overfitting, which is not what I understand as smoothing. Is there a special option / parameter for getting back the function of a really smooth spline like here . The usage of the penalty parameter for smooth.spline didn't have any visible effect. Maybe I did it wrong? Here are data and code: results <- structure( list( beta = c( 0.983790622281964, 0.645152464354322, 0.924104713597375, 0.657703886566088, 0.788138034115623, 0.801080207252363, 1, 0.858337365965949, 0