public static void Test()
 {
     Random rand = new Random();
     int dim = rand.Next(2, 7);
     MemorySavingLeastSquare msls = new MemorySavingLeastSquare(dim);
     double[] ans = Enumerable.Range(0, dim).Select(x => rand.NextDouble() * 200 - 100).ToArray();
     List<double[]> leftArr = new List<double[]>();
     List<double> rightArr = new List<double>();
     for (int k = 0; k < 200; k++)
     {
         double[] left = Enumerable.Range(0, dim).Select(x => rand.NextDouble() * 200 - 100).ToArray();
         double right = Enumerable.Range(0, dim).Select(i => left[i] * ans[i]).Sum() + rand.NextDouble() * 10 - 5;
         msls.PutPoint(left, right);
         leftArr.Add(left);
         rightArr.Add(right);
     }
     double[] ans1 = CvEx.Solve(leftArr, rightArr, InvertMethod.Svd);
     double[] ans2 = msls.Solve();
     System.Windows.MessageBox.Show(string.Join(", ", ans.Select(x => x.ToString("0.00000"))) + "\n" + string.Join(", ", ans1.Select(x => x.ToString("0.00000"))) + "\n" + string.Join(", ", ans2.Select(x => x.ToString("0.00000"))));
 }
        public static void Test()
        {
            Random rand = new Random();
            int    dim  = rand.Next(2, 7);
            MemorySavingLeastSquare msls = new MemorySavingLeastSquare(dim);

            double[]        ans      = Enumerable.Range(0, dim).Select(x => rand.NextDouble() * 200 - 100).ToArray();
            List <double[]> leftArr  = new List <double[]>();
            List <double>   rightArr = new List <double>();

            for (int k = 0; k < 200; k++)
            {
                double[] left  = Enumerable.Range(0, dim).Select(x => rand.NextDouble() * 200 - 100).ToArray();
                double   right = Enumerable.Range(0, dim).Select(i => left[i] * ans[i]).Sum() + rand.NextDouble() * 10 - 5;
                msls.PutPoint(left, right);
                leftArr.Add(left);
                rightArr.Add(right);
            }
            double[] ans1 = CvEx.Solve(leftArr, rightArr, InvertMethod.Svd);
            double[] ans2 = msls.Solve();
            System.Windows.MessageBox.Show(string.Join(", ", ans.Select(x => x.ToString("0.00000"))) + "\n" + string.Join(", ", ans1.Select(x => x.ToString("0.00000"))) + "\n" + string.Join(", ", ans2.Select(x => x.ToString("0.00000"))));
        }
Ejemplo n.º 3
0
 private void button1_Click_1(object sender, RoutedEventArgs e)
 {
     MemorySavingLeastSquare.Test();
 }