%matplotlib inline
%load_ext autoreload
# ! pip install git+https://github.com/avivajpeyi/pspline_psd.git -q
P-Spline Generation#
You can generate a p-spline basis using some set of knots using the following:
import numpy as np
from slipper.splines.p_splines import PSplines
import matplotlib.pyplot as plt
np.random.seed(42)
knots = np.linspace(0, 1, 5)
degree = 3
pspline = PSplines(knots, degree, )
weights = np.random.randn(pspline.n_basis)
pspline.plot(weights=weights)
plt.show()
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[2], line 2
1 import numpy as np
----> 2 from slipper.splines.p_splines import PSplines
3 import matplotlib.pyplot as plt
5 np.random.seed(42)
ModuleNotFoundError: No module named 'slipper'
knots = [0,0.3, 0.5,0.6,0.85, 1]
degree = 2
pspline = PSplines(knots, degree, diffMatrixOrder=1)
weights = np.array([0,0.4, 0.2,0.7,0,0.2,0])
pspline.plot(weights=weights)
plt.show()
