功能数据之间的L2距离(曲线平滑)

索尔维格

我使用平滑创建了两个“函数” fd4和fd6。

fit6 <- smooth.basis(tid6, zbegfor, fdParobj2) 
fd6 <- fit6$fd 

曲线图

我想在间隔[0,1]上测量它们之间的L2距离,但我一直找不到合适的方法。

|| f − g || _2 = sqrt(int(| f(x)-g(x)| ^ 2,0,1))

最好的选择是:如何使用R计算函数L_2范数,但是当我使用fd6而不是时f <- function(x) x^2,会收到以下消息:

“ fac中的错误-fdmat:不一致的数组”。

我已经花费了数小时试图找到解决方案。请帮我!


现在具有可重现的代码:

library(fda)

# Smoothing of movement pattern without obstacle rescaled to the interval [0,1]
without <- c(22.5050173512478, 22.5038665040295, 22.5171851824298, 22.5368096190746, 
22.5770229184757, 22.6709727229898, 22.8195669635573, 23.0285400460222, 
23.3240853426905, 23.6895323912605, 24.0905709304813, 24.5674870961964, 
25.129085512519, 25.7433521858875, 26.4096817521118, 27.1338935155912, 
27.906416101033, 28.7207273157549, 29.5431756517467, 30.3697951466496, 
31.2214907341765, 32.0625307132683, 32.8786845916855, 33.671550678219, 
34.4449992914392, 35.1852293010227, 35.8866367048324, 36.5650863548079, 
37.1776116180247, 37.7706354957587, 38.3082855431959, 38.8044130844639, 
39.2471137254193, 39.6193031585418, 39.9685683244076, 40.2345560551869, 
40.4394442661545, 40.5712407258558, 40.6905311089523, 40.712419802203, 
40.6704560575084, 40.5583379372846, 40.3965425630546, 40.1443139907057, 
39.8421899334408, 39.4671160834355, 39.018733225651, 38.5381390971577, 
38.035680135599, 37.4625783280288, 36.8649362406917, 36.2320264206665, 
35.5599736527209, 34.8983871226943, 34.2058073957721, 33.4893682831911, 
32.7568501019309, 32.0241649500974, 31.3036406455137, 30.587636320768, 
29.8962657607091, 29.2297665999702, 28.6003939337949, 28.0003531206639, 
27.433551463149, 26.9088532545635, 26.4265682839796, 25.974193299003, 
25.5553146923473, 25.1701249455904, 24.8107813804098, 24.4776168601955, 
24.167582682288, 23.8726502760669, 23.589703789663, 23.3222235336882, 
23.0616248799115, 22.8185342685607, 22.6767541125512, 22.6567795841271, 
22.6488510112824, 22.6436058079441, 22.6391304188382)

timewithout <- (1:length(without))/length(without) # For scaling
splineBasis = create.bspline.basis(c(0,1), nbasis=25, norder=6) # The basis for smoothing
basis = fdPar(fdobj=splineBasis, Lfdobj=2, lambda=0.00001) 
fitwithout <- smooth.basis(timewithout, without, basis) # Smoothing
fdwithout <- fitwithout$fd 

