'BSpline process from R to Python
I have a some code that performs smoothing process using BSpline and fdPar functions. Below is the process:
Start to process
norder = 6, which is 1 more than degree of Bspline.
Setup the spline base Object - basisobj.
rangval <- c(1, length(data))
breaks = seq(1,length(data),length.out=length(data)/60)
nbasis = length(breaks) - 2 + norder
basisobj = create.bspline.basis(rangval,nbasis,norder=norder,breaks=breaks)
- Define a Functional Parameter Object - fdParobj
fdParobj = fdPar(basisobj)
- Define a fdobj
fdobj = smooth.basis(timepoints,data,fdParobj)
- predict
I am trying to convert the code / process above into Python.
I have been able to perform the BSpline to some extent. See below:
from scipy.interpolate import BSpline
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import math
breaks = np.linspace(1, (len(pressure_data)), math.ceil(len(pressure_data)/60))
k = math.ceil(len(pressure_data)) - 2
degree = 5
order = degree + 1
n = order + k
t = np.zeros(math.ceil(len(pressure_data)/60) + (2*order)) # create an array for knots
t[:order] = 0
t[-order:] = len(pressure_data)
t[order:-order] = (breaks )
xx = np.arange(len(pressure_data))
for i in range(0,n):
c = np.zeros(n)
c[i] = 1
spl = BSpline(t,c,degree)
plt.plot(xx, spl(xx))
plt.show()
However, I am trying to figure out how to convert the remaining (Step 3 and 4) into Python. Any help will be much appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
