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

Fix the lock.png not found issue in model.plot #266

Merged
merged 3 commits into from
Jun 13, 2024

Conversation

Animadversio
Copy link
Contributor

Thanks for the amazing repo and research, super inspiring!

It seems that in the original pykan the lock.png is not included in the distribution. Due to this model.plot(.) could generate file not found error at the line

im = plt.imread(f'{folder}/lock.png')

image

I think the lock.png need to be included in the distribution to be load and plotted properly.

Minimal code to reproduce the issue in a Colab notebook

!pip install pykan

from kan import KAN, create_dataset
# initialize KAN with G=3
model = KAN(width=[2,1,1], grid=10, k=3)
# create dataset
f = lambda x: (x[:,[0]]+x[:,[1]])/(1+x[:,[0]]*x[:,[1]])
dataset = create_dataset(f, n_var=2, ranges=[-0.9,0.9])

model.train(dataset, opt="LBFGS", steps=20);
model.plot(beta=10)

model.lock(0,[[0,0],[1,0]])
model.plot(beta=10)

Fix

  1. Make the lock.png part of the distribution in setup.py and SOURCES.txt
  2. Change the loading path of the lock.png to a package variable RESOURCE_DIR.

The new version passed the test.

!pip install git+https://github.com/Animadversio/pykan.git

from kan import KAN, create_dataset
# initialize KAN with G=3
model = KAN(width=[2,1,1], grid=10, k=3)
# create dataset
f = lambda x: (x[:,[0]]+x[:,[1]])/(1+x[:,[0]]*x[:,[1]])
dataset = create_dataset(f, n_var=2, ranges=[-0.9,0.9])

model.train(dataset, opt="LBFGS", steps=20);
model.plot(beta=10)

model.lock(0,[[0,0],[1,0]])
model.plot(beta=10)

@KindXiaoming KindXiaoming merged commit f6ac7e2 into KindXiaoming:master Jun 13, 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

Successfully merging this pull request may close these issues.

None yet

2 participants