+ +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ Contents +
+ +
+
+
+
+
+ +
+ +
+
+
import numpy as np
+import matplotlib.pyplot as plt
+from scipy.interpolate import BSpline
+from sklearn.preprocessing import SplineTransformer
+
+
+
+
+
+
+
k = 2  # Grau da spline
+t = [0, 1, 2, 3, 4, 5, 6]
+c = [-1, 2, 0, -1]
+
+spl = BSpline(t, c, k)
+
+
+
+
+
+
+
print(dir(spl))
+
+
+
+
+
['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_ensure_c_contiguous', '_evaluate', 'antiderivative', 'axis', 'basis_element', 'c', 'construct_fast', 'derivative', 'extrapolate', 'integrate', 'k', 't', 'tck']
+
+
+
+
+
+
+
plt.plot(spl(np.arange(0, 6, 0.1)))
+plt.show()
+
+
+
+
+_images/Untitled_3_0.png +
+
+
+
+
spl.design_matrix
+
+
+
+
+
---------------------------------------------------------------------------
+AttributeError                            Traceback (most recent call last)
+/tmp/ipykernel_81029/3889434849.py in <module>
+----> 1 spl.design_matrix
+
+AttributeError: 'BSpline' object has no attribute 'design_matrix'
+
+
+
+
+
+
+
X = np.arange(0, 60).reshape(60, 1)
+spline = SplineTransformer(degree=4, n_knots=5)
+B = spline.fit_transform(X)
+plt.plot(B)
+plt.show()
+
+
+
+
+_images/Untitled_5_0.png +
+
+
+
+
from scipy.interpolate import make_interp_spline, BSpline
+import numpy as np
+x = np.linspace(0, np.pi * 2, 4)
+y = np.sin(x)
+k = 3
+
+bspl = make_interp_spline(xb
+                          , y, k=k)
+design_matrix = bspl.design_matrix(x, bspl.t, k)
+
+
+
+
+
---------------------------------------------------------------------------
+NameError                                 Traceback (most recent call last)
+/tmp/ipykernel_9874/634180188.py in <module>
+      5 k = 3
+      6 
+----> 7 bspl = make_interp_spline(xb
+      8                           , y, k=k)
+      9 design_matrix = bspl.design_matrix(x, bspl.t, k)
+
+NameError: name 'xb' is not defined
+
+
+
+
+
+
+
k = 2
+t = [-1, 0, 1, 2, 3, 4, 5, 6]
+x = [1, 2, 3, 4]
+design_matrix = BSpline.design_matrix(x, t, k).toarray()
+design_matrix
+
+
+
+
+
---------------------------------------------------------------------------
+AttributeError                            Traceback (most recent call last)
+/tmp/ipykernel_9874/3284528771.py in <module>
+      2 t = [-1, 0, 1, 2, 3, 4, 5, 6]
+      3 x = [1, 2, 3, 4]
+----> 4 design_matrix = BSpline.design_matrix(x, t, k).toarray()
+      5 design_matrix
+
+AttributeError: type object 'BSpline' has no attribute 'design_matrix'
+
+
+
+
+
+
+
a = [1, 2, 3, 4, 5]
+
+np.pad(a, (1, 1), '')
+
+
+
+
+
array([5, 1, 2, 3, 4, 5, 5])
+
+
+
+
+ + + + +
+ + + +
+
+ +
+
+ +