# Same but movement is over an obstacle
with <- c(22.4731637093167, 22.4655561889073, 22.4853719755102, 22.4989400065304, 
22.5495656349031, 22.666945409755, 22.8368941117498, 23.0846080078369, 
23.4160560011242, 23.8285634914224, 24.2923085321078, 24.8297004047422, 
25.4884540279408, 26.2107053559, 27.0614232848574, 27.9078055119721, 
28.8449720096674, 29.8989669834473, 30.996962022701, 32.1343108758062, 
33.3286403418359, 34.6364870430171, 35.9105342483246, 37.1883582665643, 
38.467212668323, 39.7381525466373, 41.0395064969214, 42.3095531191294, 
43.5708069740233, 44.7881178787717, 45.9965529977777, 47.1643807808923, 
48.284786275036, 49.3593991064962, 50.3863035442644, 51.3535489662494, 
52.2739716491521, 53.1338828493223, 53.9521101656512, 54.7037562884229, 
55.3593092084143, 55.9567618011946, 56.4768579145271, 56.9251919073806, 
57.2971965985674, 57.5937987523734, 57.8158626068961, 57.9554856023804, 
58.009777126789, 57.9863251605612, 57.8932199088797, 57.6988126618694, 
57.4350394069443, 57.1112025796509, 56.7580579506751, 56.2680669960935, 
55.6963799946038, 55.0574070566765, 54.3592140352073, 53.6072275005723, 
52.7876353306759, 51.9172334605074, 50.9879178368431, 49.9953932631072, 
48.9460707853802, 47.8511977258834, 46.6827266395278, 45.4635999409637, 
44.2633368255294, 43.0386729762103, 41.7880095105045, 40.4834298069985, 
39.1610223705633, 37.9241872458281, 36.7158342529737, 35.5408830466013, 
34.4070964101159, 33.307156473109, 32.2514661493348, 31.2475129673168, 
30.2990631096187, 29.4096423238141, 28.590173995037, 27.8437368908309, 
27.17493959411, 26.5779670740351, 26.0377946174036, 25.5731202027558, 
25.1761397934058, 24.8319659155494, 24.5479180062239, 24.2940808334792, 
24.09388897537, 23.934861348149, 23.7999923744404, 23.6877461628934, 
23.5982309560843, 23.5207597985246, 23.4354446383638, 23.3604065265148, 
23.2819126915765, 23.1725048152396, 23.0637455648184, 22.9426779696074, 
22.8079176617495, 22.69360227086, 22.6622165457034, 22.6671302753094, 
22.66828206305, 22.6703162730529, 22.6715781657376)
timewith <- (1:length(with))/length(with)
fitwith <- smooth.basis(timewith, with, basis) # Smoothing
fdwith <- fitwith$fd 

# Plots for understanding
plot(fdwith, col=2) # Smoothed curve for movement over obstacle
plot(fdwithout, col=2, add = TRUE) # Same but no obstacle

# I have to find the L2-distance between these curves
朱利叶斯·维诺拉(Julius Vainora)

首先,可以利用对fd对象执行算术运算的可能性fdwith - fdwithout其次,也许是从提取值的更好的方式fd在特定点对象,但是这也适用:predict(newdata = 0.5, fdwith - fdwithout)所以,

sqrt(integrate(function(x) predict(newdata = x, fdwith-fdwithout)^2, lower = 0, upper = 1)$val)
# [1] 9.592434

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何根据距离平滑曲线

来自分类Dev

成对L2距离计算的优化

来自分类Dev

如何计算最佳拟合曲线与数据点之间的距离?

来自分类Dev

使用矩阵乘法用numpy计算L2距离

来自分类Dev

数据框平滑功能

来自分类Dev

两条曲线之间的距离

来自分类Dev

标记曲线之间的最大偏差/距离

来自分类Dev

绘制熊猫系列数据的平滑曲线

来自分类Dev

从输入数据点生成平滑曲线的算法

来自分类Dev

OpenVPN L2 / Tap丢失数据包

来自分类Dev

绘图中 3 个点之间的平滑曲线

来自分类Dev

Scipy:最大化内插曲线之间的距离

来自分类Dev

直线和曲线之间的区域(无功能)

来自分类Dev

R-通过我的数据点拟合平滑曲线

来自分类Dev

R-通过我的数据点拟合平滑曲线

来自分类Dev

使用cocos2d-x绘制平滑的Bezier曲线

来自分类Dev

如何在ARM Cortex-A7的内核之间划分L2缓存?

来自分类Dev

2个坐标之间的距离

来自分类Dev

2 gps点之间的距离

来自分类Dev

平滑Dymola中的曲线

来自分类Dev

按钮中的平滑曲线

来自分类Dev

具有三次贝塞尔曲线计时功能CSS的平滑圆形动画

来自分类Dev

测量数据框行之间的距离

来自分类Dev

Coq:(a :: L1) = (b :: L2) ⇒ a = b ∧ L1 = L2?

来自分类Dev

如何找到R中曲线的两点之间的整个距离?

来自分类Dev

使用动态数据创建“ L”形曲线

来自分类Dev

如何将平滑的Cspline曲线输出为数据文件

来自分类Dev

如何通过平滑曲线使用matplotlib plt.plot(df)表示图形中的数据?

来自分类Dev

2列行之间的Hausdorff距离