public void IndexerProperty_AtNoneReplenishedGridPoint_BenchmarkResult1(LabelMatrix.MissingValueReplenishment missingValueReplenishment, LabelMatrix.OrderOfInput orderOfInput)
        {
            /* some sample data, matrix is provided column-by-column: */
            var matrixEntries = new double[] { 1, 2, 3, 4, Double.NaN, 6, 7, 8, 9 };
            var xLabels       = new double[] { 1.1, 2.12, 3.4 };
            var yLabels       = new double[] { 1.05, 2.07, 3.65 };

            int rowCount    = 3;
            int columnCount = 3;
            var labelMatrix = LabelMatrix.Create(rowCount, columnCount, matrixEntries, xLabels, yLabels, missingValueReplenishment, orderOfInput);

            var indexCollection = new Tuple <int, int, int>[] {  // (rowIndex, columnIndex, Index of 'matrixEntries')
                Tuple.Create(0, 0, 0),
                Tuple.Create(1, 0, 1),
                Tuple.Create(2, 0, 2),
                Tuple.Create(0, 1, 3),
                // skip the 'NaN' value in this test
                Tuple.Create(2, 1, 5),
                Tuple.Create(0, 2, 6),
                Tuple.Create(1, 2, 7),
                Tuple.Create(2, 2, 8)
            };

            foreach (var indices in indexCollection)
            {
                int rowIndex    = indices.Item1;
                int columnIndex = indices.Item2;
                int expectedMatrixEntryIndex = indices.Item3;

                double actual   = labelMatrix[rowIndex, columnIndex];
                double expected = matrixEntries[expectedMatrixEntryIndex];

                Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("Row: {0}, Column: {1}, expected: {2}, actual: {3}", rowIndex, columnIndex, expected, actual));
            }
        }
        public void GetValue_TestCase1(GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Extrapolator horizontalLeftExtrapolator, GridPointCurve.Extrapolator horizontalRightExtrapolator, GridPointCurve.Interpolator verticalInterpolator, GridPointCurve.Extrapolator verticalAboveExtrapolator, GridPointCurve.Extrapolator verticalBelowExtrapolator, GridPointSurface2d.ConstructionOrder constructionOrder, double x, double y, double expected)
        {
            int rowCount    = 3;
            int columnCount = 3;
            var xLabels     = new double[] { 1.1, 2.12, 3.4 };
            var yLabels     = new double[] { 1.05, 2.07, 3.65 };

            double[] matrixEntries = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // matrix is provided column-by-column

            var labelMatrix = LabelMatrix.Create(rowCount, columnCount, matrixEntries, xLabels, yLabels);

            var surface = GridPointSurface2d.Create(labelMatrix, horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator, verticalInterpolator, verticalAboveExtrapolator, verticalBelowExtrapolator, constructionOrder);

            double actual = surface.GetValue(x, y);

            Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("expected: {0}, actual: {1}", expected, actual));
        }
