-
Notifications
You must be signed in to change notification settings - Fork 377
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
Can still plot model and prune model in efficient kan? #29
Comments
Plotting is definitely possible but not planned yet. The parameters in For the pruning, it still needs to validate if my "efficient" way of doing sparsifying regularization works as expected. If not, the trained network might be badly redundant, unlike the cases in original paper. |
Thank you for your reply |
Specifically, how should we use the parameter ‘spline_weight’ to draw the shape of the activation function on each edge? |
I write some code to visualize the activation function on each edge, but it seems not right. If somebody knows how to modify it, welcome to chat. 😄
|
mark |
HI, I used your code and it feels pretty good. Can you say what is incorrect? |
I think the issue is that we only visualize the spline coefficients, but in the original implementation they visualize the activation function based on the pre- and post-activations (see also here) |
After a careful reading of pykan's code, I realized that perhaps EffiecientKAN is difficult to visualize as well as the native pykan. EffiecientKAN actually weights the results of all B-spline functions for all nodes to produce output directly, in order to speed up efficiency. This means that the spline_weight[i][j] in your code does not represent the spline coefficients for the [i][j]th node as native pykan does, and therefore you cannot plot the spline function directly with spline_weight[i][j]. I think EffiecientKAN perhaps speeds up the efficiency while reducing the interpretability of the model. If you know how to visualize on EffiecientKAN, please let me know. |
Yes, you are right. I also found that the spline_weight[i][j] in EffiecientKAN not represent the spline coefficients for the [i][j]th node as native pykan does. Now, I use some tricks to visualize activation function. I just direct compute the output of the kan using range from (-1, 1).
If you have multi-layers, you can direct choose which layer you want to visualize:
|
mark |
I'm not sure that's correct. When using KAN, what we usually want to visualize is the activation function on the edge from the input node to the output node. Whereas this approach seems to visualize the function after all the activation functions are combined:”plt.plot(t.detach().cpu().numpy(), net.kan_layer(t.unsqueeze(1)).detach().cpu().numpy(), label="KAN layer", color="red")”. |
Assuming that the model has a hidden layer [3,1] and the number of variables nvars = 5
number_of_layer = 0
from_node_i = 2
target_node_j = 1
arr = torch.arange(-1,1,0.01)
N = arr.shape[0]
X = torch.zeros(N, nvars)
X[:,from_node_i] = arr
Y = model.layers[number_of_layer](X)
Y = Y[:, target_node_j]
plt.plot(arr.detach().numpy(), Y.detach().numpy()) |
I notice that most image classification tasks are based on efficient-kan instead of original kan. I want to know if it is possible to plot and prune the efficient-kan just like the examples in original kan.
The text was updated successfully, but these errors were encountered: