Пример #1
0
        public void GetValue_TestCaseDataOrder1_BenchmarkResult1([Values(0.0, 1.2, 4.64, 8.98)] double x)
        {
            int gridPointCount     = 10;
            var gridPointArguments = new[] { 1.0, 2.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0 };
            var gridPointValues    = new[] { 7.0, 8.0, 9.0, 8.0, 9.0, 11.0, 10.0, 13.0, 14.0, 13.0 };

            var leastSquaresRegression = new LeastSquaresRegression(1, BasisFunctions.Monomial);
            var curve = leastSquaresRegression.Create();

            curve.Update(gridPointCount, gridPointArguments, gridPointValues);

            double actual = curve.GetValue(x);

            double xSumDivN = 4.3;  // = 1/n * \sum_j x_j
            double ySumDivN = 10.2;
            double Sxy      = 37.4; // = \sum x_j * y_j - 1/n * \sum x_j * \sum y_j
            double Sxx      = 32.1; // = \sum x_j^2 - 1/n * (\sum x_j)^2

            // y = m * x + b, where
            var m = Sxy / Sxx;               // = 1.1651090342679127
            var b = ySumDivN - m * xSumDivN; //  = 5.19...

            double expected = m * x + b;

            Assert.That(actual, Is.EqualTo(expected).Within(1E-7));
        }
Пример #2
0
        public void GetValue_TestCaseDataOrder1_BenchmarkResult2([Values(1.2, 11.421)] double x)
        {
            int gridPointCount     = 8;
            var gridPointArguments = new[] { 5.0, 2.0, 12.0, 9.0, 15.0, 6.0, 25.0, 16.0 };
            var gridPointValues    = new[] { 64.0, 87.0, 50.0, 71.0, 44.0, 56.0, 42.0, 60.0 };

            var leastSquaresRegression = new LeastSquaresRegression(1, BasisFunctions.Monomial);
            var curve = leastSquaresRegression.Create();

            curve.Update(gridPointCount, gridPointArguments, gridPointValues);

            double actual = curve.GetValue(x);

            double xSumDivN = 11.25;
            double ySumDivN = 59.25;
            double Sxx      = 383.5;
            double Sxy      = -593.5;

            // y = m * x +b, where
            var    m        = Sxy / Sxx;               // = 1.5476...
            var    b        = ySumDivN - m * xSumDivN; // =  76.6605...
            double expected = m * x + b;

            Assert.That(actual, Is.EqualTo(expected).Within(1E-7));
        }
            /// <summary>Initializes a new instance of the <see cref="Parametrization"/> class.
            /// </summary>
            /// <param name="leastSquaresRegression">The <see cref="LeastSquaresRegression"/> object which serves as factory for the current object.</param>
            internal Parametrization(LeastSquaresRegression leastSquaresRegression)
            {
                m_LeastSquaresRegressionFactory = leastSquaresRegression;

                int order = leastSquaresRegression.Order;

                m_Coefficients = new double[order + 1];  // only 'order' elements are relevant
                m_WorkingArray = new double[order + 1];
                m_AdjustedReciprocalSingularValues = new double[order + 1];
            }
Пример #4
0
        public void GetValue_TestCaseDataOrder1_BenchmarkResult3([Values(2.67, 7.85)] double x)
        {
            int gridPointCount     = 6;
            var gridPointArguments = new[] { 1.2, 2.3, 3.0, 3.8, 4.7, 5.9 };
            var gridPointValues    = new[] { 1.1, 2.1, 3.1, 4.0, 4.9, 5.9 };

            var leastSquaresRegression = new LeastSquaresRegression(1, BasisFunctions.Monomial);
            var curve = leastSquaresRegression.Create();

            curve.Update(gridPointCount, gridPointArguments, gridPointValues);

            double actual = curve.GetValue(x);

            var m = 1.0506950122649; // y = m * x +b, calculated by Microsoft Excel and with 'paper and pencil'
            var b = -0.1432542927228;

            double expected = m * x + b;

            Assert.That(actual, Is.EqualTo(expected).Within(1E-7));
        }