b-splines for drawing, not predicting, based on control path

坚强是说给别人听的谎言 提交于 2019-12-14 01:58:47

问题


I've tried to approach my general problem through two separate questions here on SO: Specify clamped knot vector in bs-call and Fit a B spline to a control path. The responses to these have led me to a reformulation of the bigger problem, which I'm now posting.

What I'm trying to accomplish is (in R), given a set of (non-monotonous) control points, how do I draw a b-spline along the path given by the control points. The b-spline must be clamped in both ends. This is purely for graphical purpose.

NOTE: I'm not trying to predict values based on the control points. Using a combination of predict, lm and bs as proposed in Fit a B spline to a control path results in a b spline that tries to pass through the control points (which is not the point) - especially if setting df or knots so that the spline is clamped, this approach leads to overfitting and the spline will pass through every control point.

In the end the approach will be applied to 100s or 1000s of separate sets of control points so algorithmic efficiency is a factor, though currently I'm just looking for a way to get it done.

toy data (same as in the linked questions):

path <- data.frame(
    x = c(3, 3.5, 4.6875, 9.625, 5.5625, 19.62109375, 33.6796875, 40.546875, 36.59375, 34.5, 33.5, 33),
    y = c(0, 1, 4, 5, 6, 8, 7, 6, 5, 2, 1, 0)
)

All of this is for the purpose of calculating Hierarchical Edge Bundles in R.

EDIT:

Okay, so it seems that I'm unable to access the underlying b-spline implementation that is used under the hood (Or maybe I didn't try hard enough). Anyway I ended up crafting my own Rcpp based implementation inspired by Jason Yu-Tseh Chi's de Boor algorithm. The upside of this was that I could make it vectorised so multiple paths could be constructed in one go. This will be part of an upcoming CRAN package (hierarchicalSets), but I'll be happy to share it with anyone expressing interest in the meantime (too long to post here)...

UPDATE:

For anyone interested in this, spline drawing will be implemented as a geom/stat extension to ggplot2 in the ggforce extension package

来源:https://stackoverflow.com/questions/33650171/b-splines-for-drawing-not-predicting-based-on-control-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!