Beispiel #3
0
        public void IndexerProperty_yLinear_BenchmarkResult3(
            [Values(LabelMatrix.OrderOfInput.AscendingOrder, LabelMatrix.OrderOfInput.Disordered, LabelMatrix.OrderOfInput.DisorderedHorizontalLabels, LabelMatrix.OrderOfInput.DisorderedVerticalLabels)]
            LabelMatrix.OrderOfInput orderOfInput)
        {
            var matrixEntries = new double[] { 1, 2, 3, 4, Double.NaN, 6, 7, 8, 9, 10 };
            var xLabels       = new double[] { 1, 2 };
            var yLabels       = new double[] { 1, 2, 3, 4, 5 };

            int rowCount    = 5;
            int columnCount = 2;

            var missingValueReplenishment = LabelMatrix.MissingValueReplenishment.WeightedNearestGridPoints.yAxis.Linear;

            var labelMatrix = LabelMatrix.Create(rowCount, columnCount, matrixEntries, xLabels, yLabels, missingValueReplenishment, orderOfInput);

            double actual   = labelMatrix[4, 0];
            double expected = 4.0; // in y-direction only one value is available

            Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("Row: {0}, Column: {1}, expected: {2}, actual: {3}", 0, 4, expected, actual));
        }
        public void IndexerProperty_yLinear_BenchmarkResult1(
            [Values(LabelMatrix.OrderOfInput.AscendingOrder, LabelMatrix.OrderOfInput.Disordered, LabelMatrix.OrderOfInput.DisorderedHorizontalLabels, LabelMatrix.OrderOfInput.DisorderedVerticalLabels)]
            LabelMatrix.OrderOfInput orderOfInput)
        {
            var matrixEntries = new double[] { 1, 2, 3, 4, Double.NaN, 6, 7, 8, 9 };
            var xLabels       = new double[] { 1.1, 2.12, 3.4 };
            var yLabels       = new double[] { 1.05, 2.07, 3.65 };

            int rowCount    = 3;
            int columnCount = 3;

            var missingValueReplenishment = LabelMatrix.MissingValueReplenishment.WeightedNearestGridPoints.yAxis.Linear;

            var labelMatrix = LabelMatrix.Create(rowCount, columnCount, matrixEntries, xLabels, yLabels, missingValueReplenishment, orderOfInput);

            double actual   = labelMatrix[1, 1];
            double expected = (yLabels[1] - yLabels[0]) * (6.0 - 4.0) / (yLabels[2] - yLabels[0]) + 4.0;  // a linear interpolation

            Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("Row: {0}, Column: {1}, expected: {2}, actual: {3}", 1, 1, expected, actual));
        }
        public void IndexerProperty_xLinear_BenchmarkResult2(
            [Values(LabelMatrix.OrderOfInput.AscendingOrder, LabelMatrix.OrderOfInput.Disordered, LabelMatrix.OrderOfInput.DisorderedHorizontalLabels, LabelMatrix.OrderOfInput.DisorderedVerticalLabels)]
            LabelMatrix.OrderOfInput orderOfInput)
        {
            /* some sample data, matrix is provided column-by-column: */
            var matrixEntries = new double[] { 1, 2, 3, 4, Double.NaN, 6, 7, 8, 9, 10 };
            var xLabels       = new double[] { 1, 2, 3, 4, 5 };
            var yLabels       = new double[] { 1, 2 };

            int rowCount    = 2;
            int columnCount = 5;

            var missingValueReplenishment = LabelMatrix.MissingValueReplenishment.WeightedNearestGridPoints.xAxis.Linear;

            var labelMatrix = LabelMatrix.Create(rowCount, columnCount, matrixEntries, xLabels, yLabels, missingValueReplenishment, orderOfInput);

            double actual   = labelMatrix[0, 2];
            double expected = (xLabels[1] - xLabels[0]) * (7.0 - 3.0) / (xLabels[2] - xLabels[0]) + 3.0;  // a linear interpolation

            Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("Row: {0}, Column: {1}, expected: {2}, actual: {3}", 0, 2, expected, actual));
        }
Beispiel #6
0
        public void GetValue_AtGridPoint_GridPointValue_TestCase2(GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Extrapolator horizontalLeftExtrapolator, GridPointCurve.Extrapolator horizontalRightExtrapolator, GridPointCurve.Interpolator verticalInterpolator, GridPointCurve.Extrapolator verticalAboveExtrapolator, GridPointCurve.Extrapolator verticalBelowExtrapolator, GridPointSurface2d.ConstructionOrder constructionOrder)
        {
            int rowCount    = 2;
            int columnCount = 5;

            var xLabels = new double[] { 1.05, 2.6, 3, 4, 5 };
            var yLabels = new double[] { 1.3, 2.8 };

            var matrixEntries = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // matrix is provided column-by-column
            var labelMatrix   = LabelMatrix.Create(rowCount, columnCount, matrixEntries, xLabels, yLabels);

            var surface = GridPointSurface2d.Create(labelMatrix, horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator, verticalInterpolator, verticalAboveExtrapolator, verticalBelowExtrapolator, constructionOrder);

            for (int j = 0; j < rowCount; j++)
            {
                for (int k = 0; k < columnCount; k++)
                {
                    double expected = labelMatrix[j, k];

                    double actual = surface.GetValue(x: labelMatrix.HorizontalDoubleLabels[k], y: labelMatrix.VerticalDoubleLabels[j]);
                    Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("Row: {0}, Column: {1}, expected: {2}, actual: {3}", j, k, expected, actual));
                }
            }
        }