KindXiaoming / pykan

Kolmogorov Arnold Networks
MIT License
15.02k stars 1.38k forks source link

issue of API_3_grid #361

Open Fei0823 opened 3 months ago

Fei0823 commented 3 months ago

when i run this section of codes, thr following error arise. image Then, i chaged model.act_fun[0].coef[0].shape[0] to model.act_fun[0].coef[0].shape[1], it equals to G+k. However, the following error occurs image

kobyzev-yuri commented 3 months ago

I also have this problem with this tutorial code like you show and try to use only 8 B-basis (G-k=8) instead of (G+k=14) in formula and code after 1st cell, i got result which do not use ALL coefficients, but first 8. It is interesting what exactly coefficients have we use with B-basis?

image

kobyzev-yuri commented 3 months ago

In https://scikit-learn.org/stable/auto_examples/linear_model/plot_polynomial_interpolation.html we can read that there is also k = 3 "technical knots" from each side of fitted interval. I suppose here something like that and 6 knots are technical, so 8+6=14 and 14 means with additional tech knots I try to check this and get coefficients in 3 variants: from 0, from 3 and from 6. And best fit was "shift 3): image

kobyzev-yuri commented 3 months ago

Is it possible to use spline coefficients for KAN model activation in way compatible with scipy.interpolate.BSplin? :

G = ... k = 3 grid = torch.linspace(-1,1,steps=G+1)[None,:] ... coef = model.act_fun[0].coef

and than use coef and grid something like that:

from scipy.interpolate import BSpline spline_output = BSpline(grid, coef, k)

KindXiaoming commented 3 months ago

the grid parameter has changed a lot. So the current API_3_grid can't work. I'll have an update soon.