public void StandardErrorWeightedValues()
        {
            var vals = new List <WeightedValue>
            {
                new WeightedValue {
                    Value = 2, Weight = 1
                },
                new WeightedValue {
                    Value = 3, Weight = 1
                },
                new WeightedValue {
                    Value = 5, Weight = 0
                },
                new WeightedValue {
                    Value = 7, Weight = 0
                },
                new WeightedValue {
                    Value = 11, Weight = 4
                },
                new WeightedValue {
                    Value = 13, Weight = 1
                },
                new WeightedValue {
                    Value = 17, Weight = 2
                },
                new WeightedValue {
                    Value = 19, Weight = 1
                },
                new WeightedValue {
                    Value = 23, Weight = 0
                },
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(5.31507, Statistics.StandardError(vals)));
        }
        public void VarianceWeightedValues()
        {
            var vals = new List <WeightedValue>
            {
                new WeightedValue {
                    Value = 2, Weight = 1
                },
                new WeightedValue {
                    Value = 3, Weight = 1
                },
                new WeightedValue {
                    Value = 5, Weight = 0
                },
                new WeightedValue {
                    Value = 7, Weight = 0
                },
                new WeightedValue {
                    Value = 11, Weight = 4
                },
                new WeightedValue {
                    Value = 13, Weight = 1
                },
                new WeightedValue {
                    Value = 17, Weight = 2
                },
                new WeightedValue {
                    Value = 19, Weight = 1
                },
                new WeightedValue {
                    Value = 23, Weight = 0
                },
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(28.25, Statistics.Variance(vals)));
        }
        public void Modus()
        {
            var vals = new List <double> {
                1.5, 2, 3.1, 1.5, 6, 8.4, 1.5, 5
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(1.5, Statistics.Modus(vals)));
        }
        public void MedianValuesEvenLength()
        {
            var vals = new List <double> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(4.5, Statistics.Median(vals)));
        }
        public void VarianceSingleValues()
        {
            var vals = new List <double> {
                7.45, 11.25, 29.87, 41.15, 47.12
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(248.572336, Statistics.Variance(vals)));
        }
        public void AverageValue()
        {
            var list = new List <double> {
                1.1, 5.4, 84.41, 51.25, 5.79, 66.22
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(35.695, Statistics.AverageValue(list)));
            Assert.IsTrue(NumericUtilities.DoubleCompare(35.695, Statistics.ExpectedValue(list)));
        }
        public void StandardErrorSingleValues()
        {
            var vals = new List <double> {
                7.45, 11.25, 29.87, 41.15, 47.12
            };
            var result = Statistics.StandardError(vals);

            Assert.IsTrue(NumericUtilities.DoubleCompare(15.7661769, Statistics.StandardError(vals)));
        }
        public void CovarianceSingleValues()
        {
            var x = new List <double> {
                65.21, 64.75, 65.26, 65.76, 65.96
            };
            var y = new List <double> {
                67.25, 66.39, 66.12, 65.70, 66.64
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(-0.04644, Statistics.Covariance(x, y)));
        }
        public void Corellation()
        {
            var x = new List <double> {
                43, 21, 25, 42, 57, 59
            };
            var y = new List <double> {
                99, 65, 79, 75, 87, 81
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(0.5298, Statistics.Corellation(x, y)));
        }
        public void MovingAverage()
        {
            var vals = new List <double> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };
            var expected = new List <double> {
                6.0 / 3.0, 9.0 / 3.0, 12.0 / 3.0, 15.0 / 3.0, 18.0 / 3.0, 21.0 / 3.0, 24.0 / 3.0, 27.0 / 3.0
            };
            var result = Statistics.MovingAverage(vals, 3);

            result
            .Zip(expected, (res, exp) => NumericUtilities.DoubleCompare(res, exp))
            .ToList()
            .ForEach(r => Assert.IsTrue(r));
        }
        public void LinearRegression()
        {
            var vals = new List <KeyValuePair <int, double> >
            {
                new KeyValuePair <int, double>(1, 5),
                new KeyValuePair <int, double>(2, 6),
                new KeyValuePair <int, double>(3, 8),
                new KeyValuePair <int, double>(4, 6),
                new KeyValuePair <int, double>(5, 7),
            };
            double slope, offset;

            Statistics.LinearRegression(vals, out slope, out offset);
            Assert.IsTrue(NumericUtilities.DoubleCompare(0.4, slope));
            Assert.IsTrue(NumericUtilities.DoubleCompare(5.2, offset));
        }
Пример #12
0
        public void MatrixGaussEliminationValidResult()
        {
            var values = new double[, ]
            {
                { 8, -1, -2, 0 },
                { -1, 7, -1, 10 },
                { -2, -1, 9, 23 }
            };
            var matrix     = new Matrix <double>(values);
            var resultType = matrix.GaussElimination(out List <double> result);

            Assert.AreEqual(resultType, GaussEliminationResultType.ValidResult);
            var expectedResult = new List <double> {
                1, 2, 3
            };

            Assert.AreEqual(result
                            .Zip(expectedResult, (r, e) => NumericUtilities.DoubleCompare(r, e))
                            .Count(a => a), 3);
        }
        public void CovarianceWeightedValues()
        {
            var x = new List <WeightedValue>
            {
                new WeightedValue {
                    Value = 65.21, Weight = 0.5
                },
                new WeightedValue {
                    Value = 64.75, Weight = 0.5
                },
                new WeightedValue {
                    Value = 65.26, Weight = 0.5
                },
                new WeightedValue {
                    Value = 65.76, Weight = 0.5
                },
                new WeightedValue {
                    Value = 65.96, Weight = 0.5
                }
            };
            var y = new List <WeightedValue>
            {
                new WeightedValue {
                    Value = 67.25, Weight = 0.5
                },
                new WeightedValue {
                    Value = 66.39, Weight = 0.5
                },
                new WeightedValue {
                    Value = 66.12, Weight = 0.5
                },
                new WeightedValue {
                    Value = 65.70, Weight = 0.5
                },
                new WeightedValue {
                    Value = 66.64, Weight = 0.5
                }
            };

            Assert.IsTrue(NumericUtilities.DoubleCompare(-0.04644, Statistics.Covariance(x, y)));
        }
        public void AverageValueWeight()
        {
            var list = new List <WeightedValue>
            {
                new WeightedValue {
                    Weight = 5, Value = 12
                },
                new WeightedValue {
                    Weight = 0.2, Value = 5
                },
                new WeightedValue {
                    Weight = 1, Value = 14
                },
                new WeightedValue {
                    Weight = 0.67, Value = 13
                },
                new WeightedValue {
                    Weight = 1.7, Value = 55
                },
            };
            var result = 20.67794632;

            Assert.IsTrue(NumericUtilities.DoubleCompare(result, Statistics.AverageValue(list)));
        }
 public void DoubleCompare()
 {
     Assert.IsTrue(NumericUtilities.DoubleCompare(1.24, 1.2400000001));
     Assert.IsTrue(NumericUtilities.DoubleCompare(4.7 / 3.14, 4.7 * (1.0 / 3.14)));
     Assert.IsFalse(NumericUtilities.DoubleCompare(2.52, 2.53));
 }