Content



Download Multithreaded Piecewise Linear version

Code KAN lin TH



This is multithreaded piecewise linear version. The training is performed for multiple Kolmogorov-Arnold models concurrently and then the best model is selected. There are two selection steps. The best model, after the first step is copied into all other models, then concurrent training is resumed. The goal is not performance, but the accuracy. The error on tested dataset in multithreaded process is, usually, 0.5%. The training time is about 0.5 seconds for 10 000 records with 5 features. Below is the code for worker thread.
        static void DoWork(Object obj)
        {
            Random r = new Random();
            Model m1 = (Model)obj;

            for (int epoch = 0; epoch < 12; ++epoch)
            {
                m1.error = 0.0;
                for (int i = 0; i < inputs.Count; ++i)
                {
                    double residual = target[i];
                    for (int j = 0; j < m1.addends.Length; ++j)
                    {
                        residual -= m1.addends[j].ComputeUsingInput(inputs[i]);
                    }
                    for (int j = 0; j < m1.addends.Length; ++j)
                    {
                        m1.addends[j].UpdateUsingMemory(residual);
                    }
                    m1.error += residual * residual;
                }
                m1.error /= inputs.Count;
                m1.error = Math.Sqrt(m1.error);
                m1.error /= (targetMax - targetMin);
                Console.WriteLine("Training step {0}, relative RMSE {1:0.0000}", epoch, m1.error);
            }
        }