public void VarianceTest8() { double[,] matrix = { { 4.0, 2.0, 0.60 }, { 4.2, 2.1, 0.59 }, { 3.9, 2.0, 0.58 }, { 4.3, 2.1, 0.62 }, { 4.1, 2.2, 0.63 } }; double[] weights = { 0.9, 0.9, 0.9, 0.9, 0.9 }; double[] expected = { Tools.WeightedVariance(matrix.GetColumn(0), weights, WeightType.Automatic), Tools.WeightedVariance(matrix.GetColumn(1), weights, WeightType.Automatic), Tools.WeightedVariance(matrix.GetColumn(2), weights, WeightType.Automatic), }; double[] actual = Tools.WeightedVariance(matrix, weights, WeightType.Automatic); Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-10)); }
public void VarianceTest7() { double[][] matrix = new double[, ] { { 4.0, 2.0, 0.60 }, { 4.2, 2.1, 0.59 }, { 3.9, 2.0, 0.58 }, { 4.3, 2.1, 0.62 }, { 4.1, 2.2, 0.63 } }.ToArray(); double[] weights = { 0.9, 0.9, 0.9, 0.9, 0.9 }; double[] expected = { Tools.WeightedVariance(matrix.GetColumn(0), weights), Tools.WeightedVariance(matrix.GetColumn(1), weights), Tools.WeightedVariance(matrix.GetColumn(2), weights), }; double[] actual = Tools.WeightedVariance(matrix, weights); Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-10)); }
public void WeightedVarianceTest3() { double[] weights = { 2, 1, 1, 1, 2, 3, 1, 3, 1, 1, 1, 1 }; double[] samples = { 5, 1, 4, 1, 2, 3, 4, 3, 4, 3, 2, 3 }; weights = weights.Divide(weights.Sum()); double actual = Tools.WeightedVariance(samples, weights); Assert.AreEqual(1.3655172413793104, actual); }
public void WeightedVarianceTest2() { double[] original = { 5, 5, 1, 4, 1, 2, 2, 3, 3, 3, 4, 3, 3, 3, 4, 3, 2, 3 }; double expected = Tools.Variance(original); var repeats = new[] { 2, 1, 1, 1, 2, 3, 1, 3, 1, 1, 1, 1 }; var samples = new[] { 5, 1, 4, 1, 2, 3, 4, 3, 4, 3, 2, 3.0 }; double actual = Tools.WeightedVariance(samples, repeats); Assert.AreEqual(expected, actual); }
public void WeightedVarianceTest1() { double[] original = { 5, 5, 1, 4, 1, 2, 2, 3, 3, 3, 4, 3, 3, 3, 4, 3, 2, 3 }; double expected = Tools.Variance(original, unbiased: false); double[] weights = { 2, 1, 1, 1, 2, 3, 1, 3, 1, 1, 1, 1 }; double[] samples = { 5, 1, 4, 1, 2, 3, 4, 3, 4, 3, 2, 3 }; weights = weights.Divide(weights.Sum()); double actual = Tools.WeightedVariance(samples, weights, unbiased: false); Assert.AreEqual(expected, actual); }