Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated GaussianDistributionTests.cs based off feedback from nsp

  • Loading branch information...
commit 592a82b42373a57c5c9aa58de1f5c01c2ce7dafe 1 parent 67cada3
@moserware authored
Showing with 47 additions and 5 deletions.
  1. +47 −5 UnitTests/Numerics/GaussianDistributionTests.cs
View
52 UnitTests/Numerics/GaussianDistributionTests.cs
@@ -10,6 +10,22 @@ public class GaussianDistributionTests
private const double ErrorTolerance = 0.000001;
[Test]
+ public void CumulativeToTests()
+ {
+ // Verified with WolframAlpha
+ // (e.g. http://www.wolframalpha.com/input/?i=CDF%5BNormalDistribution%5B0%2C1%5D%2C+0.5%5D )
+ Assert.AreEqual(0.691462, GaussianDistribution.CumulativeTo(0.5), ErrorTolerance);
+ }
+
+ [Test]
+ public void AtTests()
+ {
+ // Verified with WolframAlpha
+ // (e.g. http://www.wolframalpha.com/input/?i=PDF%5BNormalDistribution%5B0%2C1%5D%2C+0.5%5D )
+ Assert.AreEqual(0.352065, GaussianDistribution.At(0.5), ErrorTolerance);
+ }
+
+ [Test]
public void MultiplicationTests()
{
// I verified this against the formula at http://www.tina-vision.net/tina-knoppix/tina-memo/2003-003.pdf
@@ -56,13 +72,39 @@ public void DivisionTests()
[Test]
public void LogProductNormalizationTests()
{
- var m4s5 = new GaussianDistribution(4, 5);
- var m6s7 = new GaussianDistribution(6, 7);
+ // Verified with Ralf Herbrich's F# implementation
+ var standardNormal = new GaussianDistribution(0, 1);
+ var lpn = GaussianDistribution.LogProductNormalization(standardNormal, standardNormal);
+ Assert.AreEqual(-1.2655121234846454, lpn, ErrorTolerance);
- var product2 = m4s5 * m6s7;
- var normConstant = 1.0 / (Math.Sqrt(2 * Math.PI) * product2.StandardDeviation);
- var lpn = GaussianDistribution.LogProductNormalization(m4s5, m6s7);
+ var m1s2 = new GaussianDistribution(1, 2);
+ var m3s4 = new GaussianDistribution(3, 4);
+ var lpn2 = GaussianDistribution.LogProductNormalization(m1s2, m3s4);
+ Assert.AreEqual(-2.5168046699816684, lpn2, ErrorTolerance);
+ }
+
+ [Test]
+ public void LogRatioNormalizationTests()
+ {
+ // Verified with Ralf Herbrich's F# implementation
+ var m1s2 = new GaussianDistribution(1, 2);
+ var m3s4 = new GaussianDistribution(3, 4);
+ var lrn = GaussianDistribution.LogRatioNormalization(m1s2, m3s4);
+ Assert.AreEqual(2.6157405972171204, lrn, ErrorTolerance);
+ }
+
+ [Test]
+ public void AbsoluteDifferenceTests()
+ {
+ // Verified with Ralf Herbrich's F# implementation
+ var standardNormal = new GaussianDistribution(0, 1);
+ var absDiff = GaussianDistribution.AbsoluteDifference(standardNormal, standardNormal);
+ Assert.AreEqual(0.0, absDiff, ErrorTolerance);
+ var m1s2 = new GaussianDistribution(1, 2);
+ var m3s4 = new GaussianDistribution(3, 4);
+ var absDiff2 = GaussianDistribution.AbsoluteDifference(m1s2, m3s4);
+ Assert.AreEqual(0.4330127018922193, absDiff2, ErrorTolerance);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.