Example #1
0
 /// <summary>
 /// Tests whether the support of a given distribution includes or excludes given values.
 /// </summary>
 /// <param name="distribution">The distribution.</param>
 /// <param name="values">The values to test.</param>
 /// <param name="testInclusion">Specifies whether the inclusion test must be performed instead of the exclusion test.</param>
 private static void TestInclusionExclusion <T>(IDistribution <T> distribution, T[] values, bool testInclusion)
 {
     Console.WriteLine("Testing distribution: " + distribution.ToString());
     foreach (var val in values)
     {
         var excluded = double.IsNegativeInfinity(distribution.GetLogProb(val));
         var msg      = val + (excluded ? " was not in " : " was in ");
         Assert.True(excluded != testInclusion, msg + " " + distribution.ToString());
         Console.WriteLine(msg + "distribution");
     }
 }
        private static void Test(string name, IDistribution <string> dist, params string[] vals)
        {
            var sa = (StringDistribution)dist;

            Console.Write(name + "=" + sa);
            double sum = 0;

            foreach (var s in vals)
            {
                var logProb = dist.GetLogProb(s);
                sum += Math.Exp(logProb);
            }

            var ok     = Math.Abs(sum - 1.0) < 1E-8;
            var valstr = string.Join("|", vals.Select(s => s + "$").ToArray());

            Assert.True(ok, $"Result was {sa} should be ({valstr})");
        }