示例#1
0
 public void GaussianNetworkOutOfRangeMeasureTestInputMethod()
 {
     var net = new GaussianNetwork(new SimpleMeasure("WrongNet", 10U));
     net.TestInput(new SimpleMeasure("WrongNet", 101U));
 }
示例#2
0
        public void GaussianNetworkBusinessLogic()
        {
            GaussianNetwork net = new GaussianNetwork(new SimpleMeasure("Calvino", 80U));
            Assert.AreEqual(net.Mean, 80D, 0.000000000001D);
            Assert.AreEqual(net.S, 0D, 0.000000000001D);
            Assert.AreEqual(net.StdDev, 0, 0.000000000001D);
            Assert.AreEqual(net.N, 1);

            Assert.IsFalse(net.TestInput(new SimpleMeasure("Galileo", 80U)));
            // under stableN, the SSID is enough
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 80U)));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 79U)));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 10U)));

            net.UpdateStats(new SimpleMeasure("Calvino", 40U));
            Assert.AreEqual(net.Mean, 60D, 0.000000000001D); //12 digits precision
            Assert.AreEqual(net.S, 800D, 0.000000000001D);
            Assert.AreEqual(net.StdDev, 20D, 0.000000000001D);
            Assert.AreEqual(net.N, 2);

            Assert.IsFalse(net.TestInput(new SimpleMeasure("Galileo", 60U)));
            // under stableN, the SSID is enough
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 40U)));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 59U)));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 10U)));

            net.UpdateStats(new SimpleMeasure("Calvino", 0U));
            Assert.AreEqual(net.Mean, 40D, 0.000000000001D);
            Assert.AreEqual(net.S, 3200, 0.000000000001D);
            Assert.AreEqual(net.StdDev, 32.659863237109D, 0.000000000001D);
            Assert.AreEqual(net.N, 3);

            Assert.IsFalse(net.TestInput(new SimpleMeasure("Galileo", 40U)));
            // under stableN, the SSID is enough
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 40U)));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 39U)));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", 10U)));

            for (int i = 0; i < 1000; i++)
            {
                net.UpdateStats(new SimpleMeasure("Calvino", 40U));
                net.UpdateStats(new SimpleMeasure("Calvino", 35U));
                net.UpdateStats(new SimpleMeasure("Calvino", 37U));
                net.UpdateStats(new SimpleMeasure("Calvino", 38U));
            }
            Assert.AreEqual(net.Mean, 37.501873594804D, 0.000000000001D);
            Assert.AreEqual(net.S, 16218.735948039D, 0.000000001D);
            Assert.AreEqual(net.StdDev, 2.01286990465602D, 0.000000000001D);
            Assert.AreEqual(net.N, 4003);

            Assert.IsFalse(net.TestInput(new SimpleMeasure("Galileo", 37U)));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Round(net.Mean))));
            // 1 StdDev
            double delta1 = 1 * net.StdDev - 0.001D;
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Floor(net.Mean + delta1))));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Ceiling(net.Mean - delta1))));
            // K * StdDev
            double deltaK = GaussianNetwork.K * net.StdDev - 0.001D;
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Floor(net.Mean + deltaK))));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Ceiling(net.Mean - deltaK))));
            // Over
            double deltaO = GaussianNetwork.K * net.StdDev + 1D;
            Assert.IsFalse(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Floor(net.Mean + deltaO))));
            Assert.IsFalse(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Ceiling(net.Mean - deltaO))));
            Assert.IsFalse(net.TestInput(new SimpleMeasure("Calvino", 0U)));
            Assert.IsFalse(net.TestInput(new SimpleMeasure("Calvino", 100U)));

            // Check K * StdDev < SignalQualityUnit special case
            for (int i = 0; i < 1000000; i++)
            {
                net.UpdateStats(new SimpleMeasure("Calvino", 37U));
            }
            Assert.AreEqual(net.Mean, 37D, 0.5D);
            Assert.Less((net.StdDev * GaussianNetwork.K).CompareTo(GaussianNetwork.SignalQualityUnit), 1);
            double deltaU = GaussianNetwork.SignalQualityUnit - 0.001D;
            double deltaUO = GaussianNetwork.SignalQualityUnit + 1D;
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Floor(net.Mean + deltaU))));
            Assert.IsTrue(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Ceiling(net.Mean - deltaU))));
            Assert.IsFalse(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Floor(net.Mean + deltaUO))));
            Assert.IsFalse(net.TestInput(new SimpleMeasure("Calvino", (uint)Math.Ceiling(net.Mean - deltaUO))));
        }