pykan icon indicating copy to clipboard operation
pykan copied to clipboard

Freely defining aggregation over nodes

Open guyko81 opened this issue 9 months ago • 2 comments

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.

guyko81 avatar May 03 '24 15:05 guyko81

you can do log transform to make it multiplicative.

1991jhf avatar May 04 '24 01:05 1991jhf

You're right - stupid me. Although the solution for any function will be very convoluted. Let me put something together before closing this issue.

guyko81 avatar May 04 '24 10:05 guyko81

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)) $$ image

guyko81 avatar May 04 '24 11:05 guyko81