Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The loss doesn't decrease #243

Closed
leoq276 opened this issue May 30, 2024 · 2 comments
Closed

The loss doesn't decrease #243

leoq276 opened this issue May 30, 2024 · 2 comments

Comments

@leoq276
Copy link

leoq276 commented May 30, 2024

I tested how well KAN fits some simple functions and found that in some cases the training and testing losses do not decrease.

For example:

from kan import *
model = KAN(width=[2,5,1], grid=5, k=3, seed=0)
f = lambda x: x[:,0] + x[:,1]
dataset = create_dataset(f, n_var=2)
# train the model
result = model.train(dataset, opt="LBFGS", steps=20);
# loss
plt.plot(res['train_loss'], label='Train')
plt.plot(res['test_loss'], label='Test')
plt.legend()

loss

This is also true for f = lambda x: torch.sqrt(x[:,0]**2 + x[:,1]**2), f = lambda x: x[:,0]**2 + x[:,1]**2 and some other cases.

I have tried to change some of the parameters ,including width, grid, opt, lr, 'lamb, lamb_l1` but it didn't work.

@KindXiaoming
Copy link
Owner

KindXiaoming commented May 30, 2024

Hi, please change

f = lambda x: x[:,0] + x[:,1] to

f = lambda x: x[:,[0]] + x[:,[1]]. I apologize this could be a bit confusing.

@leoq276
Copy link
Author

leoq276 commented May 31, 2024

Thank you so much! It turns out using f = lambda x: x[:,0] + x[:,1] creates the label with shape [1000] and f = lambda x: x[:,[0]] + x[:,[1]] creates the label with shape [1000, 1].

@leoq276 leoq276 closed this as completed May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants