Ejemplo n.º 1
0
        public void TestNormal()
        {
            const double mu                  = 0.0;
            const double sigma               = 1.0;
            int          numOfFailures       = 0;
            const int    numOfTimesToRun     = 1000;
            const int    maxExpectedFailures = 15;

            for (int i = 0; i < numOfTimesToRun; i++)
            {
                Console.WriteLine("Test Run Number {0}", (i + 1));

                // Reset the seed for the next run
                Configuration.CurrentConfiguration =
                    Configuration.ConfigurationFromString($"{{\"prng_seed\":{DateTime.Now.Millisecond},\"prng_index\":{i}}}");
                RNGFactory.Reset();

                if (IsNormalDistribution(mu, sigma) == false)
                {
                    numOfFailures++;
                    Console.WriteLine("This failed {0} times.", numOfFailures);
                }
            }
            Console.WriteLine("End of Test. This failed {0} times.", numOfFailures);
            Expect(numOfFailures <= maxExpectedFailures);
        }
Ejemplo n.º 2
0
        public void FixedPopulationTest()
        {
            Configuration.CurrentConfiguration = Configuration.ConfigurationFromString("{}");
            RNGFactory.Reset();
            var modelInfo = compartments.emodl.EmodlLoader.LoadEMODLModel("(import (rnrs) (emodl cmslib)) (start-model \"fixedPopulation\") (species S 42) (species I 1) (observe susceptible S) (reaction infect (S) (I) (* S I)) (end-model)");
            var results   = compartments.Program.ExecuteModel(modelInfo, "SSA", 10.0, 1000, 4);

            foreach (var vector in results.Data)
            {
                Assert.AreEqual(42.0, vector[0]);
            }
        }
Ejemplo n.º 3
0
        private static void RunPopulationTest(string distribution, out double mean, out double stdDev)
        {
            Configuration.CurrentConfiguration = Configuration.ConfigurationFromString(string.Format("{{\"prng_seed\":{0},\"prng_index\":{1}}}", DateTime.Now.Millisecond, DateTime.Now.DayOfYear));
            RNGFactory.Reset();
            const string modelTemplate = "(import (rnrs) (emodl cmslib)) (start-model \"fixedPopulation\") (species S ({0})) (species I 1) (observe susceptible S) (reaction infect (S) (I) (* S I)) (end-model)";
            var          modelInfo     = compartments.emodl.EmodlLoader.LoadEMODLModel(string.Format(modelTemplate, distribution));
            var          results       = compartments.Program.ExecuteModel(modelInfo, "SSA", 10.0, 1000, 4);
            double       sum           = results.Data.Sum(vector => vector[0]);
            double       sumSqr        = results.Data.Sum(vector => (vector[0] * vector[0]));
            double       n             = results.Data.Length;

            mean   = sum / n;
            stdDev = Math.Sqrt((sumSqr - 2 * mean * sum + n * mean * mean) / n);
            Console.WriteLine("initial population (mean):      {0}", mean);
            Console.WriteLine("initial population (std. dev.): {0}", stdDev);
        }