Open drdozer opened 4 months ago
This is a kind of dimension mismatching error, i fixed it in your code.
Here is something i also didn't get quite understand here
the parameters of B_batch
it wrote below, but actaully grid's shape is not what it says here. it looks like (number of samples, number of grid points), which seems a bit non sense.
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)
now you have x with its shape (1,40), so the grid's shape cannot be (1,11). i changed it to shape (40,11)
Here is the code, i had run it without error now
import torch
import numpy as np
import math
from kan.spline import coef2curve
def exp_sin(x):
return np.exp(np.sin(math.pi * x))
train_xs = np.arange(-5.,5.,0.25)
train_ys = exp_sin(train_xs)
t_xs = torch.reshape(torch.from_numpy(train_xs).float(), (1,len(train_xs)))
num_spline = 1
num_sample = len(train_xs)
num_grid_interval = 10
k = 3
grids = torch.einsum('i,j->ij', torch.ones(t_xs.shape[1],), torch.linspace(-1.,1.,steps=num_grid_interval+1))
coef = torch.normal(0.,1.,size=(grids.shape[0], num_grid_interval+k, num_grid_interval-k))
print(f"Shape of t_xs: {t_xs.shape}")
print(f"Shape of grids: {grids.shape}")
print(f"Shape of coef: {coef.shape}")
t_ys = coef2curve(t_xs, grids, coef, k=k)
Hi. Thanks for making the KAN code available. I've been trying to understand how it all works, and was trying to run coef2curve to get an idea of how the splines are calculated. However, I couldn't get it to run.
This barfs with an error related to shapes:
I don't understand the code well enough to grasp what's going wrong here. It seems like some mismatch between the dimensionality of the grid and coefficients? I think I've stuck close to a copy-paste of your example, so unsure why it doesn't work.