pykan
pykan copied to clipboard
fit to f(x)=x^-1
hello, this work is great, but I'm running into a little problem. when the function I want to fit is f(x,y)=x^-1+y^2 , I found that y^2 is easy to fit but x^-1 not, the model is set by following code:
from kan import *
model = KAN(width=[2,1], grid=5, k=3, seed=0)
f = lambda x: x[:,[0]]**(-1) + x[:,[1]]**2
dataset = create_dataset(f, n_var=2, ranges=[0.1, 10])
model.train(dataset, opt="LBFGS", steps=20, lamb=0.01, lamb_entropy=10.)
model.plot()
the reasult is below:
I want to know if I did something wrong
Hi, it might help to try grid=20
or higher (to be more expressive such that the fast changing behavior around x=0
can be captured), and lamb=0.00
(the shape is already simple enough, we probably don't want any further sparsification). If that still doesn't work, try making the dataset simpler first for debugging, e.g., try ranges=[0.5,2]
.
I can confirm this works under the suggestions. Even if not reaching machine precision (probably due to the missing [0, 0.1]
interval), the suggested final formula is specific enough to desume it yourself.
Here's the gist: https://gist.github.com/AlessandroFlati/34130182001a35b43d896d9195b79745
Also, remember that choosing Adam
after auto_symbolic
(with much more iterations) often helps in reaching more precision.