pykan
pykan copied to clipboard
Freely defining aggregation over nodes
It would be interesting to allow multiplication effect from one node to another. Example: in time series analysis if the Sundays are always closed, so the sales is always 0, it's not possible to create a clean 0 prediction from pure additive rules. If a node could affect the final result through a multiplier logic, it would be possible to learn closed store cases.
set_aggregate_effect(0, [1,1], 'x_3*(x_0+x_1+x_2)') where the first argument is the input layer, second argument is the target layer and node, third argument is the equation for the aggregation of the input nodes.
you can do log transform to make it multiplicative.
You're right - stupid me. Although the solution for any function will be very convoluted. Let me put something together before closing this issue.
I hope this correct, but even if I made a mistake everyone gets the point. Doable, but not easy :)
$$ x_4(x_1+x_2+x_3) $$
model = KAN(width=[4,2,1,1], grid=6, k=3) model.train(dataset, opt="Adam", lr=0.01, steps=1)
x1+x2+x3
model.remove_edge(0,0,1) model.remove_edge(0,1,1) model.remove_edge(0,2,1)
keeping x4
model.remove_edge(0,3,0)
forcing linear, so it surely simple sum
model.fix_symbolic(0,0,0,'x') model.fix_symbolic(0,1,0,'x') model.fix_symbolic(0,2,0,'x') model.fix_symbolic(0,3,1,'x')
adding logarithm
model.fix_symbolic(1,0,0,'log') model.fix_symbolic(1,1,0,'log')
exponential
model.fix_symbolic(2,0,0,'exp')
$$
\exp(\log(x_4) + \log(x_1 + x_2 + x_3))
$$