src.environment.problem.SOO.COCO_BBOB.kan.spline¶
Module Contents¶
Functions¶
evaludate x on B-spline bases |
|
converting B-spline coefficients to B-spline curves. Evaluate x on B-spline curves (summing up B_batch results over B-spline basis). |
|
converting B-spline curves to B-spline coefficients using least squares. |
|
extend grid |
API¶
- src.environment.problem.SOO.COCO_BBOB.kan.spline.B_batch(x, grid, k=0, extend=True, device='cpu')[source]¶
evaludate x on B-spline bases
Args:¶
x : 2D torch.tensor inputs, shape (number of splines, number of samples) grid : 2D torch.tensor grids, shape (number of splines, number of grid points) k : int the piecewise polynomial order of splines. extend : bool If True, k points are extended on both ends. If False, no extension (zero boundary condition). Default: True device : str devicde
Returns:¶
spline values : 3D torch.tensor shape (batch, in_dim, G+k). G: the number of grid intervals, k: spline order.
Example¶
from kan.spline import B_batch x = torch.rand(100,2) grid = torch.linspace(-1,1,steps=11)[None, :].expand(2, 11) B_batch(x, grid, k=3).shape
- src.environment.problem.SOO.COCO_BBOB.kan.spline.coef2curve(x_eval, grid, coef, k, device='cpu')[source]¶
converting B-spline coefficients to B-spline curves. Evaluate x on B-spline curves (summing up B_batch results over B-spline basis).
Args:¶
x_eval : 2D torch.tensor shape (batch, in_dim) grid : 2D torch.tensor shape (in_dim, G+2k). G: the number of grid intervals; k: spline order. coef : 3D torch.tensor shape (in_dim, out_dim, G+k) k : int the piecewise polynomial order of splines. device : str devicde
Returns:¶
y_eval : 3D torch.tensor shape (number of samples, in_dim, out_dim)
- src.environment.problem.SOO.COCO_BBOB.kan.spline.curve2coef(x_eval, y_eval, grid, k, lamb=1e-08)[source]¶
converting B-spline curves to B-spline coefficients using least squares.
Args:¶
x_eval : 2D torch.tensor shape (in_dim, out_dim, number of samples) y_eval : 2D torch.tensor shape (in_dim, out_dim, number of samples) grid : 2D torch.tensor shape (in_dim, grid+2*k) k : int spline order lamb : float regularized least square lambda
Returns:¶
coef : 3D torch.tensor shape (in_dim, out_dim, G+k)