sp94 / cubicsplines.jl Goto Github PK
View Code? Open in Web Editor NEWCubic splines for Julia
License: Other
Cubic splines for Julia
License: Other
The REQUIRE file could not be found.
cc: @sp94
The REQUIRE file could not be found.
cc: @sp94
Hello,
I'm currently using CubicSplines.jl
together with the Unitful.jl
package. Since the CubicSpline
struct is currently restricted to vectors with real elements, this forces me to convert units to real numbers and back. Could we possibly remove the restriction to real elements (instead restricting it to numbers)?
We should add CI/CD for automatic testing and code coverage
There is the start of a travis.yaml file from #6, but fails on systems without matplotlib installed
@StefanMathis thanks very much for your pull request #5. I have a couple questions about some of the documentation
CubicSplines.jl
The extrapolation behaviour is defined by the coefficients of a 3rd degree
polynomial which can be given as additional keyword arguments extrapl and extrapr
to the constructor. extrapl and/or extrapr should be either "nothing" or a
set of coefficients.Case 1: Extrapolation is set to "nothing"
In this case, the default quadratic extrapolation according to section 2.3 of [1]
is used to construct the spline and the spline throws an error when evaluated
outside its boundaries.Case 2: Extrapolation is set to a vector
The container is given as a n-element collection of values:
extrapl = [p1, p2, p3, ..., pn]
which are used to evaluate the following function:
y = p0 + p1*(x-x3) + p2*(x-x3)^2 + p3*(x-x3)^3 + ... + pn*(x-x3)^n
The constant p0 is equal to y3 by definition (continuous spline). x3 and y3
are the first/last datapoint values respectively.
Does the first paragraph contradict the third paragraph? Should we remove "3rd degree" from the first line?
README.md
The example doesn't run (it doesn't include the xdata and ydata). Do you know what xdata and ydata were used?
Hello Samuel,
I just found that there is no new release of the package yet, which leads to Pkg still downloading the old version w/o extrapolation. Would you mind releasing a new version (v0.1.2)?
I discovered that the interpolated values given from CubicSplines.jl do not match those given by the R function aspline
for input values in the interval xs[end-1]
to xs[end]
It's not too hard to use a symmetry argument to see that the Julia splined value must be wrong, as set out in the script below. I believe the fix is at line 38 of CubicSplines.jl which should read:
for i in 1:length(ms)
rather than
for i in 1:length(ms)-1
using CubicSplines
using RCall
using Plots
#=CubicSplines2.jl is a copy of CubicSplines.jl with line 38 changed from:
for i in 1:length(ms)-1
to read instead:
for i in 1:length(ms)
=#
include("CubicSplines2.jl")
xs = collect(-2.0:2.0)
ys = mod.(xs, 2)
xin = collect(-2.0:0.5:2.0)
#=By symmetry about zero we should have result(+x) = result(-x)
But that's not true when x is in the interval xs[end-1] to xs[end]
CubicSplines.CubicSpline(xs, ys)[ 1.5] == 0.725
CubicSplines.CubicSpline(xs, ys)[-1.5] == 0.75
As a further check, compare against R's aspline https://www.rdocumentation.org/packages/akima/versions/0.6-2/topics/aspline
=#
j_res = CubicSplines.CubicSpline(xs, ys)[xin]
J_res = CubicSplines2.CubicSpline(xs, ys)[xin]
R_res = rcopy(rcall(:aspline, xs, ys, xin))[:y]
@show xin
@show j_res
@show J_res
@show R_res
@show all(j_res .== R_res)
@show all(J_res .== R_res)
plot(xin,j_res)
plot!(xin,R_res)
running that script:
xin = [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0]
j_res = [0.0, 0.75, 1.0, 0.5, 0.0, 0.5, 1.0, 0.725, 0.0]
J_res = [0.0, 0.75, 1.0, 0.5, 0.0, 0.5, 1.0, 0.75, 0.0]
R_res = [0.0, 0.75, 1.0, 0.5, 0.0, 0.5, 1.0, 0.75, 0.0]
all(j_res .== R_res) = false
all(J_res .== R_res) = true
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.