Content
|
Splines KAN
The code for spline version is written in C#. The the logic is explained in the KAN's core
and splines
The network is the sum of KAN addends, below is example of instantiation. Each addend is
$$ \Phi\left(\sum_{p=1}^{n} \phi_{p}(x_{p})\right). $$
Basis innerBasis = new Basis(8);
Basis outerBasis = new Basis(12);
int Epochs = 400;
int M = 5;
List listAddend = new List();
for (int i = 0; i < M; ++i)
{
listAddend.Add(new KANAddend(xmin, xmax, targetMin / M, targetMax / M, innerBasis, outerBasis, 0.1, 0.1));
}
Users can test it for three formulas
$$ z = exp(sin(\pi x) + y^2), $$
$$ z = exp((sin(\pi (x_1^2 + x_2^2) ) + sin(\pi (x_3^2 + x_4^2) ))/2), $$
$$
y = \frac{2 + 2 x_3}{3\pi} \left[ {arctan}\left( 20( x_1 - \frac{1}{2} + \frac{x_2}{6})\exp\left(x_5\right) \right) + \frac{\pi}{2} \right] + \frac{2 + 2 x_4}{3\pi} \left[ {arctan}\left( 20( x_1 - \frac{1}{2} - \frac{x_2}{6})\exp\left(x_5\right) \right) + \frac{\pi}{2} \right].
$$
The first and second formulas are taked from a DEMO of MIT KAN.
Their execution report for the first formula is in the copy below
Our result is next
The accuracy is about the same, errors are $0.0047$ and $0.0050$. The execution time is significantly different 0.74 and 23 seconds, but their code is in Python so performance can't be
compared and our code is not optimized for fast execution. In an optimized C++ code, the time is $0.06$.
It also builds and saves images of identified functions, here is an example
|
|
The accuracy may be increased by trying concurrently different initializations and trainings. This code does not have that, because it is demo and
it can be easily added by any end user. All you need is to place basic logic into concurrent threads and choose the best result when completed.
In this way the error may be as low as $0.0020$ without increasing of the training time.
|
|
|