Ejemplo n.º 1
0
        public void TestBernoulliPointEstimator()
        {
            var distribution = new Bernoulli(0.25);

            Assert.False(distribution.GetMode());
            Assert.False(PointEstimator.GetEstimate(distribution, Metrics.ZeroOneError));  // Mode
            Assert.False(distribution.GetMean() >= 0.5);
            Assert.False(PointEstimator.GetEstimate(distribution, Metrics.SquaredError));  // Mean
            Assert.False(PointEstimator.GetEstimate(distribution, Metrics.AbsoluteError)); // Median = Mode

            distribution = new Bernoulli(0.5);
            Assert.True(distribution.GetMode());
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.ZeroOneError));  // Mode
            Assert.True(distribution.GetMean() >= 0.5);
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.SquaredError));  // Mean
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.AbsoluteError)); // Median = Mode

            distribution = new Bernoulli(0.6);
            Assert.True(distribution.GetMode());
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.ZeroOneError));  // Mode
            Assert.True(distribution.GetMean() >= 0.5);
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.SquaredError));  // Mean
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.AbsoluteError)); // Median = Mode

            Assert.Throws <ArgumentNullException>(() => PointEstimator.GetEstimate(distribution, null));

            // Test generic representation of distribution
            var genericDistribution = new Dictionary <bool, double> {
                { true, 0.25 }, { false, 0.75 }
            };                                                                                    // Order matters!

            Assert.False(PointEstimator.GetEstimate(genericDistribution, Metrics.ZeroOneError));  // Mode
            Assert.False(PointEstimator.GetEstimate(genericDistribution, Metrics.SquaredError));  // Mean
            Assert.False(PointEstimator.GetEstimate(genericDistribution, Metrics.AbsoluteError)); // Median = Mode

            genericDistribution = new Dictionary <bool, double> {
                { true, 0.5 }, { false, 0.5 }
            };
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.ZeroOneError));  // Mode
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.SquaredError));  // Mean
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.AbsoluteError)); // Median = Mode

            genericDistribution = new Dictionary <bool, double> {
                { true, 0.6 }, { false, 0.4 }
            };
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.ZeroOneError));  // Mode
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.SquaredError));  // Mean
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.AbsoluteError)); // Median = Mode

            Assert.Throws <ArgumentNullException>(() => PointEstimator.GetEstimate(distribution, null));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Prints the prediction.
 /// </summary>
 /// <param name="index">Index.</param>
 /// <param name="posteriorActivity">Posterior activity.</param>
 /// <param name="label">If set to <c>true</c> label.</param>
 /// <param name="score">Score.</param>
 public static void PrintPrediction(int index, Bernoulli posteriorActivity, bool label, double score)
 {
     Console.WriteLine("{0,3}, Score: {1,4:N2}, Bayes Point {2:N2}, Label {3,5}, Predicted {4,5}, Correct {5,5}",
                       index, score, posteriorActivity.GetMean(), label, posteriorActivity.GetMode(), label == posteriorActivity.GetMode());
 }