public void CalculateHoeffdingsDTest() { OnlineCalculatorError error; // direct perfect dependency var xs = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; var ys = new double[] { 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }; var d = HoeffdingsDependenceCalculator.CalculateHoeffdings(xs, ys, out error); Assert.AreEqual(error, OnlineCalculatorError.None); Assert.AreEqual(d, 1.0, 1E-5); // perfect negative dependency ys = xs.Select(x => -x).ToArray(); d = HoeffdingsDependenceCalculator.CalculateHoeffdings(xs, ys, out error); Assert.AreEqual(error, OnlineCalculatorError.None); Assert.AreEqual(d, 1.0, 1E-5); // ties xs = new double[] { 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 5.0 }; ys = new double[] { 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 6.0 }; d = HoeffdingsDependenceCalculator.CalculateHoeffdings(xs, ys, out error); Assert.AreEqual(error, OnlineCalculatorError.None); Assert.AreEqual(d, 0.6783, 1E-5); // ties xs = new double[] { 1.0, 1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 6.0, 6.0 }; ys = xs.Select(x => x * x).ToArray(); d = HoeffdingsDependenceCalculator.CalculateHoeffdings(xs, ys, out error); Assert.AreEqual(error, OnlineCalculatorError.None); Assert.AreEqual(d, 0.75, 1E-5); // degenerate xs = new double[] { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; ys = new double[] { 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 }; d = HoeffdingsDependenceCalculator.CalculateHoeffdings(xs, ys, out error); Assert.AreEqual(error, OnlineCalculatorError.None); Assert.AreEqual(d, -0.3516, 1E-4); var normal = new HeuristicLab.Random.NormalDistributedRandom(new HeuristicLab.Random.MersenneTwister(31415), 0, 1); xs = Enumerable.Range(0, 1000).Select(i => normal.NextDouble()).ToArray(); ys = Enumerable.Range(0, 1000).Select(i => normal.NextDouble()).ToArray(); // independent d = HoeffdingsDependenceCalculator.CalculateHoeffdings(xs, ys, out error); Assert.AreEqual(error, OnlineCalculatorError.None); Assert.AreEqual(d, -0.00023, 1E-5); xs = Enumerable.Range(0, 1000).Select(i => normal.NextDouble()).ToArray(); ys = xs.Select(x => x * x).ToArray(); d = HoeffdingsDependenceCalculator.CalculateHoeffdings(xs, ys, out error); Assert.AreEqual(error, OnlineCalculatorError.None); Assert.AreEqual(d, 0.25071, 1E-5); // symmetric? d = HoeffdingsDependenceCalculator.CalculateHoeffdings(ys, xs, out error); Assert.AreEqual(error, OnlineCalculatorError.None); Assert.AreEqual(d, 0.25071, 1E-5); }