Пример #1
0
        public void TestStateDependentGammaInfoFunctions()
        {
            const int numReactions = 3;
            const int gammaSize    = 5;
            const int bcThreshold  = 20;
            var       gammaInfo    = new StateDependentGammaInfo(numReactions, gammaSize, bcThreshold);

            const double weight = 1.0;
            var          n      = new List <int[]> {
                new[] { 20, 20, 20, 20, 20 }, new[] { 1, 2, 3, 4, 5 }, new[] { 10, 20, 30, 15, 5 }
            };
            var lambda = new List <double[]> {
                new[] { 10.0, 20.0, 40.0, 100.0, 1000.0 }, new[] { 2.0, 4.0, 6.0, 8.0, 10.0 }, new[] { 20.0, 10.0, 60.0, 30.0, 10.0 }
            };

            gammaInfo.UpdateGamma(weight, n, lambda);
            gammaInfo.SetIntermediateGamma();
            Assert.That(new[] { 2.0, 1.0, 0.5, 0.2, 0.02 }, Is.EquivalentTo(gammaInfo.IntermediateGamma[0]));
            Assert.That(new[] { 0.5, 0.5, 0.5, 0.5, 0.5 }, Is.EquivalentTo(gammaInfo.IntermediateGamma[1]));
            Assert.That(new[] { 0.5, 2.0, 0.5, 0.5, 0.5 }, Is.EquivalentTo(gammaInfo.IntermediateGamma[2]));

            var startPC = new[] { 0.0, 0.2, 0.5 };
            var endPC   = new[] { 0.5, 0.8, 1.0 };
            var ppc     = new List <double[]>();

            ppc.AddRange(gammaInfo.IntermediatePropensityCutoff);
            gammaInfo.UpdatePropensityCutoff(startPC, endPC);
            Assert.That(ppc, Is.EqualTo(gammaInfo.PreviousIntermediatePropensityCutoff));
            Assert.That(new[] { 0.1, 0.2, 0.1 * 3, 0.4 }, Is.EqualTo(gammaInfo.IntermediatePropensityCutoff[0]));
            Assert.That(new[] { 0.2 + (0.8 - 0.2) / 5, 0.2 + (0.8 - 0.2) / 5 * 2, 0.2 + (0.8 - 0.2) / 5 * 3, 0.2 + (0.8 - 0.2) / 5 * 4 }, Is.EqualTo(gammaInfo.IntermediatePropensityCutoff[1]));
            Assert.That(new[] { 0.6, 0.7, 0.8, 0.9 }, Is.EqualTo(gammaInfo.IntermediatePropensityCutoff[2]));


            var ppc2 = new List <double[]>();

            ppc2.AddRange(gammaInfo.IntermediatePropensityCutoff);
            gammaInfo.MergeBins();
            Assert.That(new[] { 0.1, 0.2, 0.1 * 3, 0.4 }, Is.EqualTo(gammaInfo.PreviousIntermediatePropensityCutoff[0]));
            Assert.That(new[] { 0.2 + (0.8 - 0.2) / 5, 0.2 + (0.8 - 0.2) / 5 * 2, 0.2 + (0.8 - 0.2) / 5 * 3, 0.2 + (0.8 - 0.2) / 5 * 4 }, Is.EqualTo(gammaInfo.PreviousIntermediatePropensityCutoff[1]));
            Assert.That(new[] { 0.6, 0.7, 0.8, 0.9 }, Is.EqualTo(gammaInfo.PreviousIntermediatePropensityCutoff[2]));
            Assert.That(ppc2[0], Is.EqualTo(gammaInfo.IntermediatePropensityCutoff[0]));
            Assert.That(new[] { 1.0 }, Is.EqualTo(gammaInfo.IntermediatePropensityCutoff[1]));
            Assert.That(new[] { 0.7, 0.8 }, Is.EqualTo(gammaInfo.IntermediatePropensityCutoff[2]));

            gammaInfo.UpdateStructure();
            var gammaNum = GetHiddenField <List <double[]> >("_gammaNum", gammaInfo);

            Assert.AreEqual(new double[gammaSize], gammaNum[0]);
            Assert.AreEqual(new double[1], gammaNum[1]);
            Assert.AreEqual(new double[3], gammaNum[2]);
        }
Пример #2
0
        public void TestStateDependentGammaInfo()
        {
            const int numReactions = 3;
            const int gammaSize    = 5;
            const int bcThreshold  = 20;
            var       gammaInfo    = new StateDependentGammaInfo(numReactions, gammaSize, bcThreshold);

            Assert.That(Enumerable.Repeat(1.0, gammaSize).ToArray(), Is.EquivalentTo(gammaInfo.IntermediateGamma[0]));
            Assert.That(Enumerable.Repeat(1.0, gammaSize).ToArray(), Is.EquivalentTo(gammaInfo.IntermediateGamma[1]));
            Assert.That(Enumerable.Repeat(1.0, gammaSize).ToArray(), Is.EquivalentTo(gammaInfo.IntermediateGamma[2]));

            List <double[]> gamma, pc;
            var             rates = new[] { 1.0, 1.0, 1.0 };

            CreateGammaPC(gammaSize, rates, out gamma, out pc);
            Assert.That(pc, Is.EquivalentTo(gammaInfo.IntermediatePropensityCutoff));
        }
Пример #3
0
        public void TestUpdateBiasingParameters()
        {
            const string configString = @"{""solver"":""SDWSSA"", ""sdwSSA"":{""crossEntropyThreshold"":0.005, ""crossEntropyRuns"":1000000, ""biasingParametersFileName"":""resources\\rever_isom_CEinfo.json""}}";

            Configuration.CurrentConfiguration = Configuration.ConfigurationFromString(configString);

            var          modelInfo = EmodlLoader.LoadEMODLFile("resources\\rever_isom.emodl");
            const double duration  = 10.0;
            const int    repeats   = 1000000;
            const int    samples   = 1;
            var          solver    = new sdwSSA(modelInfo, duration, repeats, samples);

            var gammaInfo        = new StateDependentGammaInfo(2, 10, 20);
            var method           = GetHiddenMethod("UpdateBiasingParameters", solver);
            var inputObjectArray = new object[2];

            inputObjectArray[0] = gammaInfo;
            inputObjectArray[1] = 35;
            method.Invoke(solver, inputObjectArray);

            var biasingParameters = GetHiddenField <BiasingParameters>("_biasingParameters", solver);

            Assert.AreEqual(35, biasingParameters.RareEvent.Thresholds[2]);
        }